// paths for sIFR unless overwrote on page level
var focolight = { src: 'swf/foco_light.swf' };
var focoregular = { src: 'swf/foco_regular.swf' };


$(document).ready(function() {
	
	// home page carousel call (jquery cycle)
	$('#carousel #slides').cycle({
	    fx: 'fade',
		speed: 500,
		timeout: 5000,		
		pause: 1,
		pager: '#carousel-nav'
	});

	$('ul.image-slideshow').cycle({
	    fx: 'fade',
		speed: 500,
		timeout: 5000,
		pause: 1
	});

	// "share" popup call (jquery tools tooltip module)
	$("a.share").tooltip({ 
		effect: 'toggle',
		position: 'bottom left',
		offset: [47, 233],
		predelay: 200,
		delay: 200,
		relative: true
	});

	$("#sister-links ul li#s3").tooltip({ 
		tip: '#sister-links ul li#s4',
		effect: 'toggle',
		position: 'bottom center',
		predelay: 200,
		delay: 200,
		relative: true
	});

	$("#news-story a.share").click(
		function() {
			return false;
		}
	);
	
// BEGIN BASIC HOVER FADES
	$("ul#nav li").hover(
		function(){
			$(this).find(".hoverbg").fadeIn(500);
		},
		function(){
			$(this).find(".hoverbg").stop(true,true).hide();
		}
	);
	
	$("ul.calendar-downloads li a, a.close-button, a.next-button, a.close-overlay, a.share").hover(
		function(){
			$(this).find("span, div").fadeIn(500);
		},
		function(){
			$(this).find("span, div").stop(true,true).hide();
		}
	);

	$("#assault-banner, #rankings-box .banner, #game-rankings #game-box").hover(
		function(){
			$(this).find(".hover-light div").fadeIn(500);
		},
		function(){
			$(this).find(".hover-light div").stop(true,true).hide();
		}
	);
		
	$("#highlights .linkbox").hover(
		function(){
			$(this).find(".view-button a").fadeIn(500);
		},
		function(){
			$(this).find(".view-button a").stop(true,true).hide();
		}
	);

	$("#highlights #carousel").hover(
		function(){
			$(this).find(".read-more a, .hover-light div").fadeIn(500);
		},
		function(){
			$(this).find(".read-more a, .hover-light div").stop(true,true).hide();
		}
	);

	$("#game-aside .game-link, #games-thumbs .game").hover(
		function(){
			$(this).find(".play-button a").fadeIn(500);
		},
		function(){
			$(this).find(".play-button a").stop(true,true).hide();
		}
	);
// END BASIC HOVER FADES
	
				
	$('#show-schedule ol#show-dates li:first-child').addClass("first-child");

	
	$('#rankings-box table tr').hover(
		function() {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		}
	);
		
	// maintains hover state while over social bookmarks
	$(".social-bookmarks").hover(
		function(){
			$('a.share span, .hover-light div').show();
		},
		function(){
			$('a.share span, .hover-light div').hide();
		}
	);
	
	// hover state for finalists
	$('#finalists > ol > li').hover(
		function(){
			if ($(this).hasClass("highlight"))
			{
				//
			}
			else {
				$(this).addClass("hover");
			}
			$(this).find("a.more-button span").fadeIn(500);
		},
		function(){ 
			$(this).removeClass("hover");
			$(this).find("a.more-button span").stop(true,true).hide();
		}
	);

	// hover state for scores
	$('#scores > ol > li').hover(
		function(){
			if ($(this).hasClass("highlight"))
			{
				//
			}
			else {
				$(this).addClass("hover");
			}
			$(this).find("a.watch-button span").fadeIn(500);
		},
		function(){ 
			$(this).removeClass("hover");
			$(this).find("a.watch-button span").stop(true,true).hide();
		}
	);

	// more button click
	$('#finalists > ol > li').click(function() {
		$(this).find(".more-button").hide();		
		$(this).addClass('highlight');	
		$(this).removeClass("hover");
		$(this).find(".more-details").show();
		$(this).siblings().hide();
		return false;
	});

	// close button click
	$('a.close-button').click(function() {
		$(this).parent().hide();
		$(this).parent().siblings('.more-button').show();
		$(this).parent().parent().removeClass('highlight').siblings().show();
		return false;
	});

	$(".more-details ul > li:odd").addClass("odd");
	$(".more-details ul li:last-child").addClass("last");

	$("#rankings-box table tr:odd").addClass("odd");
	$("#rankings-box table tr:last-child").addClass("last");

	$("ul.tabs").tabs("div#content-box > div.share_box", {
		current: 'active'
    });

	// close button click
	$('#close-btn').click(
		function() {
			$("#share_box").removeClass('show_box');
			return false;
		}
	);

	// share button click
	$('.share-button').click(
		function() {
			$("#share_box").toggleClass('show_box');
			return false;
		}
	);	
	
	// click events for video links
	$('#scores ol li').click(
		function() {
			var flashURL = $(this).children("a").attr("href"); var flv;
			$('.close-flash-movie').show();
			$('#game-container').empty();
			flashembed("game-container", { src: '../../swf/player/Main.swf', width: '550', height: '330', bgcolor:'#000100', wmode:'opaque', version: [9, 0] }, { skinUrl: '../../swf/player/skin.swf', videoUrl: flashURL });
			return false;
		}
	);	
	
	// close button for videos
	$('.share-game .close-flash-movie a').click(
		function() {
			$('.close-flash-movie').hide();			
			$('#game-container').empty();
			embedFlash();
		}
	);
	
	// assault course rollovers
	$("#game-rankings #game-box a.assault-hotspot").hover(
		function() {
			$('#assault-mapshade').fadeIn(200);
			$(this).prev().fadeIn(400);
			$(this).addClass("hotspot-over");
		},
		function() {
			$('#assault-mapshade').stop(true,true).hide();
			$(this).prev().stop(true,true).hide();
			$(this).removeClass("hotspot-over");
		}
	);

	// assault course overlays
	
	$('#game-rankings a#zipwire-hotspot').overlay({
		close: 'a.close-overlay',
		target: "#zipwire-overlay",
		absolute: true,
		left: 0,
		top: 0
	});
	$('#game-rankings a#tunnels-hotspot').overlay({
		close: 'a.close-overlay',
		target: "#tunnels-overlay",
		absolute: true,
		left: 0,
		top: 0
	});
	$('#game-rankings a#logs-hotspot').overlay({
		close: 'a.close-overlay',
		target: "#logs-overlay",
		absolute: true,
		left: 0,
		top: 0
	});
	$('#game-rankings a#hill-hotspot').overlay({
		close: 'a.close-overlay',
		target: "#hill-overlay",
		absolute: true,
		left: 0,
		top: 0
	});
	$('#game-rankings a#ratrun-hotspot').overlay({
		close: 'a.close-overlay',
		target: "#ratrun-overlay",
		absolute: true,
		left: 0,
		top: 0
	});
	$('#game-rankings a#cargonet-hotspot').overlay({
		close: 'a.close-overlay',
		target: "#cargonet-overlay",
		absolute: true,
		left: 0,
		top: 0
	});
	$('#game-rankings a#beams-hotspot').overlay({
		close: 'a.close-overlay',
		target: "#beams-overlay",
		absolute: true,
		left: 0,
		top: 0
	});
	$('#game-rankings a#tank-hotspot').overlay({
		close: 'a.close-overlay',
		target: "#tank-overlay",
		absolute: true,
		left: 0,
		top: 0
	});
	$('#game-rankings a#raftpull-hotspot').overlay({
		close: 'a.close-overlay',
		target: "#raftpull-overlay",
		absolute: true,
		left: 0,
		top: 0
	});

	$('a.close-overlay').click(function(){ return false; });
	

});
