function setCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}
function soundOFF(){
	setCookie('sounds','off',25);
}
function soundON(){
	setCookie('sounds','on',25);
}
var flashvars = {};
var params = {wmode: "transparent", loop: "true"};
var attributes = {id: "sound"};
var SoundStatus =  getCookie('sounds');
swfobject.embedSWF("i/Assets/swf/Mp3Player.swf?soundURL=http://www.tavpassport.com/i/Assets/jingle.mp3&PlayerStatus="+ SoundStatus, "sound", "16", "16", "8.0.0", false, flashvars, params, attributes);

function fixElement(inObject,inMessage){
	alert(inMessage);
	$(inObject).focus();
}

$(document).ready(function(){

URLEncode($("ul.sm li.twitter a"));	
/*	
var flashvars = {};
var params = {wmode: "transparent", scale: "noscale"};
var attributes = {id: "fly"};
swfobject.embedSWF("i/assets/swf/TavFly.swf", "fly", "1024", "40", "9.0.0","expressInstall.swf", flashvars, params, attributes);
*/

var flashvars = {};
var params = {wmode: "transparent", scale: "noscale"};
var attributes = {id: "flyen"};
 swfobject.embedSWF("i/Assets/swf/TavFly.swf?language=en&path=/xml/1_58_3.xml", "flyen", "1024", "40", "9.0.0","expressInstall.swf", flashvars, params, attributes);

						   
						   
	$("a[rel='external']").click(function(){
		window.open($(this).attr("href"));
		return false;
	});
	$("#slider").anythingSlider({
		easing: "swing",       			 // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 3000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 600,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",             	// Start text
		stopText: "Stop",               // Stop text
		navigationFormatter: null       // Details at the top of the file on this use (advanced use)
	});
	
	$("#prime-class,#havas,#tepe-akfen").tooltip({ effect: 'slide', tipClass: 'logo'});
	$("#prime-class-en,#havas-en,#tepe-akfen-en").tooltip({ effect: 'slide', tipClass: 'logo'});
	$(".horizon a").hover(function(){
		setTimeout(function(){$(".horizon-info").fadeIn('slow');},200);
		},function(){
		setTimeout(function(){$(".horizon-info").fadeOut('slow');},200);
			
		}
	)
	
	
	
	
	$("#films").click(function(){
		$("ul.itms li:first").html('<div id="sound"></div>');
	});
	
	
	
	if($.browser.msie && $.browser.version == "6.0"){
		$("#search").attr({src: "i/Assets/images/fix.gif"});
		$("#search").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='i/Assets/images/srcbtn.png')"});
		$("#nwsubmit").attr({src: "i/Assets/images/fix.gif"});
		$("#nwsubmit").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='i/Assets/images/send.png')"});
		$("#srcsubmit").attr({src: "i/Assets/images/fix.gif"});
		$("#srcsubmit").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='i/Assets/images/search_btn.png')"});
	}
	
	$("#sss li .question a").click(function(){
		if($(this).parents("li:eq(0)").hasClass("active")){
			$("#sss li.active").children(".expand").slideToggle(300);
			$("#sss li.active").removeClass("active");
		}
		else{
			$("#sss li.active").children(".expand").slideToggle(300);
			$("#sss li.active").removeClass("active");
			$(this).parents("li:eq(0)").addClass("active");
			$(this).parents("li:eq(0)").children(".expand").slideToggle(300);
		}
		return false;
	});
	
	$("#sub-node li .ques a").click(function(){
		if($(this).parents("li:eq(0)").hasClass("active")){
			$("#sub-node li.active").children(".exp").slideToggle(300);
			$("#sub-node li.active").removeClass("active");
		}
		else{
			$("#sub-node li.active").children(".exp").slideToggle(300);
			$("#sub-node li.active").removeClass("active");
			$(this).parents("li:eq(0)").addClass("active");
			$(this).parents("li:eq(0)").children(".exp").slideToggle(300);
		}
		return false;
	});
	
	
	
	$("#src").focus(function(){
		if($(this).val() == "ARAMA"){
			$(this).val("");
		}
	});
	$("#src").blur(function(){
		if($(this).val() == ""){
			$(this).val("ARAMA");
		}
	});
	
	$("#srcen").focus(function(){
		if($(this).val() == "SEARCH"){
			$(this).val("");
		}
	});
	$("#srcen").blur(function(){
		if($(this).val() == ""){
			$(this).val("SEARCH");
		}
	});
	
	$("#txtnw").focus(function(){
		if($(this).val() == "e-postanizi yaziniz"){
			$(this).val("");
		}
	});
	$("#txtnw").blur(function(){
		if($(this).val() == ""){
			$(this).val("e-postanizi yaziniz");
		}
	});
	$("#srcform").submit(function(){
		if($("#src").val().length < 3){
			alert("Aramak istediğiniz kelime en az 3 karakterden oluşmalıdır.");
			$("#src").focus();
			return false;
		}
		else if($("#src").val() == "ARAMA"){
			alert("Lütfen aramak istediğiniz anahtar kelimeyi yazınız.");
			$("#src").focus();
			return false;
		}
	});
	$("#nwform").submit(function(){
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test($("#txtnw").val())){
			alert("Lütfen geçerli bir mail adresi giriniz.");
			$("#txtnw").focus();
			return false;
		}
	});
	
	$("#zone_5 li a").click(function(){
        if($(this).parent("li").hasClass("active")){
            return false;
        }
        else{
            /*
            var aId = $(this).parent("li").attr("id").replace("article_","");
            var title = $(this).attr("title");
            $("#zone_5 li.active").removeClass("active");
            $(this).parent("li").addClass("active");
            $.ajax({
                type: 'POST',
                url: window.location,
                data: "content_field=article_1&article_id=" + aId + "&W=OK",
                success: function(content){
                    $("#tlrcnt").html("<h2>" + title + "</h2>\n" + content);
                    alert("<h2>" + title + "</h2>\n" + content);
                }
            });
            return false;
            */
            $("#zone_5 li.active").removeClass("active");
            $(this).parent("li").addClass("active");
            var aId = $(this).parent("li").attr("id")
           
            $("#tlrcnt").show();
            $("#tlrcnt .tcnt.active").removeClass("active");
            $("#tlrcnt .tcnt[rel='"+ aId +"']").addClass("active");
            return false;
        }
    });
	
	$("#zone_18 li a").click(function(){
        if($(this).parent("li").hasClass("active")){
            return false;
        }
        else{
            /*
            var aId = $(this).parent("li").attr("id").replace("article_","");
            var title = $(this).attr("title");
            $("#zone_5 li.active").removeClass("active");
            $(this).parent("li").addClass("active");
            $.ajax({
                type: 'POST',
                url: window.location,
                data: "content_field=article_1&article_id=" + aId + "&W=OK",
                success: function(content){
                    $("#tlrcnt").html("<h2>" + title + "</h2>\n" + content);
                    alert("<h2>" + title + "</h2>\n" + content);
                }
            });
            return false;
            */
            $("#zone_18 li.active").removeClass("active");
            $(this).parent("li").addClass("active");
            var aId = $(this).parent("li").attr("id")
           
            $("#tlrcnt").show();
            $("#tlrcnt .tcnt.active").removeClass("active");
            $("#tlrcnt .tcnt[rel='"+ aId +"']").addClass("active");
            return false;
        }
    });
	


	if(window.location.hash == "#tav"){
		$("#films").trigger("click");
	}
	else if(window.location.hash == "#tavpassport"){
		$("#filmss").trigger("click");
	}
	
});



