if(top.location!=self.location)top.location=self.location.href;
(function($, window) {

	/* List of background images to use, the default image will be the first one in the list
	var backgrounds = [
		'http://webtelevizyonu.com/wp-content/themes/v4/images/background.jpg'
	],*/

	// Background options - see documentation
	backgroundOptions = {
	},

	// Twitter username
	twitterUsername = 'WebTelevizyonu',

	// Number tweets to show, set to 0 to disable Twitter
	tweetCount = 3,	

	// The hide map text on the contact page
	hideMapButtonText = 'Haritayı Gizle';

	$('html').addClass('js-enabled');

	$(document).ready(function() {
		// Preview options
		$('#options-panel').tabSlideOut({
			tabHandle: '.options-handle',	// class of the element that will be your tab
			tabLocation: 'right',			// side of screen where tab lives, top, right, bottom, or left
			speed: 300,						// speed of animation
			action: 'click',				// options: 'click' or 'hover', action to trigger animation
			topPos: '200px',				// position from the top
			fixedPosition: false
		});

		$('#options-bg').change(function() {
			$('#img-overlay-effects')[0].className = $(this).val();
		});

		$('#options-header').change(function() {
			$('#header-outer').removeClass('header-plain header-diagonal header-middle header-dark').addClass($(this).val());
		});

		$('#options-content-bg').change(function() {
			if ($(this).val().length) {
				var removeClasses = 'textured-bg diagonal-bg transparent-bg level1 level2 level3 level4 level5 level6';
				$('.left-col-wrap-inner, .right-col-wrap-inner, .full-width').removeClass(removeClasses).addClass($(this).val());
			}
		});

		$('#options-font').change(function() {
			$('h1, h2, h3, table.pearl-table th').css('font-family', $(this).val());
		});
		// End preview options		

		$.fullscreen(
			$.extend(backgroundOptions, {
				backgrounds: window.backgrounds || backgrounds,
				backgroundIndex: window.backgroundIndex
			})
		);

		// Initialise the menu
		$('ul.sf-menu').superfish({ speed: 0 });

		// Tabs (fade effect)
		$('#tabs').tabs({
			fx: {
				opacity: 'toggle'
			}
		});

		// Accordion
		$('#accordion').accordion({
			autoHeight: false
		});

		// Testimonials
		if ($('#testimonials').length) {
			$('#testimonials').cycle({
				fx: 'fade',
				timeout: 6000,
				cleartype: true, cleartypeNoBg: true
			});
		}

		// Footer pop out boxes
		$('.footer-pop-out-trigger', '#footer').click(function () {
			var $trigger = $(this);
			var $allBoxes = $('.footer-pop-out-box', '#footer');
			if ($allBoxes.is(':animated')) {
				return false;
			}
			var thisId = $trigger.attr('id').substring(16);
			var $thisBox = $('#' + thisId + '-pop-out');
			if ($thisBox.is(':visible')) {
				$('.footer-pop-out-trigger').removeClass('footer-pop-active');
				$thisBox.slideUp();
			}
			else {
				if ($allBoxes.is(':visible')) {
					$('.footer-pop-out-trigger').removeClass('footer-pop-active');
					$allBoxes.filter(':visible').slideUp(function() {
						$trigger.addClass('footer-pop-active');
						$thisBox.slideDown();
					});
				}
				else {
					$trigger.addClass('footer-pop-active');
					$thisBox.slideDown();
				}
			}
			return false;
		});

		// Bind the view map button to slide down / up the map
		var $viewMapButton = $('.view-map'),
		$mapImg = $('.hidden-map'),
		$contactInfoWrap = $('.iphorm-outer'),
		viewMapButtonText = $('.view-map').text();

		$viewMapButton.click(function() {
			if (!$mapImg.add($contactInfoWrap).is(':animated')) {
				if (!$mapImg.hasClass('map-visible')) {
					$contactInfoWrap.slideUp(600, function() {
						$mapImg.slideDown(600, function() {
							$mapImg.addClass('map-visible');
							$viewMapButton.text(hideMapButtonText);
						});
					});
				}
				else {
					$mapImg.removeClass('map-visible').slideUp(600, function() {
						$contactInfoWrap.slideDown(600, function() {
							$viewMapButton.text(viewMapButtonText);
						});
					});
				}
			}
			return false;
		});

		// Bind any links with the class 'scroll-top' to animate the scroll to the top
		var scrollElement = 'html, body';
		$('html, body').each(function () {
			var seDomElement = $(this)[0];
		    var initScrollTop = seDomElement.scrollTop;
		    
		    seDomElement.scrollTop = initScrollTop + 1;
		    if (seDomElement.scrollTop == initScrollTop + 1) {
		        scrollElement = this.nodeName.toLowerCase();
		        seDomElement.scrollTop = initScrollTop;
		        return false;
		    }    
		});

		$('a.scroll-top').click(function () {
			if ($(scrollElement).scrollTop() > 0) {
				$(scrollElement).animate({ scrollTop: 0 }, 1000);
			}			
			return false;
		});

		// Scroll to comment form
		$('a.comment-write').click(function () {
			if ($('#yorum-yaz').length) {
				var offsetTop = $('#yorum-yaz').offset().top;
				$(scrollElement).animate({ scrollTop: offsetTop-25 }, 1000);
				return false;
			}
		});
		
		// Scroll to comments
		$('a.comment-counter').click(function () {
			if ($('#yorum-oku').length) {
				var offsetTop = $('#yorum-oku').offset().top;
				$(scrollElement).animate({ scrollTop: offsetTop-25 }, 1000);
				return false;
			}
		});

		// Open links with class popup-link in new window
		$('a.popup-link').click(function() {
			var href = $(this).attr('href');
			if (href.length > 0) {
				window.open(href);
			}
			return false;
		});

		// Make the form inputs and search fields clear value when focused
		$('.toggle-val').toggleVal({ populateFrom: 'label', removeLabels: true });

		// Create the gallery rollover effect
		$('li.one-portfolio-item a').append(
			$('<div class="portfolio-hover"></div>').css({ opacity: 0, display: 'block' })
		).live('mouseenter', function() {
			$(this).find('.portfolio-hover').stop().fadeTo(400, 0.8);
		}).live('mouseleave', function() {
			$(this).find('.portfolio-hover').stop().fadeTo(400, 0.0);
		});
	}); // End (document).ready

	$(window).load(function() {
		// Load the Twitter feed
		if (twitterUsername && tweetCount > 0) {
			(function() {
				var t = document.createElement('script'); t.type = 'text/javascript'; t.src = 'http://twitter.com/statuses/user_timeline/' + twitterUsername + '.json?callback=twitterCallback2&count=' + tweetCount;
				var h = document.getElementsByTagName('head')[0]; h.appendChild(t);
			})();
		}

		if ($('ul#homepage-slider').length) {
			// Anything slider
			$('.homepage-slider-loading').remove();
			$('ul#homepage-slider').show().anythingSlider({
				width: 900,
				height: 300,
				autoPlay: true,
				startStopped: false,
				pauseOnHover: false,
				buildNavigation: false,
				resizeContents: false,
				animationTime: 1000,
				delay: 3000
			});
		}
	}); // End (window).load	

	// Any images to preload
	window.preload([
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/opacity-40-rep.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/opacity-50-rep.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/opacity-60-rep.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/opacity-70-rep.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/opacity-80-rep.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/opacity-90-rep.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/horz-content-nav-bg.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/horz-content-nav-bg2.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/header-dark.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/header-diagonal.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/header-plain.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/header-middle.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/header-mid-right.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/sub-a-hover.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/sub-a-hover-warrow.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/sub-nav-bg.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/sub-sub-nav-bg.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/close.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/close1.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/tools-in.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/pop-up-h2-bg.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/pop-up-rep.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/go-to-top1.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/minimise1.png',
 		'http://webtelevizyonu.com/wp-content/themes/v4/images/vert-nav-bg.png',
		'http://webtelevizyonu.com/wp-content/themes/v4/images/twitter-button-bg2.png'
	]);

}) (jQuery, window);



