var sizeterpilih=new Array(); 
$(document).ready(function(){
	/*$(".productList li").hover(function(){
		$(this).css("background-position","right 0px");
	},function(){
		$(this).css("background-position","0px 0px");
	});*/
		
	$(".add2cart").submit(function(){
		add2cart(this,"");
		return false;
	});
	
	$("#search_input").focus(function(){
		if( $(this).val() == 'Cari Baju...' )
			$(this).val("");
	}).blur(function(){
		if( $(this).val() == '' )
			$(this).val("Cari Baju...");
	});
	
	//$("#tooltipslink").click(function(){
	//	$("#tooltips").toggle();
	//	return false;
	//});
	//$("#hidetooltips").click(function(){
	//	$("#tooltips").toggle();
	//	return false;
	//});
	$("#pilihbahasa,#langhidetooltips").click(function(){
		$("#langtooltips").toggle();
		return false;
	});
	$("#customerlogin,#custhidetooltips").click(function(){
		$("#custtooltips").toggle();
		return false;
	});
	
	$(".ldd_submenu ul li a,.category ul li a").hover(function(){
		$(this).next().show();
		return false;
	});


	$(".add2cartsize").submit(function(){
		$("#imageloading").hide();
		
		arrcoupletype	= $.parseJSON($(this).attr("name"));
		dropdownsize	= '';
		i = 0;
		$.each(arrcoupletype, function(coupletype, arrsize) {
			if( i != 0 )
				dropdownsize = dropdownsize + ' &amp; ';
			
			dropdownsize = dropdownsize + '<select name="child_product_id" id="pilihsize" class="selectBig" onchange="setSizeProductId(this,'+i+')"><option value="">Pilih Ukuran '+ coupletype +' &nbsp;</option>';
			
			$.each(arrsize, function(size, prodid) {
				dropdownsize = dropdownsize + '<option value="'+prodid+'">'+size+'</option>' ;
			});
			dropdownsize = dropdownsize + '</select>';
			i++;
		});
		
		$('#add2cartmessageinsidetext').html('Silahkan pilih ukuran baju yang Anda inginkan: <br><br>'+dropdownsize+'&nbsp;&nbsp;<br><br><input type="submit" id="thebelibutton" title="" value="Beli Ukuran Ini &raquo;" class="checkoutBtn" onclick="add2cart(this,size)"/>');
		tb_show("Silahkan pilih ukuran",'#TB_inline?inlineId=add2cartmessage&amp;height=180&amp;width=650'); 
		
		return false;
	});
	
	$("#loginform").submit(function(){
		$('#add2cartmessageinsidetext').html('Silahkan tunggu, username dan password Anda sedang diperiksa.');
		tb_show("Member Login",'#TB_inline?inlineId=add2cartmessage&amp;height=180&amp;width=650'); 
		username	= $('#loginusername').val();
		password	= $('#loginpassword').val();
		rememberme	= ($('#rememberme').is(':checked'))?"1":"0";
		login_as	= $('#login_as').val();
		
		doLogin(username,password,rememberme,login_as);
		
		return false;
	});

	
	
	var COOKIE_NAME = 'femalecatmenu';
	//alert($.cookie(COOKIE_NAME));

	$(".maincat").mouseover(function(){
		$(this).removeClass("maincat").addClass("maincatactive");
	}).mouseout(function(){
		$(this).removeClass("maincatactive").addClass("maincat");
	}).click(function(){
		if($(this).next().is(":hidden"))
		{
			$(".category").hide();
			$(this).next().show(); 
		}
		else
		{
			$(this).next().hide();
			//$(".category").hide();
			//$(this).next().hide(); 
			return false;
		}
		var date = new Date();
		date.setTime(date.getTime() + (60 * 1000));
		$.cookie(COOKIE_NAME, 'test', { path: '/', expires: date })
	});
	
	$("#showcheckouttool").click(function(){
		$("#cartlist").toggle();
		if( $("#cartlist").is(':hidden') )
			$("#checkouttoolspace").css("background", "no-repeat right url(http://store.co.id/images/keranjangcewek.png)");
		else
			$("#checkouttoolspace").css("background", "no-repeat right url(http://store.co.id/images/keranjangcewek2.png)");
		
		return false;
	});
	
	
	/* main menu */
	var $menu = $('#ldd_menu');
	$menu.children('li').each(function(){
		var $this = $(this);
		var $span = $this.children('span');
		$span.data('width',$span.width());
		
		$this.bind('mouseenter',function(){
			$this.find('a:first').addClass("ahover");
			$menu.find('.ldd_submenu').stop(true,true).hide();
			$span.stop().animate({'width':'auto'},0,function(){
				$this.find('.ldd_submenu').show();
			});
			return false;
		}).bind('mouseleave',function(){
			$this.find('a:first').removeClass("ahover");
			$this.find('.ldd_submenu').stop(true,true).hide();
			$span.stop().animate({'width':$span.data('width')+'px'},0);
		});
		
	});
	
	/*featured home*/
	
	//$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("#featured ul li").click(function() {
		clearInterval(interval);
		changeFeatured(this);
		//setTimeout(function(){
			interval = setInterval( "changeNextFeatured()", 5000 );
		//},7000);
		/*
		$("#featured ul li").removeClass("ui-tabs-selected"); //Remove any "active" class
		$(this).addClass("ui-tabs-selected"); //Add "active" class to selected tab
		//$(".ui-tabs-panel").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(".ui-tabs-panel").slideUp("slow");
		$(activeTab).slideDown("slow");	
		*/
		return false;
	});
	
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(700); //Fade in the active ID content
		return false;
	});
	
	
	
	// filter button show cat
	// hover on div
	$(".buttonfilter div,.listfilter div").hover(function(){
		$(this).css("background-position","0 -100px")
		.children().first().css("background-position","right -100px").addClass("activelink");
	}, function(){
		$(this).css("background-position","0 0")
		.children().first().css("background-position","right 0").removeClass("activelink");
	});
	
	$(".buttonfilter .active,.listfilter .active").hover(function(){
		$(this).css("background-position","0 -100px")
		.children().first().css("background-position","right -100px").addClass("activelink");
	},function(){
		$(this).css("background-position","0 -200px")
		.children().first().css("background-position","right -200px").removeClass("activelink");
	});
	
	
	//color
	$(".colorfilter a").hover(function(){
		$(this).css("background-position","0 -100px");
	}).mouseout(function(){
		$(this).css("background-position","0 0");
	});
	
	$(".colorfilter .active").hover(function(){
		$(this).css("background-position","0 -100px");
	}).mouseout(function(){
		$(this).css("background-position","0 -200px");
	});
});
function showSearch()
{
	tb_show("Search Produk <?= ucwords($_CONFIG['mainkeyword']); ?>",'#TB_inline?inlineId=searchHidden&amp;height=180&amp;width=650');
	$("#searchtanya").focus();
}
function gotoCart()
{
	$("#add2cartmessagetext").html("<br /><br /><img src=\"images/loadingAnimation.gif\" /><br><br>Mohon tunggu sebentar, sedang loading halaman keranjang belanja");
	window.location="index.php?action=store.chart";	
}
function add2cart(thecart,is_size)
{
	if( is_size.length < 1 )
		product_id	= $(thecart).attr("id");
	else
	{
		product_id	= '';
		$.each(sizeterpilih, function(key, prodid) {
			if( prodid != '' )
				product_id	= product_id + prodid + ',';
		});
		
		if( product_id == '' )
		{
			alert('Silahkan pilih ukuran yang Anda inginkan!');
			exit;
		}
	}
	$("#imageloading").show();
	$('#add2cartmessageinsidetext').html('Silahkan tunggu, produk sedang ditambahkan ke keranjang belanja.');
	tb_show("Tambah Produk ke Keranjang Belanja",'#TB_inline?inlineId=add2cartmessage&amp;height=180&amp;width=650'); 
	
	doAdd2Cart(product_id);
}
function setSizeProductId(selectinput,iter)
{
	sizeterpilih[iter]	= $(selectinput).val();
}
function changeFeatured(theli)
{
	$("#featured ul li").removeClass("ui-tabs-selected"); //Remove any "active" class
	$(theli).addClass("ui-tabs-selected"); //Add "active" class to selected tab	
	var activeTab = $(theli).find("a").attr("href");
	$(".ui-tabs-panel").slideUp(1250);
	$(activeTab).slideDown(1250);
	
}
function changeNextFeatured()
{
	currentli	= $("#featured ul li.ui-tabs-selected");
	//alert($(currentli).find("a").attr("href"));
	if( $(currentli).find("a").attr("href") == '#fragment-4' )
		nextli		= $("#featured ul li").first();
	else
		nextli	= $(currentli).next();
		
	changeFeatured(nextli);
}

var interval;
$(function() {
	interval = setInterval( "changeNextFeatured()", 5000 );
});