function advPlay(video,headline,info,innerInfo){
	var splash = '<div id="splash"></div>';
	$("body").append(splash);
	$("#splash").css({background: '#000000', opacity: '0.6'});
	if($.browser.msie && $.browser.version == "6.0"){
		$("#splash").css("height", $(document).height());
	}
	$("#splash").css("height", $(document).height());
	var flashplayer = '<div id="advplayer"></div>';
	$("body").append(flashplayer);
	$("#header .itms li:first").html('<div id="sound"></div>');
	var flashvars = {};
	var params = {wmode: "window", scale: "showall", allowScriptAccess: "always", allowFullScreen: "true"};
	var attributes = {id: "videoplayer"};
	swfobject.embedSWF("/i/Assets/swf/VideoPlayer.swf?path=/i/Assets/swf/" + video + "&text=" + headline + "&info=" + info + "&innerInfo=" + innerInfo + "", "advplayer", "635", "384", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	return false;
}
function splashClose(){
	var flashplayer = '<div id="advplayer"></div>';
	$(".inner").append(flashplayer);
	$("#splash").detach();
	$("ul.itms li:first").css("display","block");
	$("#videoplayer").detach();
	var flashvars = {};
	var params = {wmode: "transparent", loop: "true"};
	var attributes = {id: "sound"};
	var SoundStatus =  getCookie('sounds');
	swfobject.embedSWF("i/Assets/swf/Mp3Player.swf?soundURL=http://clients.euromsg.com/tav/jingle.mp3&PlayerStatus="+ SoundStatus, "sound", "16", "16", "8.0.0", false, flashvars, params, attributes);

}
function closeVideo(){
	var flashplayer = '<div id="advplayer"></div>';
	$(".inner").append(flashplayer);
	$("#splash").detach();
	$("ul.itms li:first").css("display","block");
	$("#videoplayer").detach();
	var flashvars = {};
	var params = {wmode: "transparent", loop: "true"};
	var attributes = {id: "sound"};
	var SoundStatus =  getCookie('sounds');
	swfobject.embedSWF("i/Assets/swf/Mp3Player.swf?soundURL=http://clients.euromsg.com/tav/jingle.mp3&PlayerStatus="+ SoundStatus, "sound", "16", "16", "8.0.0", false, flashvars, params, attributes);
}
$("#splash").live("click", function(){
	splashClose();
});


$('#lounge').bind('click',function(e){
		PopItUp('http://www.tavpassport.com/i/Assets/h/lounge.html','intper','570','850');
		return false;
	});

	
$('#loungetr').bind('click',function(e){
		PopItUp('http://www.tavpassport.com/i/Assets/h/lounge_liste.html','intper','570','850');
		return false;
	});	
	
	
function getCenter(pwidth,pheight){
	wwidth=screen.width;
	wheigth=screen.height;
	lpos= (wwidth - pwidth)/2;
	tpos= (wheigth - pheight)/2;
	return lpos, tpos;
}


function PopItUp(src,name,h,w,s) {
	if(s) w=w+17;
	getCenter(w,h);
	Popwin = window.open(src,name,"toolbar=0,width=" + w + ", height=" + h + ", left="+ lpos +", top="+ tpos +"; location=0, directories=0, status=1, scrollbars=1, menubar=0, resizable=1, copyhistory=0");
	Popwin.focus();
}

function URLEncode(object){
var url = encodeURIComponent(document.title+" - "+window.location.href);
$(object).attr("href","http://twitter.com/home?status="+url);
return false;
};