// Contact form validation & posting

jQuery(document).ready(function(){
	send_mail();
});

function send_mail() {
	var my_error;
	jQuery("#send").bind("click", function() {

		my_error = false;
		jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").each(function(i) {
			var surrounding_element = jQuery(this);
			var value 				= jQuery(this).attr("value"); 
			var check_for 			= jQuery(this).attr("id");
			var required 			= jQuery(this).hasClass("required"); 

			if(check_for == "email") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(value == "" || value == "E-postanız *") {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(check_for == "email") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(!value.match(/^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/)) {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(check_for == "message") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(value == "" || value == "Mesajınız *") {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(check_for == "captcha") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(value != "light") {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(required && check_for != "email" && check_for != "message" && check_for != "captcha") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(value == "") {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").length  == i+1) {
				if(my_error == false) {
					jQuery(".ajax_form").slideUp(500);
					var $datastring = "ajax=true";
					jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").each(function(i) {
						var $name = jQuery(this).attr('name');
						var $value = encodeURIComponent(jQuery(this).attr('value'));
						$datastring = $datastring + "&" + $name + "=" + $value;
					});
					jQuery(".ajax_form #send").fadeOut(100);
					jQuery.ajax({
						type: "POST",
						url: "http://webtelevizyonu.com/wp-content/themes/v4/sendmail.php",
						data: $datastring,
						success: function(response) {
							jQuery(".ajax_form").before("<div class='ajax_response'></div>");
							jQuery(".ajax_response").html(response).slideDown(500); 
							jQuery(".ajax_form #send").fadeIn(500);
							jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").val("");
						}
					});
				}
			}
		});
		return false;
	});
}



