$(document).ready(function() {

  if ($('#home').length>0) { 

     $(function(){
			$('#slideshow-wrapper').slides({
				preload: true,
				preloadImage: 'img/loading.gif',
				play: 5000,
				pause: 2500,
				hoverPause: true
			});
		});  
	 
	setScreen();
  }

  $(window).resize(function() {
    if ($('#home').length>0) { 
      setScreen(); 
	 }
  }); 

  //adjust slideshow width
  function setScreen() {
      var $winWidth = $(window).width();

	 if ($winWidth < 1400) {
	       var $diff = (($winWidth - 1280)/1.5);
		   		   if ($diff > 1) {$diff = $diff *-1;}
		   var $imageSize = $winWidth - 1280 +180;
	       $('#slideshow-wrapper').css('width',$winWidth+'px');
           $('#slideshow .slide').css('width',$winWidth+'px');
	       $('#slideshow .over-left').css('left',$diff+'px');
	   	   $('#slideshow .over-right').css('right',$diff+'px');
		   $('#slideshow  .slide .text-wrapper').css('width','840px');
		   if ($winWidth < 1281){
		       $('#slideshow .slide img').css('margin-left',$imageSize +'px');
		   }
		   
	  } 
	  
	  if ($winWidth >= 1400) {
           $('#slideshow-wrapper').css('width','1280px');
           $('#slideshow .slide').css('width','1280px');
		    $('#slideshow .slide img').css('margin','0px auto');
		    $('#slideshow .over-left').css('left','0px');
	   	   $('#slideshow .over-right').css('right','0px');
		   $('#slideshow  .slide .text-wrapper').css('width','900px');
	  }
 }
 

  tab2_init = false;
  $('.idTabs a.tab2').click(function(){ 
	if (!tab2_init) {
	tab2_init = true;
     $('#tab46 .featured-photos ul').jcarousel({ scroll: 1});

	  	//MW CUSTOM CODE REPLACEMENT FOR YT PLAYLIST
		$('#tab46 a.video-link').click(function(){
			var this_id = $(this).attr('id');
			var tmp = this_id.split('-');
			var this_row = tmp[2];
			$('#tab46 div.video').hide();
			$('#video-tab46-'+this_row).show();
			return false;
		}); 

	 //$("#tab46 ul.playlist").ytplaylist({addThumbs:true, autoPlay: false, holderId: 'video-tab46',playerHeight:368,playerWidth:608});
     $('#tab46 ul.playlist').jcarousel({ scroll: 1});
       $("#tab46 .twitterfeed").tweet({
          avatar_size: 54,
          count: 3,
          username: ["amaproflattrack"],
          loading_text: "searching twitter...",
          refresh_interval: 600
        });
	}
  }); 
  
 //Hidden as now handled in index.cfm   
/*
  $('.idTabs a.tab3').click(function(){ 
     $('#tab3 .featured-photos ul').jcarousel({ scroll: 1});
	 $("#tab3 ul.playlist").ytplaylist({addThumbs:true, autoPlay: false, holderId: 'video-tab3',playerHeight:368,playerWidth:608});
     $('#tab3 ul.playlist').jcarousel({ scroll: 1});
     $("#tab3 .twitter").tweet({
          avatar_size: 54,
          count: 2,
          username: ["amaprosbk","amaprosbk"],
          loading_text: "searching twitter...",
          refresh_interval: 120
        });
  }); 
  
  $('.idTabs a.tab4').click(function(){ 
     $('#tab4 .featured-photos ul').jcarousel({ scroll: 1});
	 $("#tab4 ul.playlist").ytplaylist({addThumbs:true, autoPlay: false, holderId: 'video-tab4',playerHeight:368,playerWidth:608});
     $('#tab4 ul.playlist').jcarousel({ scroll: 1});
     $("#tab4 .twitter").tweet({
          avatar_size: 54,
          count: 2,
          username: ["amaprosbk","amaprosbk"],
           loading_text: "searching twitter...",
          refresh_interval: 120
        });
      

  }); 

 */  //Hidden as now handled in index.cfm 
  
  tab5_init = false;
  $('.idTabs a.tab5').click(function(){ 
	if (!tab5_init) {
	tab5_init = true;
     $('#tab50 .featured-photos ul').jcarousel({ scroll: 1});

	  	//MW CUSTOM CODE REPLACEMENT FOR YT PLAYLIST
		$('#tab50 a.video-link').click(function(){
			var this_id = $(this).attr('id');
			var tmp = this_id.split('-');
			var this_row = tmp[2];
			$('#tab50 div.video').hide();
			$('#video-tab50-'+this_row).show();
			return false;
		}); 

	 //$("#tab50 ul.playlist").ytplaylist({addThumbs:true, autoPlay: false, holderId: 'video-tab50',playerHeight:368,playerWidth:608});
     $('#tab50 ul.playlist').jcarousel({ scroll: 1});
	 $(function(){
       $("#tab50 .twitterfeed").tweet({
          avatar_size: 54,
          count: 3,
          username: ["amaprohillclimb"],
          loading_text: "searching twitter...",
          refresh_interval: 600
        });
      });
	}
  }); 
  
  
  /* ********************************************************* */
 /* This runs when home page is loaded and when RR home page is loaded */
  // Section Front Page -- 45
  if ($('#tab45 .featured-photos ul').length>0) {   
    $('#tab45 .featured-photos ul').jcarousel({ scroll: 1});
  }
  
  if ($('#tab45 .twitterfeed').length>0) {   
	  $(function(){
       $("#tab45 .twitterfeed").tweet({
          avatar_size: 54,
          count: 3,
          username: ["amaprosbk"],
          loading_text: "searching twitter...",
          refresh_interval: 600
        });
      });
  }
  
  if ($('#tab45 ul.playlist').length>0) { 
  
  	//MW CUSTOM CODE REPLACEMENT FOR YT PLAYLIST
	$('#tab45 a.video-link').click(function(){
		var this_id = $(this).attr('id');
		var tmp = this_id.split('-');
		var this_row = tmp[2];
		$('#tab45 div.video').each(function(index){
			$(this).hide();
		});
		$('#video-tab45-'+this_row).show();
		return false;
	}); 
		  
	 //$("#tab45 ul.playlist").ytplaylist({addThumbs:true, autoPlay: false, holderId: 'video-tab45',playerHeight:368,playerWidth:608});
     $('#tab45 ul.playlist').jcarousel({ scroll: 1});
  }


if ($('#tab45').length == 0) {
	/* This should only run if tab45 not present, meaning we are not on home page or RR home page */
	  /* ********************************************************* */
	  // Section Front Page -- 46
	  if ($('#tab46 .featured-photos ul').length>0) {   
	    $('#tab46 .featured-photos ul').jcarousel({ scroll: 1});
	  }
	  
	  if ($('#tab46 .twitterfeed').length>0) {   
		  $(function(){
	       $("#tab46 .twitterfeed").tweet({
	          avatar_size: 54,
	          count: 3,
	          username: ["amaproflattrack"],
	          loading_text: "searching twitter...",
	          refresh_interval: 600
	        });
	      });
	  }
	  
	  if ($('#tab46 ul.playlist').length>0) {  	  
	  	//MW CUSTOM CODE REPLACEMENT FOR YT PLAYLIST
		$('#tab46 a.video-link').click(function(){
			var this_id = $(this).attr('id');
			var tmp = this_id.split('-');
			var this_row = tmp[2];
			$('#tab46 div.video').hide();
			$('#video-tab46-'+this_row).show();
			return false;
		}); 

		 //$("#tab46 ul.playlist").ytplaylist({addThumbs:true, autoPlay: false, holderId: 'video-tab46',playerHeight:368,playerWidth:608});
	     $('#tab46 ul.playlist').jcarousel({ scroll: 1});
	  }
	
	  /* ********************************************************* */
	  // Section Front Page -- 50
	  if ($('#tab50 .featured-photos ul').length>0) {   
	    $('#tab50 .featured-photos ul').jcarousel({ scroll: 1});
	  }
	  
	  if ($('#tab50 .twitterfeed').length>0) {   
		  $(function(){
	       $("#tab50 .twitterfeed").tweet({
	          avatar_size: 54,
	          count: 3,
	          username: ["amaprohillclimb"],
	          loading_text: "searching twitter...",
	          refresh_interval: 600
	        });
	      });
	  }
	  
	  if ($('#tab50 ul.playlist').length>0) {  	  

	  	//MW CUSTOM CODE REPLACEMENT FOR YT PLAYLIST
		$('#tab50 a.video-link').click(function(){
			var this_id = $(this).attr('id');
			var tmp = this_id.split('-');
			var this_row = tmp[2];
			$('#tab50 div.video').hide();
			$('#video-tab50-'+this_row).show();
			return false;
		}); 

		 //$("#tab50 ul.playlist").ytplaylist({addThumbs:true, autoPlay: false, holderId: 'video-tab50',playerHeight:368,playerWidth:608});
	     $('#tab50 ul.playlist').jcarousel({ scroll: 1});
	  }

} //Close if ($('#tab45').length == 0) {
 
 
  if ($('#sponsors').length>0) {   
//    $('#sponsors ul').jcarousel({ scroll: 1,auto:2,wrap:'last'});
    $('#sponsors ul').jcarousel({ scroll: 1,auto:2,wrap:'circular'});
    //$('#sponsors_list').jcarousel({ wrap:'circular'});
  }
 
  // lightbox for photos in gallery
   $(".featured-photos li a,ul.ep-list li a,table.gallery_photos td a").fancybox();

   
  // lightbox for photos in gallery
  $("a.play-video").click(function() {
	$.fancybox({
			'padding'		: 10,
			'autoScale'		: true,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		   : 600,
			'height'		: 450,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
   });

});

