// 	Cufon 
	Cufon.set('selector', jQuery); 
    Cufon.replace('.replace-font');    
    Cufon.replace('#main-navigation>ul>li>a', {hover: true});
   
    
// Slider
$(document).ready(function(){
	
  if(document.getElementById('latest-highlight')!=null){
    $('#latest-highlight .slideshow').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 5000,
        pager:  '#figure-switcher ul',
        prev:   '#prevBtn a', 
	    next:   '#nextBtn a', 
        pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#figure-switcher ul li:eq(' + idx + ')'; 
    }
    });
  }

//menu bar
  $('#main-navigation ul li').hover(function(){
	  	$(this).children('.sub-categories').show();
	  	},
	  	function () {
	    $(this).children('.sub-categories').hide();
	  });
	  
  $('#main-navigation ul li .sub-categories').hover(function(){
	$(this).parent().addClass('hover');
  	},
  	function () {
	$('#main-navigation ul li').removeClass('hover');
  });
	  
  
  /*photo-detail click next*/
  $('#imgnext').click(function(){
	  
	  /*get count image*/
	  var len_img = $('#photo-summary ol li').length;
	  
	  /*get number of hidden input*/
	  var off_cnt = 0;
	  for(var i=0;i<len_img;i++){
		  if($('#hidd_'+(i+1)).val() != '1'){
			  off_cnt++;
		  }
	  }
	  
	  var cnt_next = $('#timer_var').attr('value') ;
	  cnt_next = parseInt(cnt_next) + 6;
	  
	  if(cnt_next < len_img){
		  $('#photo-summary ol').children().css('display','none');
		  for(var j=0;j<6;j++){
			  $('#photo-summary ol').children(':eq('+(cnt_next+j)+')').css('display','block');
		  }
		  
		  $('#timer_var').attr('value',cnt_next);
	  }

  });
  
  /*photo-detail click prev*/
  $('#imgprev').click(function(){

	  
	  /*get count image*/
	  var len_img = $('#photo-summary ol li').length;
	  
	  var cnt_prev = $('#timer_var').attr('value') ;
	  cnt_prev = parseInt(cnt_prev) - 6;
	  
	  if(cnt_prev >= 0){
		  $('#photo-summary ol').children().css('display','none');
		  for(var j=0;j<6;j++){
			  $('#photo-summary ol').children(':eq('+(cnt_prev+j)+')').css('display','block');
		  }
		  
		  $('#timer_var').attr('value',cnt_prev);
	  }
	  
	  

  });
  
  /*photo-detail click img pager*/
  $('#photo-summary ol li').click(function(){
	  
	  //stop play when click
	  $('#navi-play').text("Play");
	  $('#pause_var').val('1');
	  
	  /*set all active class remove*/
	  $('#photo-summary ol').find('a').removeClass('active-slide');
	  /*set src image fullsize*/
	  //$('#photo-wrapper figure a img').attr('src',$(this).find('img').attr('src'));
	  $('#photo-wrapper figure').find('img').attr('src',$(this).find('img').attr('src'));
	  /*set caption desc*/
	  //$('#caption_desc').find('p').text($(this).find('img').attr('alt'));
	  $('#caption_desc').find('p').html($(this).find('img').attr('alt'));
	  /*set li selected active a class */
	  $(this).find('a').addClass('active-slide');
	  /*set list of all image*/
	  var list_page = $(this).find('img').attr('id') + ' of ' + $('#photo-summary ol li').length;
	  // $('#photo-wrapper figure p').text(list_page);
	  //alert(list_page);
	  $('#photo-wrapper figure').find('p').text(list_page);
	  /*get count image*/ 
	  
  });
  
  function GetParam(param) {
	  //get child node
	  var path = $('#photo-summary ol li:eq('+param+')').find('img');
	  
	  //set full size image
	  //$('#photo-wrapper figure a img').attr('src',path.attr('src'));
	  $('#photo-wrapper figure').find('img').attr('src',path.attr('src'));
	  //set image caption
	  //$('#caption_desc').find('p').text(path.attr('alt'));
	  $('#caption_desc').find('p').html(path.attr('alt'));
	  //set list of all image
	  var list_page = path.attr('id') + ' of ' + $('#photo-summary ol li').length;
	  //$('#photo-wrapper figure p').text(list_page);
	  $('#photo-wrapper figure').find('p').text(list_page);
  };
  
  /*photo-detail click next pics*/
  $('#navi-next').click(function(){
	  
	  //stop play when click
	  $('#navi-play').text("Play");
	  $('#pause_var').val('1');
	  
	  //check class active where li live
	  
	  var len_img = $('#photo-summary ol li').length;
	  var arr_selected = 'x';
	  var start_six = parseInt($('#timer_var').attr('value')) ;
	  var end_six = start_six + 5;
	  var start_nextsix = start_six + 6;
	  
	  for(var i=0;i<len_img;i++){
		  
		  //chk select
		  if($('#photo-summary ol li:eq('+i+') a').attr('class') == 'active-slide'){
			  
			  arr_selected = parseInt(i);
			  
			  if(i+1 != len_img){
				  
				  $('#photo-summary ol li:eq('+i+') a').removeClass('active-slide');
				  $('#photo-summary ol li:eq('+(i+1)+') a').addClass('active-slide');
				  GetParam(i+1);
				  
				  if((arr_selected+1) > end_six){//> limit
					  
					  //shift right 6 position
					  $('#photo-summary ol').children().css('display','none');
					  for(var j=0;j<6;j++){
						  $('#photo-summary ol').children(':eq('+(start_nextsix+j)+')').css('display','block');
					  }
					  
					  $('#timer_var').attr('value',start_nextsix);
				  }
				  
			  }

			  break;
		  }

	  }
	   
  });

  
  /*photo-detail click prev pics*/
  $('#navi-prev').click(function(){
	  
	  //stop play when click
	  $('#navi-play').text("Play");
	  $('#pause_var').val('1');

	  //check class active where li live
	  var len_img = $('#photo-summary ol li').length;
	  var arr_selected = 'x';
	  var start_six = parseInt($('#timer_var').attr('value')) ;
	  var end_six = start_six + 5;
	  var start_prevsix = start_six - 6;
	
	  
	  for(var i=0;i<len_img;i++){
		  //chk select
		  
		  if($('#photo-summary ol li:eq('+i+') a').attr('class') == 'active-slide'){
			  arr_selected = i;
			  
			  //!first item
			  if(i+1 != 1){
				  
				  //set prev show
				  $('#photo-summary ol li:eq('+i+') a').removeClass('active-slide');
				  $('#photo-summary ol li:eq('+(i-1)+') a').addClass('active-slide');
				  GetParam(i-1);
				  
				  if((arr_selected) == start_six){//is == start_six
					  
					  //shift left 6 position
					  $('#photo-summary ol').children().css('display','none');
					  
					  for(var j=0;j<6;j++){
						  $('#photo-summary ol').children(':eq('+(start_prevsix+j)+')').css('display','block');
					  }
					  
					  $('#timer_var').attr('value',start_prevsix);
					  
				  }

			  }
			  break;
		  }

	  }
	  
  });
	
  $('#navi-play').click(function(){
	  
	  
	  var len_img = $('#photo-summary ol li').length;
	  var arr_selected = 0;
	  
	  for(var i=0;i<len_img;i++){

		  if($('#photo-summary ol li:eq('+i+') a').attr('class') == 'active-slide'){
			  arr_selected = i;
			  break;
		  } 
	  }
	  
	  if($('#navi-play').text() == 'Play'){
		  //change to pause
		  $('#navi-play').text("Pause");
		  $('#pause_var').val('0');
		  setTimeout(function(){testLoop(arr_selected)},2500);
	  }
	  else
	  {
		  $('#navi-play').text("Play");
		  $('#pause_var').val('1');
	  }

  });
  
  function testLoop(param) {//recursive loop
	  
	  var start_six = parseInt($('#timer_var').attr('value')) ;
	  var end_six = start_six + 5;
	  var start_nextsix = start_six + 6;
	  
	  if($('#pause_var').val() != '1' ){
	  
		  var len_img = $('#photo-summary ol li').length
	  
		  if(param+1 != len_img){
	  
			  if((param+1) > end_six){//> limit
				  
				  $('#photo-summary ol li').css('display','none');
				  
				  //shift right 6 position
				  $('#photo-summary ol').children().css('display','none');
				  for(var j=0;j<6;j++){
					  $('#photo-summary ol').children(':eq('+(start_nextsix+j)+')').css('display','block');
				  }
				  
				  $('#timer_var').attr('value',start_nextsix);
			  }

			  //set next show
			  $('#photo-summary ol li:eq('+param+') a').removeClass('active-slide');
			  $('#photo-summary ol li:eq('+(param+1)+') a').addClass('active-slide');
			  GetParam(param+1);
			  param = param +1;
			  
			  if(param < $('#photo-summary ol li').length ){
		    	  setTimeout(function(){testLoop(param)},2500);
		      }
			  
		  }
		  else
		  {//last return to first 
			  
			  $('#photo-summary ol li').css('display','none');
			  
			  for(var j=0;j<6;j++){
				  $('#photo-summary ol').children(':eq('+(j)+')').css('display','block');
			  }
			  
			  $('#timer_var').attr('value',0);
			  
			  GetParam(0);
			  
			  $('#photo-summary ol li:eq('+(len_img-1)+') a').removeClass('active-slide');
			  $('#photo-summary ol li:eq(0) a').addClass('active-slide');
			  
			  setTimeout(function(){testLoop(0)},2500);
		  }
	  
	  }
	  else
	  {
		  $('#pause_var').val('0');
	  }
      
  };
  
  
  
});
