/*
 * jQuery Pack for KAKUSEE Ver.201010
 *
 * Copyright (C) 2010 HOKUTO Co.,Ltd.
 *
 */
 
var a = 0;
var maxlength = 0;
var timer = 5000;
var timerID;
 
jQuery(document).ready(function(){
								
   var preLoader = new Image();
   preLoader.src = 'img/toppage/visual_bg.png';
								
   maxlength = $('#thumbnails ul li').length;
   $('#thumbnails ul li a').each(function(){
	  var imageurl = $(this).attr('href');
	  $('#photoHanger ul').append('<li><img src="'+imageurl+'"></li>');
   });
							
   var num = 0;
	
   $('.pickup dl').mouseenter(function(){
	   $(this).css('background-color','#E2DEC7');
   });
   
   $('.pickup dl').mouseleave(function(){
	   $(this).css('background-color','#ffffff');
   });
   
   $('.pickup').each(function(){
	   num++;
       var newName = 'arr'+num;
       var newName = new Array();
	   $(this).children('dl:first').css('width','158px');
	   $(this).children('dl').each(function(){
	      var h =  $(this).innerHeight();
		  newName.push(h);
	   });
	   var n = newName[0];
	   for (i=1; i<newName.length; i++) if (newName[i] > n) n = newName[i];
	   $(this).children('dl').each(function(){
	      $(this).css('height',n-5);
	   });
	   if($.browser.msie || $.browser.mozilla){
	      $(this).children('dl').each(function(){
	          $(this).css('height',n-20);
	      });
	   }
   });
   
   if(location.pathname != "/") {
		var now = location.href.split('/');
		var cate = now.slice(now.length-2,now.length-1);
		var url = cate.toString();
		$('#globalNavi li a[href$="http://kakusee.co.jp/'+url+'/index.html"]').css("background-position","0 -40px");
   }
   
   if($.os.name == 'iphone' || $.os.name == 'ipod' || $.os.name == 'ipad') {
   }else{
		$('a[href*=#]').click(function () {
	       var targetId = $(this).attr('href');
	       var targetPos = $(targetId).offset().top;
	       $('html,body').animate({scrollTop:targetPos},500);
	       return false;
	    });
   }
   
   $('.animation').hover(
	 function(){
	   $(this).css('opacity','0.6');
	 },
	 function(){
       $(this).css('opacity','1');
	 }
   );
   
});

function thumbnailAction(){
    if(a==maxlength){
	   a=0;
	}
	$('#photoHanger ul li').each(function(){
	   var alpha = $(this).css('opacity');
	   if(alpha==1){
	      var Pos = $('#photoHanger ul li').index(this);
		  $('#photoHanger ul li').slice(Pos,Pos+1).animate({"opacity": "0"},500);
	   }
	});
    a+=1;
	var start = a-1;
	var end = a;
	$('#thumbnails ul li a').children('img').css('top','0');
	$('#thumbnails ul li a').slice(start,end).children('img').css('top','-70px');
	if($.browser.msie && $.browser.version < 7){
	    $('#thumbnails ul li a').children('img').css('margin-top','0');
	    $('#thumbnails ul li a').slice(start,end).children('img').css('margin-top','-70px');
	}
	$('#photoHanger ul li').slice(start,end).animate({"opacity": "1"},500);
	timerID = setTimeout("thumbnailAction()", timer);
}

function unitclick(link){
	location.href = link;
}

$(window).load(function(){
	$('#loading').css('display','none');
	$('#photoHanger').css('display','block');
	$('#thumbnails ul li a').click(function(){
	   clearTimeout(timerID);
	   var index = $('#thumbnails ul li a').index(this);
	   a=index;
	   thumbnailAction();
	   return false;
    });
    thumbnailAction();
});
