/*!
 * anasayfa.js
 *
 * Copyright (c) 2009 pabbuc.com
 *
 * Created: 26.10.2009 13:52:05 by hakan ozen
 * Last updated: 24.11.2009 14:28:30 by hakan ozen 
 * Revision: 0.0.2
 */
 
var fake_select_display = 0;

$(document).click(function() {
	if (fake_select_display) {
		$(".fake_select").hide();
		fake_select_display = 0;
	}
});

$(document).ready(function() {	
	/* SLIDER - MARKALAR
	*/
	var firstMarginLeft = $('#markalar').css('marginLeft').replace(/px/, ''); //global var.
	var patlayazam = firstMarginLeft;
	var brandNo = $('#markalar li').length / 3; //global var.
	var liWidth = 186; //global var.
	var lastClick = 0;
	
	$('#markalar').css('marginLeft', -(Number(brandNo * liWidth - 5)) + 'px');
	
	firstMarginLeft = -(Number(firstMarginLeft) + Number(brandNo * liWidth));
	
	function slide_1(obj) {
		var marginLeft = $('#markalar').css('marginLeft').replace(/px/, '');
		var slideLength = 930;
		var newMarginLeft;		
		var clickTime = new Date();
		var timeout = 600;

		if(lastClick == 0 || (clickTime.getTime() - lastClick.getTime())>timeout){
			if( obj.attr('id') == 'screenRightButton') {
				if ( Math.abs(marginLeft) > Math.abs(firstMarginLeft) ){
					marginLeft = (Number(patlayazam) + Number(marginLeft%firstMarginLeft)) - Number(50);
					$('#markalar').css('marginLeft',  marginLeft + 'px');
				}
			
				newMarginLeft = Number(marginLeft) - Number(slideLength);
			}
			else {
				if ( marginLeft > firstMarginLeft) {
					marginLeft = (Number(firstMarginLeft) + Number(marginLeft)) + Number(25);
					$('#markalar').css('marginLeft',  marginLeft + 'px');
				}

				newMarginLeft = Number(marginLeft) + Number(slideLength);
			}
			
			lastClick = clickTime;
		}
		
		$('#markalar').animate({'marginLeft': newMarginLeft + 'px'}, 500);	
	}
	
	$('#screenRightButton, #screenLeftButton').click(function() {
		slide_1($(this));
	});
	
	/* SLIDER - MUSTERI YORUMLARI
	*/
	var firstMarginLeft2 = $('#markalar2').css('marginLeft').replace(/px/, ''); //global var.
	var patlayazam2 = firstMarginLeft2;
	var brandNo2 = $('#markalar2 li').length / 3; //global var.
	var liWidth2 = 446; //global var.
	var lastClick2 = 0;
	
	$('#markalar2').css('marginLeft', -(Number(firstMarginLeft2) + Number(brandNo2 * liWidth2)) + 'px');
	firstMarginLeft2 = -(Number(firstMarginLeft2) + Number(brandNo2 * liWidth2));	
	
	function slide_2(obj) {
		var marginLeft2 = $('#markalar2').css('marginLeft').replace(/px/, '');
		var slideLength2 = '932';
		var newMarginLeft2;		
		var clickTime = new Date();
		var timeout = 600;
		
		if(lastClick2 == 0 || (clickTime.getTime() - lastClick2.getTime())>timeout) {
			if(obj.attr('id') == 'screenRightButton2') {
				if ( Math.abs(marginLeft2) > Math.abs(firstMarginLeft2) ){
					marginLeft2 = (Number(patlayazam2) + Number(marginLeft2%firstMarginLeft2)) + Number(5);
					$('#markalar2').css('marginLeft',  marginLeft2 + 'px');
				}
				newMarginLeft2 = Number(marginLeft2) - Number(slideLength2);
			}
			else {
				if ( marginLeft2 > firstMarginLeft2) {
					marginLeft2 = ((Number(firstMarginLeft2) + Number(marginLeft2)) - Number(15)) * 2 - Number(15);
					$('#markalar2').css('marginLeft',  marginLeft2 + 'px');
				}
				newMarginLeft2 = Number(marginLeft2) + Number(slideLength2);
			}
			
			lastClick2 = clickTime;
		}
		
		$('#markalar2').animate({'marginLeft': newMarginLeft2 + 'px'}, 500);
	}
	
	$('#screenRightButton2, #screenLeftButton2').click(function() {
		slide_2($(this));
	});
	
	/* SLIDER'LARI LOOP ILE KAYDIRMA
	*/
	var slide_1_timeout;
	
	function auto_slide_1() {
		slide_1_timeout = setTimeout(function() {
			slide_1($("#screenRightButton"));
			auto_slide_1();
		}, 10000);
	}
	
	function auto_slide_2() {
		slide_2_timeout = setTimeout(function() {
			slide_2($("#screenRightButton2"));
			auto_slide_2();
		}, 40000);
	}
	
	/* IMLECIN SLIDER'IN USTUNE GELDIGINDE LOOP ILE KAYDIRMAYI DURDURAN
	USTUNDEN CEKILDIGINDE YENIDEN LOOP ILE KAYDIRMAYI DEVREYE SOKAN FONKSIYON
	*/
	$("#screen").mouseover(function() {
    clearTimeout(slide_1_timeout);
  }).mouseout(function() { 
    auto_slide_1();
  });	
	
	auto_slide_1();
	auto_slide_2();
	
	/* MARKALAR SLIDER'INDAKI MARKA LOGOLARININ USTUNE GELINDIGINDE
	IMAJIN SRC'SINI DEGISTIREN FONKSIYON
	
	*/
	$("#markalar li a img").mouseover(function() {
    var src = $(this).attr("src");
    var new_src= src.replace(/_g.jpg/, '.jpg');
    
    $(this).attr("src", new_src);
  }).mouseout(function() {
    var src = $(this).attr("src"); 
    var new_src= src.replace(/.jpg/, '_g.jpg');
    
    $(this).attr("src", new_src);  
  });
  /* MARKALAR SLIDER'INDAKI MARKA LOGOLARININ USTUNE GELINDIGINDE
	marka ad�n� de�i�tiren fonk.
	
	*/
	 $("#markalar li p a").css("font-size","14px");
  $("#markalar li").mouseover(function() {
    $(this).find("p a").css({'color':'#ED008E','font-weight':'bold'});
  }).mouseout(function() {
    $(this).find("p a").css({'color':'#000000','font-weight':'normal'});
  });
	
	/* BALON ACIKLAMA
	*/
	var xyz = 0;
	var myTimer;
	$(".show-bubble a").mouseover(function() {
		if (xyz == 2 ){ $(".bubble").hide();}
		xyz = 1;
		var exp = $(this).children('.bubble_cont').html();
		var marginLeft = $(this).children('.margin-left').html();
		var bubble = $(".bubble");
		var bubble_cont = $(".bubble .cont");
		var offset = $(this).offset();
		var x = Number(offset.left) + Number(marginLeft);
		var y = Number(offset.top) - Number(16);
		
		clearTimeout(myTimer);
		bubble_cont.html(exp);
		bubble.css("left", x + "px");
		bubble.css("top", y + "px");
		bubble.show();
	}).mouseout(function(){
		xyz = 2;
		myTimer = setTimeout(function () { $(".bubble").hide(); }, 1000);		
	});
	$("td.show-bubble-txt").css("width","78px");
	$(".show-bubble-txt input").mouseover(function() {
		
		var exp = $(this).children('.bubble_cont').html();
		var marginLeft = $(this).children('.margin-left').html();
		var bubble = $(".bubble");
		var bubble_cont = $(".bubble .cont");
		var offset = $(this).offset();
		var x = Number(offset.left) + Number(marginLeft);
		var y = Number(offset.top) - Number(16);
		
		bubble_cont.html(exp);
		bubble.css("left", x + "px");
		bubble.css("top", y + "px");
		bubble.show();
	}).mouseout(function(){
		$(".bubble").hide();
	});
	
	/* FAKE SELECT
	*/
	function selectbox_aciliyor(acilacak) {
		var offset = acilacak.offset();
		var x = Number(offset.left) + Number(0);
		var y = Number(offset.top) + Number(0);
		var options_obj = $("#" + acilacak.attr("id") + "_options");
		
		$(".fake_select").hide();
		fake_select_display = 0;
		
		if ( options_obj.is(":hidden") ) {
			options_obj.css("top", y + "px");
			options_obj.css("left", x + "px");		
			options_obj.show();

			setTimeout(function() {
				fake_select_display = 1;
			}, 100);
		}
	}
	$("#select_1").click(function() {
		selectbox_aciliyor($(this)); 		
	});	 
	
	
	/* AYAKKABINI SEC YAKINDA
	*/
	$("#filterBox").mouseenter(function() {
		$("#yakinda_span").fadeIn("fast");
	}).mouseleave(function() {
		$("#yakinda_span").fadeOut("fast");
	});
	/* anasayfa kategorilerinin selectboxların yüklenmesi
	*/	 $("div.cont li:last-child").css("background","none");
		var c1 = "";
		var c2 = "";
		var c3 = "";
		var c4 = "";
		$("#c1 li").click(function(){
			$("a.send-search-combo img").attr("src","main_gobek_search_button_passive.gif");
			
			//yeniden başla aktivate
			c1 = "";
			c2 = "";
			c3 = "";
			c4 = "";
			$("div#select_2 img.kapla").css("display","none");
			$("div#select_2 ul.combo li a").html("Ürün grubu seçin");
			$("div#select_3 ul.combo li a").html("Renk seçin");
			$("div#select_3 img.kapla").css("display","inline");
			$("div#select_4 ul.combo li a").html("Numara veya beden seçin");
			$("div#select_4 img.kapla").css("display","inline");
			
			$("div#select_1 ul.combo li a").html($(this).find("span.text_li a").html());
			c1=$(this).find("span.id_li").html(); 
			$.ajax({
               url: "/interactive/getselectoptionsforsearch.aspx?c1=" +c1 ,
			   async: false,
			   data: "",
               global: false,
               type: "GET",                
               dataType: "html",			    
               success: function(response){
			   		   $("#select_2_options .cont").html("");
                       $("#select_2_options .cont").append( response );
					 
					  $("div.cont li:last-child").css("background","none");

					   $("#c2 li").click(function(){
					   		//ara butonactive
							$("a.send-search-combo img").attr("src","main_gobek_search_button.gif");
							c3 = "";
							c4 = "";
							$("div#select_3 img.kapla").css("display","none");
							$("div#select_4 img.kapla").css("display","none");
					   		$("div#select_3 ul.combo li a").html("Renk seçin");							
							$("div#select_4 ul.combo li a").html("Numara veya beden seçin");
					   		$("div#select_2 ul.combo li a").html($(this).find("span.text_li a").html());							
							c2 = $(this).find("span.id_li").html();
							$.ajax({
								url: "/interactive/getselectoptionsforsearch.aspx?c1="+c1+"&c2="+c2,
								async: false,
								data: "",
								global: false,
								type: "GET",
								dataType: "html",
								success: function(response){
									$("#select_3_options .cont").html("");
									$("#select_3_options .cont").append(response);
									 $("div.cont li:last-child").css("background","none");
									
									$("#select_4_options .cont").html("");
									$("#select_4_options .cont").append(response);
									
									$("#c3 li").click(function(){
										$("div#select_4 ul.combo li a").html("Numara veya beden seçin");
					   					$("div#select_3 ul.combo li a").html($(this).find("span.text_li a").html());
										c3 = $(this).find("span.id_li").html();
										if (c4==""){
											gonder = "&c3="+c3;
										}else{
											gonder = "&c3="+c3+"&c4="+c4;
										}
										$.ajax({
											url: "/interactive/getselectoptionsforsearch.aspx?c1="+c1+"&c2="+c2+"&c3="+c3,
											async: false,
											data: "",
											global: false,
											type: "GET",
											dataType: "html",
											success: function(response){												
												$("#select_4_options .cont").html("");
												$("#select_4_options .cont").append(response);
												 $("div.cont li:last-child").css("background","none");
												$("#c4 li").click(function(){
													c4 = $(this).find("span.id_li").html();
								   					$("div#select_4 ul.combo li a").html($(this).find("span.text_li a").html());
													 $("div.cont li:last-child").css("background","none");
													/*$.ajax({
														url: "/interactive/getselectoptionsforsearch.aspx?c1="+c1+"&c2="+c2+"&c4="+c4,
														async: false,
														data: "",
														global: false,
														type: "GET",
														dataType: "html",
														success: function(response){												
															$("#select_3_options .cont").html("");
															$("#select_3_options .cont").append(response);														
																								
														}
													});*/
													
												});											
											}
										});
										
									});
									$("#c4 li").click(function(){
										$("div#select_3 ul.combo li a").html("Renk seçin");
					   					$("div#select_4 ul.combo li a").html($(this).find("span.text_li a").html());
										c4 = $(this).find("span.id_li").html();
										if (c3==""){
											gonder = "&c4="+c4;
										}else{
											gonder = "&c3="+c3+"&c4="+c4;
										}
										$.ajax({
											url: "/interactive/getselectoptionsforsearch.aspx?c1="+c1+"&c2="+c2+"&c4="+c4,
											async: false,
											data: "",
											global: false,
											type: "GET",
											dataType: "html",
											success: function(response){												
												$("#select_3_options .cont").html("");
												$("#select_3_options .cont").append(response);	
												 $("div.cont li:last-child").css("background","none");
												$("#c3 li").click(function(){
													c3 = $(this).find("span.id_li").html();
								   					$("div#select_3 ul.combo li a").html($(this).find("span.text_li a").html());
													 $("div.cont li:last-child").css("background","none");
													/*$.ajax({
														url: "/interactive/getselectoptionsforsearch.aspx?c1="+c1+"&c2="+c2+"&c3="+c3,
														async: false,
														data: "",
														global: false,
														type: "GET",
														dataType: "html",
														success: function(response){												
															$("#select_4_options .cont").html("");
															$("#select_4_options .cont").append(response);														
																								
														}
													});	*/												
												
											});										
											}
										});
									});
								}
							});
						});	
               }
     		});
		});
		$("#select_2").click(function(){
			if (c1 != ""){
				//selectbox a�
				selectbox_aciliyor($(this));			
			}
		});	
		$("#select_3").click(function(){
			if (c2 != ""){
				//selectbox ac				
				selectbox_aciliyor($(this));
				//selectbox ac				
			}
		});
		$("#select_4").click(function(){
			if (c2 != ""){
				//selectbox aç
				selectbox_aciliyor($(this));
				//selectbox aç			
			}
		});
		$("a.send-search-combo").click(function(){
			if (c2!="" && c1!=""){
				if (c4=="" && c3!=""){
					gonder = "&c3="+c3;
				}else if (c3=="" && c4!=""){
					gonder = "&c4="+c4;
				}else if (c3=="" && c4 ==""){
					gonder = "";
				}else if (c3!="" && c4 !=""){
					gonder = "&c3="+c3+"&c4="+c4;
				}
				window.location.href ="http://www.pabbuc.com//interactive/getcategoryfurl.aspx?c1="+c1+"&c2="+c2+gonder
				
			}
		});
	
});