// Comment validation & posting

jQuery(document).ready(function(){
	post_comment();
});

function post_comment() {
	var my_error;
	jQuery("#submit").bind("click", function() {

		my_error = false;
		jQuery("#commentform input, #commentform textarea, #commentform radio, #commentform select").each(function(i) {
			var surrounding_element = jQuery(this);
			var value 				= jQuery(this).attr("value"); 
			var check_for 			= jQuery(this).attr("id");
			var required 			= jQuery(this).hasClass("required"); 

			if(check_for == "author") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(value == "") {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(check_for == "email") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(value == "") {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(check_for == "email") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(!value.match(/^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/)) {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(check_for == "captcha") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(value != "19") {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(check_for == "comment") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(value == ""	) {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(required && check_for != "author" && check_for != "email" && check_for != "captcha" && check_for != "comment") {
				surrounding_element.removeClass("ajax_error valid");
				baseclases = surrounding_element.attr("class");
				if(value == "") {
					surrounding_element.attr("class",baseclases).addClass("ajax_error");
					my_error = true;
				}
				else {
					surrounding_element.attr("class",baseclases).addClass("valid");	
				}
			}

			if(jQuery("#commentform input, #commentform textarea, #commentform radio, #commentform select").length  == i+1) {
				if(my_error == false) {
					var $datastring = "ajax=true";
					jQuery("#commentform input, #commentform textarea, #commentform radio, #commentform select").each(function(i) {
						var $name = jQuery(this).attr('name');
						var $value = encodeURIComponent(jQuery(this).attr('value'));
						$datastring = $datastring + "&" + $name + "=" + $value;
					});
					jQuery("#submit").fadeOut(1000);
					jQuery.ajax({
						type: "POST",
						url: "../wp-comments-post.php",
						data: $datastring,
						success: function(html) {
							jQuery("#submit").after('<div class="success"></div>');
							jQuery(".success").html('Yorumunuz gözden geçirilmek üzere başarıyla kaydedildi! Onaylandığında e-posta ile bilgilendirileceksiniz. İlginiz için teşekkürler.').fadeIn(1000);
						}
					});
				}
			}
		});
		return false;
	});
}



// CTRL + F instant search function

var TRange=null

function findString (str) {
	if (parseInt(navigator.appVersion)<4) return;
	var strFound;
	if (window.find) {

		// CODE FOR BROWSERS THAT SUPPORT window.find

		strFound=self.find(str);
		if (strFound && self.getSelection && !self.getSelection().anchorNode) {
			strFound=self.find(str)
		}
		if (!strFound) {
			strFound=self.find(str,0,1)
			while (self.find(str,0,1)) continue
		}
	}
	else if (navigator.appName.indexOf("Microsoft")!=-1) {

		// EXPLORER-SPECIFIC CODE

		if (TRange!=null) {
			TRange.collapse(false)
			strFound=TRange.findText(str)
			if (strFound) TRange.select()
		}
		if (TRange==null || strFound==0) {
			TRange=self.document.body.createTextRange()
			strFound=TRange.findText(str)
			if (strFound) TRange.select()
		}
	}
	else if (navigator.appName=="Opera") {
		alert ("Bu arama betiği için Opera tarayıcısı desteklenmiyor.")
		return;
	}
	if (!strFound) alert ("Aradığınız oyuncu \""+str+"\" bulunamadı.")
	return;
}
