/*
 * styles.js for Debut Ver.201010
 *
 * Copyright (C) 2011 HOKUTO Co.,Ltd.
 *
 */
 
var curNum = 0;
var imageLength = 0;
var mov = 30;
var nextPos = 0;

jQuery.noConflict();
jQuery(document).ready(function($){
   
   /*ヘッダー*/
   $('ul.support li:last').css('border','none');
   $('ul.support li:first').css('padding-left','0');
   $('ul.support li:last').css('padding-right','0');
   /*$('ul.util li:last a').css('padding-right','0');*/
   $('ul.util li').slice(0,5).css('padding-top','5px');
   
   $('.prolist a').hover( 
	  function(){
	    $(this).parents('.prolist').css('background-color','#E9E9D6');
	  },
	  function(){
		$(this).parents('.prolist').css('background-color','#FFFFFF');
	  }
   );
   
   /*トップページ・カテゴリーナビ*/
   $('.listContainer:first').css('border-top','1px dotted #cccccc');
   $('.listContainer').each(function(){
		$(this).children('.listHangerTop:last').css('border-right','none');
   });
   
   /*トップページ・バナー*/
   $('.topBanner').slice(0,3).css('margin','30px 0 0 0');
   $('.topBanner').slice(3,6).css('margin','20px 0 10px 0');
   $('.topBanner').slice(1,2).css('margin','30px 10px 0 10px');
   $('.topBanner').slice(4,5).css('margin','20px 10px 10px 10px');
   
   /*カテゴリーインデックス*/
   $('.listHanger:first').children('.prolist').css('border-top','1px solid #E9E9D6');
   $('.listHanger').each(function(){
	 $(this).children('.prolist:first').css('width',163);
   });
   
   /*コーディネート特集*/
   $('#cate1').css({"top": "205px","left": "785px"});
   $('#cate2').css({"top": "160px","left": "435px"});
   $('#cate3').css({"top": "130px","left": "720px"});
   $('#cate4').css({"top": "-170px","left": "620px"});
   $('#cate5').css({"top": "-130px","left": "640px"});
   $('#cate6').css({"top": "-40px","left": "595px"});
   $('#cate7').css({"top": "-310px","left": "365px"});
   $('#cate8').css({"top": "-410px","left": "780px"});
   $('#cate9').css({"top": "-290px","left": "20px"});
   $('#cate10').css({"top": "-530px","left": "200px"});
   $('#cate11').css({"top": "-390px","left": "290px"});
   $('#cate12').css({"top": "-605px","left": "120px"});
   $('#cate13').css({"top": "-760px","left": "440px"});
   $('#cate14').css({"top": "-360px","left": "20px"});
   
   if($.browser.msie && $.browser.version < 7){
	   for(i=1; i<15; i++){
		   var cateID = '#cate'+i;
		   var newImage = 'cate'+i;
		   $(cateID).children('a').children('img').attr('src','img/sp03/'+newImage+'2.gif');
	   }
   }
   
   /*$('.pointer').each(function(){
	   $(this).hover( 
		  function(){
		    $(this).children('a').children('img').css('border','2px solid #cccccc');
		  },
		  function(){
		    $(this).children('a').children('img').css('border','none');
		  }
	   );
	});*/
   $('.cateListHanger:first').css('border-top','1px solid #CCCCCC');
   
   $('.listHangerSP').each(function(){
		    $(this).children('.proList:first').css('margin-left',0);
   });
   
   window.onload = function(){
	   
	   /*トップページ・カテゴリーナビ*/   
       var numTop = 0;

       $('.listContainer').each(function(){
	       numTop++;
           var newName = 'arr'+numTop;
           var newName = new Array();
	       $(this).children('.listHangerTop').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('.listHangerTop').each(function(){
		      $(this).css('height',n);
	       });
       });
	   
	   /*カテゴリーインデックス*/   
       var numCate = 0;

       $('.listHanger').each(function(){
	       numCate++;
           var newName = 'arr'+numCate;
           var newName = new Array();
	       $(this).children('.prolist').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('.prolist').each(function(){
		      $(this).css('height',n-20);
	       });
       });
	   
	   /*かんたんご利用ガイド*/
   　　var num = 0;
       var leng = $('.Hanger').length;

       $('.userGuideInner').each(function(){
	       num++;
           var newName = 'arr'+num;
           var newName = new Array();
	       $(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);
	       });
       });
	   
	   /*特集ページ*/
	   var num02 = 0;
       var leng02 = $('.cateListHanger').length;
   
       $('.cateListHanger').each(function(){
		    $(this).children('dl:first').css('width',238);
		    num02++;
            var newName = 'arr'+num02;
            var newName = new Array();
	        $(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-15);
	       });
       });       
   
       var num03 = 0;
       var leng03 = $('.listHangerSP').length;
   
       $('.listHangerSP').each(function(){
		    num03++;
            var newName = 'arr'+num03;
            var newName = new Array();
	        $(this).children('.proList').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('.proList').each(function(){
	          $(this).children('a').children('dl').css('height',n-15);
	        });
       });
	   
	   /*インデックスビジュアル*/
	   imageLength = $('#mainBanner ul li').length;
	
	   $('#bannerThumb ul li img').click(function(){
	       clearTimeout(timerID);
	       var index = $('#bannerThumb ul li img').index(this);
		   curNum = index;
		   Actions();
	   });
	
	   var limitPos = (imageLength-5)*-mov;
	
	   $('#upBtn').click(function(){
	       if(nextPos<0){
		       nextPos=nextPos+mov;
	           $('#bannerThumbInner ul').animate({"top": nextPos},250);
		   }
	   });
	   $('#downBtn').click(function(){
		   if(nextPos>limitPos){
		       nextPos=nextPos-mov;
	           $('#bannerThumbInner ul').animate({"top": nextPos},250);
		   }
	   });
	
	   Actions();
   }
   
});

function Actions(){
    if(curNum==imageLength){
	  curNum = 0;
	}
	var limitPos = (imageLength-5)*-mov;
    curNum+=1;
	jQuery('#bannerThumb ul li img').each(function(){
	    jQuery(this).css('left',0);
	});
	jQuery('#mainBanner ul li').each(function(){
	    var alpha = jQuery(this).css('opacity');
		if(alpha==1){
		    var newIndex = jQuery('#mainBanner ul li').index(this);
			jQuery('#test').text(newIndex);
			jQuery('#mainBanner ul li').slice(newIndex,newIndex+1).animate({'opacity': '0'},250,function(){jQuery(this).css('display','none');});
		}
	});
	jQuery('#bannerThumb ul li img').slice(curNum-1,curNum).css('left',-200);
	jQuery('#mainBanner ul li').slice(curNum-1,curNum).css('display','inline');
	jQuery('#mainBanner ul li').slice(curNum-1,curNum).animate({'opacity': '1'},250);
	var thumbCur = (curNum-1)-3;
	if(thumbCur>0){
	   if(nextPos>limitPos){
		   nextPos=-mov*thumbCur;
	       jQuery('#bannerThumbInner ul').animate({"top":nextPos},250);
	   }
	}
	if(curNum-1==0){
	    if(nextPos<0){
	       jQuery('#bannerThumbInner ul').animate({"top": 0},250);
		   nextPos = 0;
		}
	}
    timerID = setTimeout("Actions()", 5000);
}
