// JavaScript Document

$(document).ready(function(){

	TTs = [ "#n0", "#n1", "#n2", "#n3", "#n4", "#n5", "#n6", "#n7", "#n8", "#n9", "#n10", "#n11", "#n12" ];
	TTs2 = [ "#n0", "#n1", "#n2", "#n3", "#n4", "#n5", "#n6", "#n7", "#n8", "#n9", "#n10", "#n11", "#n12" ];
	TTlefts = [ 248, 333, 407, 467, 676, 769, 848, 640, 530, 350, 348, 348, 630, 650 ];

	function hideTTs(){
		$(".TT").fadeOut("normal");
		//$(".TT").css("display", "block");

			cc = 0;
			//alert('');
			while(cc < 13){
				rePose_ipucu(TTs2[cc], cc);
				cc ++;
			}
		//$(".TT").css("display", "none");
	}
	// TOOLTIP'LERIN KAPAT DUGMELERI
	$(".TT a.closeMe").click(function(){ hideTTs(); });



	function rand(n) {
		return ( Math.floor ( Math.random ( ) * n) );
	}

	//setTimeout(function(){showTip();}, 1000);

	resizing = 0;
	$(window).resize(function () {
		$("#iz").append(resizing + " window resize<br />");
		if(resizing == 1){return;}
		resizing = 1;
		setTimeout(function(){
			cc = 0;
			//alert('');
			while(cc < 13){
				rePose_ipucu(TTs2[cc], cc);
				cc ++;
			}
			resizing = 0;
		}, 500);
	});



	$(".showNext").click(function(){
		showTip();
	});

	showTip();

	function showTip(){
		hideTTs();
		i = rand(TTs.length);
		/*while(getCookie("ymToolTip" + TTs[i])){
			if(TTs.length == 0){
				$("#iz").append(TTs.length + " - finish<br />");
				return;
			}
			TTs.splice(i, 1);
			i = rand(TTs.length);
		}
		setCookie("ymToolTip" + TTs[i],1,100);*/
		//$(TTs[i]).css("display", "block");

		$(TTs[i]).fadeIn("normal");
		rePose_ipucu(TTs2[i], i);
		TTs.splice(i, 1);
	}

	function rePose_ipucu(obj, n){
		sw = $(window).width();
		if(sw < 960){sw = 960;}
		ol = TTlefts[n];
		gl = ol + ((sw - 1280) / 2);
		$(obj).css("left", gl);
		oll = $(obj).position().left;
		$("#iz").append(obj + " // " + gl + " -- " + ol + " - reposed = " + oll + "<br />");
	}

	function setCookie(c_name,value,expiredays){
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}

	function getCookie(c_name){
		if (document.cookie.length>0)
		  {
		  c_start=document.cookie.indexOf(c_name + "=");
		  if (c_start!=-1)
			 {
			 c_start=c_start + c_name.length+1;
			 c_end=document.cookie.indexOf(";",c_start);
			 if (c_end==-1) c_end=document.cookie.length;
			 return unescape(document.cookie.substring(c_start,c_end));
			 }
		  }
		return "";
	}

	$("#ipucuButton").click(function(){
		//clear_cookie();
		TTs = TTs2.slice(0);
		showTip();
	});

	function clear_cookie(){
		//$("#iz").append(TTs2.length + "CLEARING <br />");
		cc = 0;
		while(cc < TTs2.length){
			Delete_Cookie("ymToolTip" + TTs2[cc], '', '');
			cc ++;
		}
		TTs = TTs2.slice(0);
		showTip();
	}


	// this deletes the cookie when called
	function Delete_Cookie( name, path, domain ) {
	$("#iz").append(name + "<br />");
	if ( getCookie( name ) )
	$("#iz").append(name + " OK <br />");
	document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
});