$(function() {
	
	$(".hcat a").click( function(){
		
		$(".EtrBox").hide();
		$( $(this).attr("href") ).show();
		$(".hcat img").each( function(){
			var src = $(this).attr("src");
			src = src.replace("_on.gif", ".gif");
			$(this).attr("src", src);
		} );
		
		var src = $("img", this ).attr("src");
		
		src = src.replace(".gif", "_on.gif");
		
		$("img", this ).attr("src", src);
		
		return false;
		
	} );
	
	
});



function initRollovers() {
	
	if (!document.getElementById) return;
	
	var overPath = "_on";
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'over') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, overPath+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace(overPath+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}



addEvent(window,"load",initonLoad);



function initonLoad() {
	initRollovers();
}


function addEvent(elm,listener,fn){
	try{
		elm.addEventListener(listener,fn,false);
	}catch(e){
		elm.attachEvent("on"+listener,fn);
	}
}








/* Smooth scrolling
SmoothScroll JavaScript Library V2
*/

new function(){

	var attr ="data-tor-smoothScroll";//for html5 , if you can't use html5 , this value change "class"
	var attrPatt = /noSmooth/;
	var d = document;//document short cut
	
	/*
	 *add Event
	  -------------------------------------------------*/
	function addEvent(elm,listener,fn){
		try{ // IE
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent(
				"on"+listener
				,function(){
					fn.apply(elm,arguments)
				}
			);
		}
	}

	/*
	 *Start SmoothScroll
	  -------------------------------------------------*/
	function SmoothScroll(a){
		if(d.getElementById(a.rel.replace(/.*\#/,""))){
			var e = d.getElementById(a.rel.replace(/.*\#/,""));
		}else{
			return;
		}
		
		//Move point
		var end=e.offsetTop
		var docHeight = d.documentElement.scrollHeight;
		var winHeight = window.innerHeight || d.documentElement.clientHeight
		if(docHeight-winHeight<end){
			var end = docHeight-winHeight;
		}
		
		//Current Point
		var start=window.pageYOffset || d.documentElement.scrollTop || d.body.scrollTop || 0;
		
		
		var flag=(end<start)?"up":"down";

		function scrollMe(start,end,flag) {
			setTimeout(
				function(){
					if(flag=="up" && start >= end){
						start=start-(start-end)/20-1;
						window.scrollTo(0,start)
						scrollMe(start,end,flag);
					}else if(flag=="down" && start <= end){
						start=start+(end-start)/20+1;
						window.scrollTo(0,start)
						scrollMe(start,end,flag);
					}else{
						scrollTo(0,end);
					}
					return ;
				}
				,10
			);
			
		}

		scrollMe(start,end,flag);
		
	}

	/*
	 *Add SmoothScroll
	  -------------------------------------------------*/
	addEvent(window,"load",function(){
		var anchors = d.getElementsByTagName("a");
		for(var i = 0 ,len=anchors.length; i<len ; i++){
			if(!attrPatt.test(anchors[i].getAttribute(attr)) && 
				anchors[i].href.replace(/\#[a-zA-Z0-9_]+/,"") == location.href.replace(/\#[a-zA-Z0-9_]+/,"")){
				anchors[i].rel = anchors[i].href;
				anchors[i].href = "javascript:void(0)";
				anchors[i].onclick=function(){SmoothScroll(this)}
			}
		}
	});

}






//slideshow_トップ
function slideSwitch() {
  var $active = $('#slideshow img.active');
  if ( $active.length == 0 ) $active = $('#slideshow img:last');
  var $next =  $active.next().length ? $active.next() : $('#slideshow img:first');
  $active.addClass('last-active');
  $next.css({opacity: 0.0})
	  .addClass('active')
	  .animate({opacity: 1.0}, 1000, function() {
		  $active.removeClass('active last-active');
	});
}
$(function() {
  setInterval( "slideSwitch()", 5000 );
});



//slideshow_ブランド
function slideSwitch_02() {
  var $active = $('#slideshow_brand img.active');
  if ( $active.length == 0 ) $active = $('#slideshow_brand img:last');
  var $next =  $active.next().length ? $active.next() : $('#slideshow_brand img:first');
  $active.addClass('last-active');
  $next.css({opacity: 0.0})
	  .addClass('active')
	  .animate({opacity: 1.0}, 1000, function() {
		  $active.removeClass('active last-active');
	});
}
$(function() {
  setInterval( "slideSwitch_02()", 4000 );
});


