$(document).ready(function()
{
	//set up slides
	var currentPosition = 0;
	var anchorMargin = 0;
	var slideHeight = 375;
	var slides = $('.slide');
	var numberOfSlides = slides.length;

	// Wrap all .slides with #slideInner div
	slides.wrapAll('<div id="slideInner"></div>')
  	// Float left to display vertically, readjust .slides width
	.css({
    	'height' : slideHeight
	});


	//sort out anchors passed in
	var myFile = document.location.toString();
	// if the URL contains an anchor
	if (myFile.match('#'))
	{
		//must be pointing to an anchor
		if(myFile.split('#')[1] != '')
		{
			// click the navigation item corresponding to the anchor
			var myAnchor = '#' + myFile.split('#')[1];
			//highlight focus class
			$('#info-section-navigation > ul > li a[href="' + myAnchor + '"]').parent().addClass("focus");
			var mainNavLinks = $('#info-section-navigation > ul > li');
			// Determine new position
			currentPosition = mainNavLinks.index($('#info-section-navigation > ul > li a[href="' + myAnchor + '"]').parent());
			anchorMargin = currentPosition * slideHeight;
		}
	}
	else
	{
		//put focus on first link
		$('#info-section-navigation > ul > li:first').addClass("focus");
	}
		
	//Grab the original BG color of the link
	var originalBG = $(".animate").css("background-color");
	
	//The color you want to fade too
	var fadeColor = "#CCCCCC";

	$('#info-section-navigation > ul > li')
	.hover(function()
	{
			$(this).children("a").animate({ color: "#7c22aa"}, 400);
		}
		,function()
		{
			$(this).children("a").animate({ color: "#6f6f6f" }, 200);
	})
	
	//firefox only
	if (($.browser.mozilla && $.browser.version >= "1.8") || ($.browser.safari))
	{
		$('#top-25-leaderboard')
		.hover(function()
		{
				$(this).css({'overflow' : 'auto'});
			}
			,function()
			{
				$(this).css({'overflow' : 'hidden'});
		})	
	}
	
	$('.normal')
		.click(function(){
		    
		    		
				//reset previous focus
				//get which link was clicked
				var mainNavLinks = $('#info-section-navigation > ul > li');
				// Determine new position
				currentPosition = mainNavLinks.index(this);
				//get which link has been selected
				currentLink = $(this).children("a").attr("href").split('#')[1];
				//do the specific fading
				switch(currentLink)
				{
					case "more-than-a-game":
						if($("#ultimate-rugby-prize > div").css("opacity") != 0)
							$("#ultimate-rugby-prize > div").fadeOut(400);						
						if($("#how-to-register > div").css("opacity") != 0)
							$("#how-to-register > div").fadeOut(400);
						if($("#your-performance > div").css("opacity") != 0)
							$("#your-performance > div").fadeOut(400);
						if($("#top-25-leaderboard > div").css("opacity") != 0)
							$("#top-25-leaderboard > div").fadeOut(400);
					break;
					
					case "ultimate-rugby-prize":
						$("#ultimate-rugby-prize > div").fadeIn(1000);
						if($("#how-to-register > div").css("opacity") != 0)
							$("#how-to-register > div").fadeOut(400);
						if($("#your-performance > div").css("opacity") != 0)
							$("#your-performance > div").fadeOut(400);
						if($("#top-25-leaderboard > div").css("opacity") != 0)
							$("#top-25-leaderboard > div").fadeOut(400);
					break;
					
					case "how-to-register":
						$("#how-to-register > div").fadeIn(1000);
						if($("#ultimate-rugby-prize > div").css("opacity") != 0)
							$("#ultimate-rugby-prize > div").fadeOut(400);
						if($("#top-25-leaderboard > div").css("opacity") != 0)
							$("#top-25-leaderboard > div").fadeOut(400);
					break;
					
					case "your-performance":
						$("#your-performance > div").fadeIn(1000);
						if($("#ultimate-rugby-prize > div").css("opacity") != 0)
							$("#ultimate-rugby-prize > div").fadeOut(400);
						if($("#top-25-leaderboard > div").css("opacity") != 0)
							$("#top-25-leaderboard > div").fadeOut(400);
					break;
					
					case "top-25-leaderboard":
						$("#top-25-leaderboard > div").fadeIn(1000);
						if($("#ultimate-rugby-prize > div").css("opacity") != 0)
							$("#ultimate-rugby-prize > div").fadeOut(400);
						if($("#how-to-register > div").css("opacity") != 0)
							$("#how-to-register > div").fadeOut(400);
						if($("#your-performance > div").css("opacity") != 0)
							$("#your-performance > div").fadeOut(400);
					break;
					
					default:;
				}
				// Move slideInner using margin-top
				$('#slideInner').animate(
					{'marginTop' : (slideHeight*(-currentPosition)) + anchorMargin}
				);
				//we need to reset the previous focus class
				$(".focus").addClass("normal").removeClass("focus");				
				//then we need to change this focus class to normal
				$(this).removeClass("normal").addClass("focus");
				
								
				return false;
			});

      $(function(){
		  $('a.external').click(function(){
			  window.open(this.href);
			  return false;
		  });
      });
});

var flashvars = { "tickersource": "ticker_en.xml" };

var params = {
	menu: "false",
	scale: "noScale",
	background : "",
	allowFullScreen: "false",
	allowScriptAccess: "always",
	play: "true",
	wmode : "transparent",
	loop: "false",
	id: "news-ticker-flash"
};
swfobject.embedSWF("../ticker/ticker.swf", "news-ticker-flash", "960", "76", "9.0.0", "expressInstall.swf", flashvars, params);


