var slider;
$(document).ready(function(){

	$('div#gasNews').css('display','block');
	$('div#top_mainImageWrap').css('display','block');

	//Hide (Collapse) the toggle containers on load
	$(".menu").css('display','block');
	$(".cartToggleContainer").hide(); 
	$(".cartToggleContainer").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("#loginSlideTrigger").click(function(){
		//$(this).toggleClass("active").before().slideToggle("slow");
		//$(.slideToggle("slow"));
		$("#gasCartContainer").css('z-index','10');
		$("#gasLoginContainer").css('z-index','11');
		$(".loginToggleContainer").slideToggle("fast"); 
		return false; //Prevent the browser jump to the link anchor
	});

	$("#cartSlideTrigger").click(function(){
		$("#gasCartContainer").css('z-index','11');
		$("#gasLoginContainer").css('z-index','10');
		$(".cartToggleContainer").slideToggle("fast",resetZIndex); 
		return false; //Prevent the browser jump to the link anchor
	});
	function resetZIndex(){
		//alert($("#gasLoginContainer").slideToggle);
		if($(".cartToggleContainer").is(":hidden"))
		{
			$("#gasCartContainer").css('z-index','10');
			$("#gasLoginContainer").css('z-index','11');
		}
	}
	$(function(){
		$('ul#topNews').bxSlider({
			mode: 'vertical',
			controls: false,
			speed: 400,
			pager: false,
			auto: true,
			pause: 3000
		});
	});

	$(function(){
		// assign the slider to a variable

		slider = $('#top_mainImage').bxSlider({
			controls: false,
			speed: 500,
			pager: false,
			auto: true,
			autoHover: true,
			pause: 3500,
			onAfterSlide : function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject){
				//alert($('.topSlider').length);
				setTopSliderBtns(currentSlideNumber);
				this.pause = 3500;
			}
		});



		// assign a click event to the external thumbnails
		/*
		$('.mainImageButtons a').click(function(){
		 var thumbIndex = $('.mainImageButtons a').index(this);
			alert(thumbIndex);
			// call the "goToSlide" public function
			slider.goToSlide(thumbIndex);
			return false;
		});
		*/
		$("#mainImageButtons").css('width',(12*slideCount)+'px');
		$("#mainImageButtons").css('margin-top','14px');
		$("#mainImageButtons").css('margin-left','auto');
		$("#mainImageButtons").css('margin-right','auto');
	});



	//TOP 下部タブ
	//if(typeof userImageTab != 'undefined'){
	if(window.hasOwnProperty("userImageTab")){
		$('div#tabArea1').imageTabs();
		//$("#tabArea1").css('z-index','90');
	}

	$(function(){
		$("ul.sub").hide();

		$("ul.menu li").click(
			function(){
				$(">ul:not(:animated)",this).slideDown("fast");
				//$(">ul",this).slideUp("fast")
			}
		)

		$("ul.menu li").hover(
			function(){
				$(">ul:not(:animated)",this).slideDown("fast")
			},
			function(){
				$(">ul",this).slideUp("fast");
			}
		)

	});

});

function changeItemImage(path){
	//alert(path);
	var el = document.getElementById("itemImage");
	el.src=path;
	//itemImage
}
function exeSearch(rootpath){
	var obj = document.getElementById("headerSearchBox");
	//alert("search"+obj.value);
	//window.location.href = "http://my.wlc.la/ec/eccube/html/"+"products/list.php?mode=search&name="+obj.value;
	if(obj.value==""){
		alert("検索したい語句を指定してください。");
		return false;
	}else{
		window.location.href = rootpath+"products/list.php?mode=search&name="+obj.value;
		return false;
	}
}

function getQuerystring(key, default_)  {  
	if (default_==null) default_="";  
	key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");  
	var qs = regex.exec(window.location.href);  
	if(qs == null)  
	 return default_;  
	else  
	 return qs[1];  
}

function moveToContact(str){
	window.location.href= "../contact/?content="+str;
	//alert(str);
}
function setTopSliderBtns(c){
	var str = "";
	for(var i=0;i<slideCount;i++){
		//alert(slideCount);
		if(i==c){
			str += '<a href="javascript:topSlideGoTo('+i+')"><img src="'+TPL_URLPATH+'img/top/mainImgBtnOn.gif" /></a>';
		}else{
			str += '<a href="javascript:topSlideGoTo('+i+')"><img src="'+TPL_URLPATH+'img/top/mainImgBtn.gif" /></a>';
		}
	}
	document.getElementById("mainImageButtons").innerHTML = str;
	//slider.pause = 3500;
}
function topSlideGoTo(n){
	setTopSliderBtns(n)
	slider.goToSlide(n);
	slider.startShow();
}
