$(function() {
	jQuery.event.add(window, "load", function() {
		
	//////////////////////////////////////////
	// variables
	/////////////////////////////////////////
	var path = "images/title/";
	var tab = [
		"ttl_topix.gif",
		"ttl_special_item.gif",
		"ttl_originalgoods.gif",
		"ttl_netcafe.gif",
	];
	var headlinetab = [
		"ttl_pikup.gif",
		"ttl_featured.gif"
	];
	
	var isSlide = false;
	var index = 1;
	var cnt = 1;
	var images = $("#gallery img");
	var thumbs = $("#thumbs img");
	var imgHeight = $("#thumbs img").attr("height");
	$(thumbs).slice(0,3).clone().appendTo("#thumbs");
	for (i=0; i<thumbs.length; i++)
	{
		$(thumbs[i]).addClass("thumb-"+i);
		$(images[i]).addClass("image-"+i);
	}
	$("#thumbs").height(imgHeight*3);
	$("#prev").click(siftUp);
	$("#next").click(sift);
	show(index);
	
	function sift() {
		if(isSlide) return;
		isSlide = true;
		if(index<(thumbs.length-1)) index+=1;
		else index=0;
		show(index);
	}
	
	function siftUp() {
		if(isSlide) return;
		isSlide = true;
		if(index > 0) index-=1;
		else index = thumbs.length - 1;
		show(index);
	}
	
	function show(num) {
		$(images).fadeOut(400);
		$(".image-"+num).stop().fadeIn(400);
		$("#thumbs").stop().animate({scrollTop: (num * imgHeight)}, 420, function() {
			isSlide = false;
		});
	}

	
	//////////////////////////////////////////
	// images
	//////////////////////////////////////////
    $("img.rollover").mouseover(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))
    }).mouseout(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
    })
	});
	
	
	//////////////////////////////////////////
	// side-nav
	//////////////////////////////////////////
	//現在のURLを配列で取得	  	
	var now = location.href.split('/');
	//親のディレクトリ取得
	if(now[4]=="customer-report"){
		var dir = "support";
	}else if(now[3]=="news"){
		var dir = "news";
	}else if((now[4]=="campaign")||(now[4]=="event")){
		var dir = "campaign_event";
	}else if(now.length<=6){
		var dir = now.slice(now.length-2,now.length-1);
	}else if(now.length=7){
		var dir = now.slice(now.length-3,now.length-2);
	}
	var reg = new RegExp('(id=\"'+dir+'\"|id='+dir+')');

	$('#side-nav').each(function(){
		var txt = $(this).html();
		$(this).html(
			txt.replace(reg,'$1 class=\"active\"')
		);
	});

	//////////////////////////////////////////
	// window.open window.close
	//////////////////////////////////////////
	$(function() {
	$(".popup").click(function(){
		window.open(this.href, "playMunual","width=610,height=650,resizable=yes,scrollbars=yes");
		return false;
	});
	});
	$(function() {
	$(".popupclose").click(function(){
		window.close();return false;
	});
	});
	
	


	
} );

