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;
}

$(document).ready(function(){
	
	$(".overlay").css("height",$(document).height());
	$(".overlay").css("width",$(document).width());
	$(".overlay, .splash-close a").click(function(){
		 setTimeout(function(){ $('.splashed-box, .splash-close').slideUp('slow'); }, 200);
		 setTimeout(function(){ $(".overlay").detach(); }, 900);
		return false;
	});
	
	$(".overlay, .splash-close a").live("click",function(){
		setTimeout(function(){ $('.splashed-box, .splash-close').slideUp('slow'); }, 200);
		setTimeout(function(){ $(".overlay").detach(); }, 900);
		return false;
	});
	
	$("a[rel='external']").click(function(){
		window.open($(this).attr("href"));
		return false;
	});
	
	/*
	var maskot = '<img src="i/Assets/images/maskot.png" alt="" />';
	$("#menu #article_8 a").append(maskot);
	*/
	
	if($.browser.msie && $.browser.version == "6.0"){
		/*
		$("#menu #article_8 a img").attr({src: "/i/Assets/images/fix.gif"});
		$("#menu #article_8 a img").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='/i/Assets/images/maskot.png')"});
		*/
		$("#srcbutton,#srcbut").attr({src: "/i/Assets/images/fix.gif"});
		$("#srcbutton,#srcbut").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='/i/Assets/images/search_button.png')"});
		$("#menu ul li").not(":#menu ul li.active").hover(function(){
			$(this).addClass("active");
		},function(){
			$(this).removeClass("active");
		});
	}
	
	
	
	if(getCookie("newsletter") == "success"){
		$("#newsletter").addClass("ok");
	}
	$("#src, #srclong").focus(function(){
		if($(this).val() == "Aranacak Kelime"){
			$(this).val("");
		}
	});
	$("#src, #srclong").blur(function(){
		if($(this).val() == ""){
			$(this).val("Aranacak Kelime");
		}
	});
	$("#newsmail").focus(function(){
		if($(this).val() == "E-Posta Adresiniz"){
			$(this).val("");
		}
	});
	$("#newsmail").blur(function(){
		if($(this).val() == ""){
			$(this).val("E-Posta Adresiniz");
		}
	});
	
	$("table tbody tr:odd").not("#orders tbody tr").addClass("dif");
	
	$("#orders tbody tr:odd").addClass("dif");
	$("#orders tr td:odd").css({textAlign: "right"});
	

    $('table.kazananlar tr').removeClass('dif');
    $("table.kazananlar table tbody tr:odd").addClass("dif");

	var newsInterval;
	
	function changeNews(){
		var changeIt = function(){
			var activeNew = $("#slider .pager ul li").index($("#slider .pager ul li.active"));
			if(activeNew != 4){
				$("#slider .pager ul li a").eq(activeNew + 1).trigger("click");
			}
			else{
				$("#slider .pager ul li a").eq(0).trigger("click");
			}
		}
		newsInterval = setInterval(changeIt,10000);
	}	
	changeNews();
	
	$("#slider .pager ul li a").live("click", function(){
		if($(this).parent("li").hasClass("active")){
			return false;
		}
		else{
			clearInterval(newsInterval);
			var sIndex = $("#slider .pager ul li a").index($(this));
			$("#slider .s_item.active").removeClass("active");
			$("#slider .s_item").eq(sIndex).addClass("active");
			$("#slider .pager ul li.active").removeClass("active");
			$("#slider .pager ul li").eq(sIndex).addClass("active");
			//$("#slider .s_item").eq(sIndex).children(".tabsum").children("h1").typewriter(10);
			$("#slider .s_item").eq(sIndex).children(".tabsum").children(".sumdtl").typewriter(20);
			changeNews();
			return false;
		}
	});
	
	
	
	var slidePager = '<div class="pager">\n<ul>';
	$("#slider .s_item").each(function(i){
		slidePager += '\n<li><a href="#">' + (i + 1) + '</a></li>'
	});
	slidePager += '\n</ul>\n</div>';
	$("#slider").append(slidePager);
	$("#slider .pager ul li").eq(0).addClass("active");
	
	$("#slider .s_item").eq(0).addClass("active");
	
	$("#submenu li").not("#submenu li.active").hover(function(){
		$(this).addClass("active");
	},function(){
		$(this).removeClass("active");
	});	
	
	$(".tabs ul li a").click(function(e){
		e.preventDefault();
		if(!$(this).parent("li").hasClass("active")){
			var elmIndex = $(".tabs").index($(this).parents(".tabs"));
			var tabIndex = $(".tabs:eq(" + elmIndex + ") ul li a").index($(this));
			$(".tabs:eq(" + elmIndex + ") ul li.active").removeClass("active");
			$(".tabs:eq(" + elmIndex + ") ul li").eq(tabIndex).addClass("active");
			$(".tabcnts:eq(" + elmIndex + ") .tabcnt.active").removeClass("active");
			$(".tabcnts:eq(" + elmIndex + ") .tabcnt").eq(tabIndex).addClass("active");
			
			


			if($(this).parent("li").index()==0){
				var obj = $(this).parent().parent().next('a');
				obj.attr({'href': '/video_galeri' }).text('Tüm Videolar');
			}
			
			if($(this).parent("li").index()==1){
				var obj = $(this).parent().parent().next('a');
				obj.attr({'href': '/foto_galeri' }).text('Tüm Fotoğraflar');
			}
		}

	});
	$("#d12").anythingSlider({
		easing: "swing",       			 // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 4000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 700,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: false,          // 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)
	});
	$("#d12 .forward, #d12 .back").css("position","absolute");
	
	$.fn.typewriter = function(delay) {
        this.each(function() {
            var $ele = $(this), str = $ele.text(), progress = 0;
            $ele.text('');
            var timer = setInterval(function() {
                $ele.text(str.substring(0, progress++) + (progress & 1 ? '_' : ''));
                if (progress >= str.length + 1) clearInterval(timer);
            }, delay);
        });
        return this;
    };
	
	$("#srcform").submit(function(){
		if($("#src").val() == "Aranacak Kelime"){
			alert("LÃ¼tfen arama yapmak istediÄiniz anahtar kelimeyi giriniz.");
			$("#src").focus();
			return false;
		}
		else if($("#src").val().length < 3){
			alert("Aramak istediÄiniz kelime en az 3 karakterden oluÅmalÄ±dÄ±r.");
			$("#src").focus();
			return false;
		}
	});
	
	$("#formsrc").submit(function(){
		if($("#srclong").val() == "Aranacak Kelime"){
			alert("LÃ¼tfen arama yapmak istediÄiniz anahtar kelimeyi giriniz.");
			$("#srclong").focus();
			return false;
		}
		else if($("#srclong").val().length < 3){
			alert("Aramak istediÄiniz kelime en az 3 karakterden oluÅmalÄ±dÄ±r.");
			$("#srclong").focus();
			return false;
		}
	});
	
	$("#newsform").submit(function(){
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test($("#newsmail").val())){
			alert("LÃ¼tfen geÃ§erli bir mail adresi giriniz.");
			$("#newsmail").focus();
			return false;
		}
	});
	
	//$('input.star').rating();
	
	$(".lastnews li h1 > a").click(function(){
		$(".lastnews li.active").removeClass("active");
		$(this).parents("li:eq(0)").addClass("active");
		$(this).parents("li:eq(0)").children(".nwcnt").slideToggle(200);
		return false;
	});
	
	
	$(".fikstur li h1 > a").parents("li").children(".nwcnt").show();
	$(".fikstur li:first, .fikstur li:eq(1)").removeClass("active").find(".nwcnt").hide();
	$(".fikstur li:first, .fikstur li:eq(2)").removeClass("active").find(".nwcnt").hide();
	
	
	



	
	
	
	$(".fikstur li h1 > a").click(function(){
		$(".lastnews li.active").removeClass("active");
		$(this).parents("li:eq(0)").addClass("active");
		$(this).parents("li:eq(0)").children(".nwcnt").slideToggle(200);
		return false;
	});
	
	var flashvars = {};
	var params = {loop: "true", wmode: "transparent"};
	var attributes = {id: "counternew"};
	swfobject.embedSWF("i/Assets/swf/counter_new.swf", "counternew", "300", "250", "8.0.0", false, flashvars, params, attributes);
	
	var flashvars = {};
	var params = {loop: "true", wmode: "transparent"};
	var attributes = {id: "potaris-swf"};
	swfobject.embedSWF("i/Assets/swf/potaris.swf", "potaris-swf", "300", "250", "8.0.0", false, flashvars, params, attributes);
	
	var flashvars = {};
	var params = {wmode: "transparent", loop: "true"};
	var attributes = {id: "dabo"};
	swfobject.embedSWF("i/Assets/swf/dabolar_last.swf", "dabo", "100%", "250", "8.0.0", false, flashvars, params, attributes);
	
	var flashvars = {};
	var params = {wmode: "transparent", loop: "true"};
	var attributes = {id: "counter"};
	swfobject.embedSWF("i/Assets/swf/Counter.swf", "counter", "100%", "75", "8.0.0", false, flashvars, params, attributes);
	
	/*article_7*/
	
	var localbtn = '<div id="localbtn"><a title="TARAFTAR LOKALÄ°" href="/web/2-7-1-1/garanti_12_dev_adam/genel/topmenu/taraftar_lokali"><img src="/i/Assets/images/lokalbutonpng.png" alt="Taraftar Lokali" width="211" height="87" /></a></div>';
	$("#article_7").html(localbtn);
	
	var flashvars = {};
	var params = {wmode: "transparent", loop: "true"};
	var attributes = {id: "localbtn"};
	swfobject.embedSWF("i/Assets/swf/taraftarlokali.swf", "localbtn", "211", "87", "8.0.0", false, flashvars, params, attributes);
	
	var flashvars = {path:"i/Assets/swf/12dev.mp3", autoStart:"true"};
	var params = {wmode: "transparent", loop: "true"};
	var attributes = {id: "player"};
	swfobject.embedSWF("i/Assets/swf/Mp3Player.swf?soundStatus=" + getCookie('sounds'), "player", "182", "23", "8.0.0", false, flashvars, params, attributes);
	
	var flashvars = {};
	var params = {wmode: "transparent", loop: "true"};
	var attributes = {id: "flow"};
	swfobject.embedSWF("i/Assets/swf/TextFlow.swf?xmlPath=i/Assets/swf/Applause.xml", "flow", "964", "61", "8.0.0", false, flashvars, params, attributes);
	
	var flashvars = {};
	var params = {wmode: "transparent", loop: "true"};
	var attributes = {id: "flow-best"};
	swfobject.embedSWF("i/Assets/swf/TextFlow.swf?xmlPath=i/Assets/swf/Applause_Best.xml", "flow-best", "964", "61", "8.0.0", false, flashvars, params, attributes);
	
	var flashvars = {};
	var params = {wmode: "transparent", loop: "true"};
	var attributes = {id: "quizbanner"};
	swfobject.embedSWF("i/Assets/swf/quiz.swf?id=11", "quizbanner", "300", "250", "8.0.0", false, flashvars, params, attributes);
	
	/*
	var randomNumber = Math.floor(Math.random() * 2);
	if(randomNumber == "0"){
		
	}
	else{
		var flashvars = {};
		var params = {wmode: "transparent", loop: "true"};
		var attributes = {id: "quizbanner"};
		swfobject.embedSWF("i/Assets/swf/karnaval.swf", "quizbanner", "300", "250", "8.0.0", false, flashvars, params, attributes);
	}
	*/
	
	$("#sortCity").change(function(){
		$(".stad_dtl.active").removeClass("active");
		$(".stad_dtl").eq($(this).val()).addClass("active");
		/*$("#stdimgs img.active").removeClass("active");
		$("#stdimgs img").eq($(this).val()).addClass("active");*/
	});
	if($("#homepage").length == 1){
		var Stadindex = 0;
		var Stadsize = $("#listticker li").size() - 1;
		function changeStad(){
			if(Stadindex == 0){
				$("#listticker li:eq(0)").fadeOut(200,function(){
					$(this).removeClass("active");
					$("#listticker li:eq(1)").fadeIn(200,function(){
						$(this).addClass("active");
						Stadindex += 1;
					});
				});
			}
			else if(Stadindex == Stadsize){
				$("#listticker li").eq(Stadsize).fadeOut(200,function(){
					$(this).removeClass("active");
					$("#listticker li:eq(0)").fadeIn(200,function(){
						$(this).addClass("active");
						Stadindex = 0;
					});
				});
			}
			else{
				$("#listticker li").eq(Stadindex).fadeOut(200,function(){
					$(this).removeClass("active");
					$("#listticker li").eq(Stadindex + 1).fadeIn(200,function(){
						$(this).addClass("active");
						Stadindex += 1;
					});
				});
			}
		}
		Stadinterval = setInterval(changeStad, 10000);
	}
});

function ChangeSoundStatus(status){
	setCookie('sounds',status,25);
}
	
	
/*
function getNews(){
	var xmlPath = "i/Assets/news.xml";
	$.ajax({
		type: "GET",
		url: xmlPath,
		dataType: "xml",
		success: function(xml) {
			var tmp = '<ul id="lastnews">';
			$(xml).find('item').each(function(){
				tmp += '\n<li>\n\
							<h1><a href="#">' + $(this).children('title').text() + '</a></h1>\n\
							<div class="nwdate">' + $(this).children('pubDate').text() + '</div>\n\
							<div class="nwcnt">\n\
								' + $(this).children('description').text().replace('<div id="content">','').replace('</div>','') + '\n\
							</div>\n\
						</li>\n';
			});
			tmp += '</ul>';
			$("#contentleft").html(tmp);
		}
	});
}
*/


