var sponsorTimer;

$( function() {
  $("#navShop").mouseover(function() {
    $("#navflame").css('background-position','bottom left');
  }).mouseout(function() {
    $("#navflame").css('background-position','top left');
  });

  //$(".lavaLamp").lavaLamp({ speed: 400 });

  $('.boxToggle').click( function(){
  	 if ( $(this).attr('class').indexOf('News') != -1 ) {
  	 	if ( $(this).hasClass('kcbsNews') ) {
  	 		$('#bbqNewsSide').hide();
  	 		$('#kcbsNewsSide').show();
  	 	}
  	 	else {
  	 		$('#kcbsNewsSide').hide();
  	 		$('#bbqNewsSide').show();
  	 	}
  	 }
  	 else if ( $(this).attr('class').indexOf('Events') != -1 ) {
  	 	if ( $(this).hasClass('listEvents') ) {
  	 		$('#resultEventsSide').hide();
  	 		$('#listEventsSide').show();
  	 	}
  	 	else {
  	 		$('#listEventsSide').hide();
  	 		$('#resultEventsSide').show();
  	 	}
  	 }
  	 else {
  	 	if ( $(this).hasClass('memberVideos') ) {
  	 		$('#sponsorVideosSide').hide();
  	 		$('#memberVideosSide').show();
  	 	}
  	 	else {
  	 		$('#memberVideosSide').hide();
  	 		$('#sponsorVideosSide').show();
  	 	}
  	 }
  	 
  	 $(this).parent().find('.boxToggle').removeClass('active').addClass('inactive');
  	 $(this).removeClass('inactive').addClass('active');
  });
  
  $('#nav li').hover( function(){
  	$(this).css('background', 'url(images/nav_arrow.jpg) top center no-repeat');
  }, function(){
  	$(this).css('background', 'transparent');  
  });
  
  if ( !$('a.navBtn .dropdown').length ) {
  	$('a.navBtn').next('.dropdown').appendTo( $('a.navBtn') ).find('a.navBtn').remove();
  }
  
  $('a.navBtn:last').mouseenter( function(){
  	$(this).find('.dropdown').css('display','block');
  }).mouseleave( function(){
  	$(this).find('.dropdown').css('display','none');
  }).find('.dropdown a').click( function(){
  	window.location = $(this).attr('href');
  	return false;
  }).hover( function(){
  	$(this).css('textDecoration','underline');
  }, function(){
  	$(this).css('textDecoration','none');
  });
  
  $('#whyjoin').mouseenter( function(){
  	$('#joinMessage').fadeIn(200);
  }).mouseleave( function(){
  	$('#joinMessage').fadeOut(200);  
  });
  
  $('#clickTab').click( function(){
  	if ( parseFloat($('#memberSigninBox').css('top')) < 0 ) {
  	  $('#memberSigninBox').animate( {top:0}, 700 );
  	}
  	else {
  	  $('#memberSigninBox').animate( {top:'-44px'}, 500 );
  	}
  }).hover( function(){
  	$(this).css('cursor','pointer');
  });
  
  if ( $('#sponsorsContainer').length ) {
  	 $('#sponsorsContainer').bind('moveSlides', function(){
 		clearTimeout( sponsorTimer );

  	 	$('#sponsorsScroll').animate( { marginLeft:'-218px' }, 600, function(){
  	 		var newSponsor = $('#sponsorsScroll .sponsorItem:visible:first').clone();
  	 		$(newSponsor).appendTo( $('#sponsorsScroll') );
  	 		$('#sponsorsScroll .sponsorItem:visible:first').remove();
  	 		$('#sponsorsScroll').css('marginLeft', 0);  	 		
  	 		
 			sponsorTimer = setTimeout(sponsorSlide, 4000);
  	 	});
   	 });
  	 
  	 sponsorTimer = setTimeout(sponsorSlide, 4000);
  }
});

function sponsorSlide(){
	$('#sponsorsContainer').trigger('moveSlides');
}

function closeVideo() {
	$('#smallVideoPlayer, #smallVideoClose').hide();
	return false;
}

function loadVideo(videoFile) {
	flowplayer("smallVideoPlayer", {
	  src: "videos/flowplayer-3.1.5.swf", wmode:"transparent"}, {
	  clip: { 
        url: 'videos/' + videoFile, 
        autoPlay: false,  
        autoBuffering: true
      }
	});
	
	$('#smallVideoPlayer, #smallVideoClose').show();
	$f().play();
	
	return false;
}

function loadLargeVideo(videoFile, title, summary, autoPlay) {
	flowplayer("largeVideoPlayer", {
	  src: "videos/flowplayer-3.1.5.swf", wmode:"transparent"}, {
	  clip: { 
        url: 'videos/' + videoFile, 
        autoPlay: false,  
        autoBuffering: true
      }
	});
	
	$('#playerTitle').html(title);
	$('#playerSummary').html(summary);
	
	if ( autoPlay ) {
		$f().play();
	}
	
	return false;
}

function loadYoutubeVideo(videoFile, title, summary, autoPlay) {	
	$('#largeVideoPlayer').html('<object width="445" height="315"><param name="movie" value="http://www.youtube.com/v/' + videoFile + '&hl=en_US&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + videoFile + '&hl=en_US&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="445" height="315"></embed></object>');
	$('#playerTitle').html(title);
	$('#playerSummary').html(summary);
	
	return false;
}

/***** Legacy functions *****/
function preload()
{
  images = new Array(numImages);
  for( var i = 0; i < numImages; i++) {
    var imgName = names[i];
    images[i] = new Image();
    images[i].src = "images/nav/nav2o_"+imgName+".gif";
  }
}

function show(id)
{
  document.getElementById(id).style.display = "block";
}

function hide(id)
{
  document.getElementById(id).style.display = "none";
}