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 sendform(form){
		var email = $("#eposta").val();
		$.ajax({
			type: "POST",
			url: "/plugins/newsletter-register",
			data: "email="+email,
			success: function(msg){
				switch(msg)
				{
					case "SUCCESSFULLY":
						saveemailForm();
						$("#eform,#foot .rcd-bulten p").hide();
						$("#frmthnx").show();	
					break;
                    case "ALREADY":
                    	$("#eform,#foot .rcd-bulten p").hide();
						$("#frmalready").show();
                    break;
                    default:
                    	$("#eform,#foot .rcd-bulten p").hide();
						$("#frmerr").show();
				}
			}
		});
		return false;
}

function sendform2(form){
	var email = $("#email").val();
	$.ajax({
		type: "POST",
		url: "/plugins/newsletter-register",
		data: "email="+email,
		success: function(msg){
			switch(msg)
			{
				case "SUCCESSFULLY":
					saveemailenForm();
					$("#enform,#foot .rcd-bulten p").hide();
					$("#frmthnx").show();
				break;
				case "ALREADY":
					$("#enform,#foot .rcd-bulten p").hide();
					$("#frmalready").show();
				break;
				default:
					$("#enform,#foot .rcd-bulten p").hide();
					$("#frmerr").show();
			}
		}
	});
	return false;
}


function saveemailForm()
{
	var email = $("#eposta").val();
	$.ajax({
		   type: "post",
		   url: location.href,
		   data: { 
				W:"POST_OK",
				__URL__:"http://live.euromsg.com/subscribe/subscribeDC.asp",
				__HTTP_TYPE__:"POST",
				__RETURN_TYPE__:"text",
				ID:"97F7AE89D46245E18625B45C32725208",
				INTERESTS: 470029,
				COLUMNS: "1,2,6,11",
				DURUM:"",
				PRE:"N",
				EMAIL:""+ email +"",
				RDR_SUCCESS:"http://www.akmerkez.com.tr/i/Assets/true.html",
				RDR_FAIL:"http://www.akmerkez.com.tr/i/Assets/false.html",
				FORCE_CID:"N",
				EMAIL_PERMIT:"Y",
 				},
			    success: function(msg){
				   if(msg == "1")
				   {
					   $("#eform,#foot .rcd-bulten p").hide();
					   $("#frmthnx").show();
				   }
				   else
				   {
					  $("#eform,#foot .rcd-bulten p").hide();
					   $("#frmerr").show();
				   }
			   }
		});
		return false;
}

function saveemailenForm()
{
	var email = $("#email").val();
	$.ajax({
		   type: "post",
		   url: location.href,
		   data: { 
				W:"POST_OK",
				__URL__:"http://live.euromsg.com/subscribe/subscribeDC.asp",
				__HTTP_TYPE__:"POST",
				__RETURN_TYPE__:"text",
				ID:"97F7AE89D46245E18625B45C32725208",
				INTERESTS: 470029,
				COLUMNS: "1,2,6,11",
				DURUM:"",
				PRE:"N",
				EMAIL:""+ email +"",
				RDR_SUCCESS:"http://www.akmerkez.com.tr/i/Assets/true.html",
				RDR_FAIL:"http://www.akmerkez.com.tr/i/Assets/false.html",
				FORCE_CID:"N",
				EMAIL_PERMIT:"Y",
 				},
			    success: function(msg){
				   if(msg == "1")
				   {
					   $("#enform,#foot .rcd-bulten p").hide();
					   $("#frmthnx").show();
				   }
				   else
				   {
					  $("#enform,#foot .rcd-bulten p").hide();
					  $("#frmerr").show();
				   }
			   }
		});
		return false;
}

$(document).ready(function(){	
	/*if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) ) {
		window.location = "http://www.akmerkez.com.tr/iphone";
	}
	else{
	}*/
	if($("#homeflash").html() == "")
	{
		$("#homeflash").append("<img id='phone-image' src='/i/Assets/images/home-page.png' alt='' />");
		$("#phone-image").attr("usemap","#Map");
	}
	$("#recordfeed").click(function(){
        var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if(!filter.test($("#eposta").val())){
				fixElement('Lütfen mail adresinizi giriniz.',$("#eposta"));
				return false;
		}
		else{
				sendform("#eform");
				return false;
		} 
	});
	$("#recordfeed-en").click(function(){
        var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if(!filter.test($("#email").val())){
				fixElement('Enter your e-mail address.',$("#email"));
				return false;
		}
		else{
				sendform2("#enform");
				 return false;
		} 
	});
	/* modal - popup*/
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {					  
			e.preventDefault();
			//Get the A tag
			var id = $(this).attr('rel');
			//Get the screen height and width
			var maskHeight = $(document).height();
			var maskWidth = $(window).width();
			//Set heigth and width to mask to fill up the whole screen
			$('#mask').css({'width':maskWidth,'height':maskHeight});
					//Get the window height and width
			var winH = $(window).height();
			var winW = $(window).width();	  
			//Set the popup window to center
			//$("div[rel='" + id + "']").css('top',  winH/2- $("div[rel='" + id + "']").height()/2);
			//$("div[rel='" + id + "']").css('left', winW/2- $("div[rel='" + id + "']").width()/2);
			/*
			if(!$.browser.msie){
				$('#mask').fadeIn(1000);	
				$('#mask').fadeTo("slow",0.8);	
			}
			*/
			$("div[rel='" + id + "']").fadeIn(500);
			if(!$(".pane-"+id).parent("div").hasClass("jScrollPaneContainer")){
				$(".pane-"+id).jScrollPane();              
			}
			//$(".pane-"+id).jScrollPane();
			/** /
			$("div[rel='" + id + "']").fadeIn(500,function(){
				
			});
			/**/
	});
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask').hide();
		$('.window').hide();
	});		
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});	
	/* modal - popup */			   
   if($("#footer ul li, #menu ul li#article_15, #menu ul li#article_595, #search-head").hasClass("active"))
   {
	   $("#menu ul").css("border-bottom","1px solid #c3bdb4");
   }
   if($("#menu ul li ul li#article_51").hasClass("active"))
   {
	   $("#menu ul li ul li#article_51 a span").width("143px");
	   $("#menu ul li ul li#article_51 a span").css("padding-right","3px");
   }   
	$(".close input").click(function(){
		$("div.hide-map").hide();	
		$("#cnt li.active").removeClass("active");
		$("#cnt-areas").css("height","560px");	
	});
	$("#cnt li .city a").click(function(){
		if($(this).parents("li").hasClass("active")){
			$(this).parents("li").children("div.hide-map").slideUp(500);
			if($.browser.msie && $.browser.version == '6.0')
			{
				$("#cnt-areas").css("height","300px");
			}
			else
			{
				$("#cnt-areas").css("height","560px");
			}
			$(this).parents("li").removeClass("active");
		}
		else{
			$("#cnt li.active").children("div.hide-map").slideToggle(300);
			$("#cnt li.active").removeClass("active");
			$(this).parents("li").children("div.hide-map").slideDown(500).show();
			$("#cnt-areas").css("height","650px");
			$(this).parents("li").addClass("active");
		}
			return false;
	});
	$('#article_17 a').attr('title', 'Çok Yakında');
	$('#article_17 a').removeAttr("href");
	$('#article_17 a').css("cursor","pointer");
	$('#article_17 a').tipsy({gravity: 'n'});
	
	$('#article_632 a').attr('title', 'COMING SOON');
	$('#article_632 a').removeAttr("href");
	$('#article_632 a').css("cursor","pointer");
	$('#article_632 a').tipsy({gravity: 'n'});
	
	$("div.chronology ul li a").click(function(){
		var box = $(this).attr("rel");
		
		$("div.dateCol div.date").hide();
		$("div#date"+box).show();
		
		$("div.image-slide img").hide();
		$("div.image-slide img#image"+box).show();
		
		$("div.chronology ul li a").removeClass("active");
		$(this).addClass("active");
		return false;
	}).filter(":first").click();
	$("div.question-list ul li a").not("div.answer a").click(function(){
		if($(this).parents("li:eq(0)").hasClass("active")){
			$("div.question-list ul li.active").children(".answer").slideToggle(300);
			$("div.question-list ul li.active").removeClass("active");
		}
		else{
			$("div.question-list ul li.active").children(".answer").slideToggle(300);
			$("div.question-list ul li.active").removeClass("active");
			$(this).parents("li:eq(0)").addClass("active");
			$(this).parents("li:eq(0)").children(".answer").slideToggle(300);
		}
		return false;
	});

	/*
	$(function($){
     	$('#clock').jclock();
    });	
		*/
	
	$("#eposta").focus(function(){
		if($(this).val() == "E-posta"){
			$(this).val("");
		}
	});
	$("#eposta").blur(function(){
		if($(this).val() == ""){
			$(this).val("E-posta");
		}
	});
	
	$("#email").focus(function(){
		if($(this).val() == "E-mail"){
			$(this).val("");
		}
	});
	$("#email").blur(function(){
		if($(this).val() == ""){
			$(this).val("E-mail");
		}
	});

	$("#keyword").focus(function(){
		if($(this).val() == "Arama"){
			$(this).val("");
		}
	});
	$("#keyword").blur(function(){
		if($(this).val() == ""){
			$(this).val("Arama");
		}
	});

	$("#menu > ul > li > a").not("#menu ul li#article_17 a, #menu > ul > li#article_15 > a,#menu > ul > li#article_14 > a, #menu > ul > li#article_16 > a, #menu > ul > li#article_11 > a, #menu > ul > li#article_12 > a, #menu > ul > li#article_9 > a, #menu > ul > li#article_13 > a, #menu > ul > li#article_567 > a, #menu > ul > li#article_591 > a, #menu > ul > li#article_632 > a, #menu > ul > li#article_633 > a, #menu > ul > li#article_592 > a, #menu > ul > li#article_593 > a, #menu > ul > li#article_594 > a, #menu > ul > li#article_595 > a, #menu > ul > li#article_596 > a").click(function(){
		$("#menu ul li ul").hide();
		$("#menu ul li").removeClass("activated");
		$(this).parent("li").addClass("activated");
		$(this).parent("li").children("ul").show();
		return false;
	});
	
  $("#menu > ul > li#article_14 a, #menu > ul > li#article_594 a").click(function(){
		$(this).next("ul").css("display","none");												 											 
   });
	
	$("#home-menu > ul > li > a").not("#home-menu ul li#article_17 a, #home-menu > ul > li#article_15 > a, #home-menu > ul > li#article_14 > a, #home-menu > ul > li#article_16 > a, #home-menu > ul > li#article_11 > a, #home-menu > ul > li#article_12 > a, #home-menu > ul > li#article_9 > a, #home-menu > ul > li#article_591 > a, #home-menu > ul > li#article_633 > a,  #home-menu > ul > li#article_567 > a, #home-menu > ul > li#article_593 > a, #home-menu > ul > li#article_594 > a, #home-menu > ul > li#article_595 > a, #home-menu > ul > li#article_596 > a, #home-menu > ul > li#article_632 > a").click(function(){
		$("#home-menu ul li ul").hide();
		$("#home-menu ul li").removeClass("activated");
		$(this).parent("li").addClass("activated");
		$(this).parent("li").children("ul").show();
		
		return false;
	});

	/* alisveris keyfi navigation START */
	$("li#article_13 ul li, li#article_592 ul li").eq(4).addClass("lie").end().eq(9).addClass("lie").end().eq(14).addClass("lie");
	/* alisveris keyfi navigation END */
	
	$("#contact-us li a").click(function(){
		if($(this).parents("li:eq(0)").hasClass("active")){
			$("#contact-us li.active").children(".hide-form").slideToggle(300);
			$("#sss li.active").removeClass("active");
			
		}
		else{
			$("#contact-us li.active").children(".hide-form").slideToggle(300);
			$("#contact-us li.active").removeClass("active");
			$(this).parents("li:eq(0)").addClass("active");
			$(this).parents("li:eq(0)").children(".hide-form").slideToggle(300);
		
		}
		return false;
	});
	
	if($.browser.msie && $.browser.version == '6.0')
	{
		 $("#search-btn").attr({src: "i/Assets/images/fix.gif"});
		 $("#search-btn").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='/i/Assets/images/search-btn.png')"}); 
		 $(".boxes .dialog2 input").attr({src: "i/Assets/images/fix.gif"});
		 $(".boxes .dialog2 input").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='/i/Assets/images/btn-close.png')"}); 
	}
	if($("#menu ul li#article_16").hasClass("active"))
	{
		//$("#cnt-areas").css("height","300");
	}
	$("#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)
	});
	
	$("#photoslider").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)
	});
	
	
	if($("#article_13, #article_592").hasClass("active")){
		var clickID = $("#menu ul li ul li.active").attr("id");
		
		var strId = getCookie("article_id");
		
		if(strId != "null"){
			var flashvars = {};
			var params = {wmode: "transparent", allowScriptAccess: "samedomain", allowFullScreen: true };
			var attributes = {id: "kroki"};
			swfobject.embedSWF("i/Assets/swf/kroki.swf?zoneId=" + $("#zoneid li." + clickID).attr("rel") + "&article=" + strId, "kroki", "980", "320", "8.0.0", false, flashvars, params, attributes);
			setCookie("article_id","null",1);
		}
		else{
			var flashvars = {};
			var params = {wmode: "transparent", allowScriptAccess: "samedomain", allowFullScreen: true };
			var attributes = {id: "kroki"};
			swfobject.embedSWF("i/Assets/swf/kroki.swf?zoneId=" + $("#zoneid li." + clickID).attr("rel"), "kroki", "980", "320", "8.0.0", false, flashvars, params, attributes);
			//setCookie("article_id","null",1);
		}
	}
	
	/*en*/
	
		if($("#article_592").hasClass("active")){
		var clickID = $("#menu ul li ul li.active").attr("id");
		
		var strId = getCookie("article_id");
		
		if(strId != "null"){
			var flashvars = {};
			var params = {wmode: "transparent", allowScriptAccess: "samedomain", allowFullScreen: true };
			var attributes = {id: "kroki-en"};
			swfobject.embedSWF("i/Assets/swf/kroki-en.swf?zoneId=" + $("#zoneid li." + clickID).attr("rel"), "kroki-en", "980", "320", "8.0.0", false, flashvars, params, attributes);
			//setCookie("article_id","null",1);
		}
		else{
			var flashvars = {};
			var params = {wmode: "transparent", allowScriptAccess: "samedomain", allowFullScreen: true };
			var attributes = {id: "kroki-en"};
			swfobject.embedSWF("i/Assets/swf/kroki-en.swf?zoneId=" + $("#zoneid li." + clickID).attr("rel"), "kroki-en", "980", "320", "8.0.0", false, flashvars, params, attributes);
			
			//setCookie("article_id","null",1);
		}
	}
	
	/*en*/


	/* new */
	
		if($("#article_698").hasClass("active")){		
		var strId = getCookie("article_id");
		
		if(strId != "null"){
			var flashvars = {};
			var params = {wmode: "transparent", allowScriptAccess: "samedomain", allowFullScreen: true };
			var attributes = {id: "kroki"};
			swfobject.embedSWF("i/Assets/swf/kroki.swf?zoneId=100", "kroki", "980", "320", "8.0.0", false, flashvars, params, attributes);
			setCookie("article_id","null",1);
		}
		else{
			var flashvars = {};
			var params = {wmode: "transparent", allowScriptAccess: "samedomain", allowFullScreen: true };
			var attributes = {id: "kroki"};
			swfobject.embedSWF("i/Assets/swf/kroki.swf?zoneId=" + $("#zoneid li." + clickID).attr("rel"), "kroki", "980", "320", "8.0.0", false, flashvars, params, attributes);
			//setCookie("article_id","null",1);
		}
	}
	

	$('#splash,.concierge-close').live('click', function() {
	  	$("#splash,#concierge-splash").detach();
		return false;
	});
	
	
	$("a#concierge").click(function(){
		var splash = '<div id="splash"></div>';
		var splashboxes = '<div id="concierge-splash"><a class="concierge-close" href="#" title="Kapat">Kapat</a><div id="krokiconcierge"></div></div>';
		$("body").append(splash,splashboxes);
		$("#splash").css("height",$(document).height());
		
		var flashvars = {};
		var params = {wmode: "transparent", allowScriptAccess: "samedomain", allowFullScreen: true };
		var attributes = {id: "krokiconcierge"};
		swfobject.embedSWF("i/Assets/swf/kroki2.swf", "krokiconcierge", "980", "320", "8.0.0", false, flashvars, params, attributes);
		setCookie("article_id","null",1);
	});
	
	$("a#concierge-en").click(function(){
		var splash = '<div id="splash"></div>';
		var splashboxes = '<div id="concierge-splash"><a class="concierge-close" href="#" title="Close">Kapat</a><div id="krokiconcierge"></div></div>';
		$("body").append(splash,splashboxes);
		$("#splash").css("height",$(document).height());
		
		var flashvars = {};
		var params = {wmode: "transparent", allowScriptAccess: "samedomain", allowFullScreen: true };
		var attributes = {id: "krokiconcierge"};
		swfobject.embedSWF("i/Assets/swf/kroki-en2.swf", "krokiconcierge", "980", "320", "8.0.0", false, flashvars, params, attributes);
		setCookie("article_id","null",1);
	});
	
	/* new */

	/*
	$("#article_13 ul li a").click(function(){
		if($("#article_13").hasClass("active")){
			var clickID = $(this).parent("li").attr("id");
			//console.log(clickID);
			sendtoFlash($("#zoneid li." + clickID).attr("rel"));
			return false;
		}
	});
	*/
});

	

	
