$(window).load(function() {
	
	delay('logoFadeOut', 2000);
	delay('contentSwapper', 3000);

	function delay(functionName, time)
	{
		setTimeout(function() { eval(functionName)(); }, time);
	}

	function logoFadeOut()
	{
		$('#logo').fadeOut(1000, function() { fadeInContent(); });		
	}	
	
	function fadeInContent()
	{
		$('#fadingContent').fadeIn(1000);
	}
	
	var sections 	= ['campaigns','displays', 'interactive',  'printandpublications', 'websites'];
	var numSections = sections.length;
	
	// these are the individual campaigns for each section. each array value is a folder name
	var campaigns 				= ['Mini', 'QH feeling good'];
	var displays				= ['DME 1', 'DME 2', 'QT'];
	var interactive				= ['QT break test'];
	var printandpublications	= ['HD vibe', 'Pymble doc', 'QH child health', 'QT code of conduct', 'Qt school road safety'];
	var websites				= ['JCY', 'QT kids'];

	var randomSection	= [];
	var randomCampaign	= [];
	var lastRandomSection = 999;
	var i = 0;
	var notTooMuchInteractive = 0;
	
	function contentSwapper()
	{
		randomSection = Math.floor(Math.random()*4);
			
		if(randomSection==lastRandomSection)
		{
			randomSection+= 1;
			
			if(randomSection + 1 > numSections)
			{
				randomSection=4;
			}
		}
		
		if(randomSection==2) // interactive was showing too much, and print and publications was not showing enough. Dirty, but quick.
		{
			if(notTooMuchInteractive==1)
			{
				randomSection = 3;
				notTooMuchInteractive = 0;
			}
			else
			{
				notTooMuchInteractive=1;
			}				
		}

		lastRandomSection = randomSection;
		
		randomCampaign = Math.floor(Math.random()*eval(sections[randomSection]).length);
		$('#heading').attr('src', 'Images/headings-' + sections[randomSection] + '.gif');
		$('#contentImage').attr('src', 'Images/' + sections[randomSection] + '/' + eval(sections[randomSection])[randomCampaign] + '/1.gif');

		$('#fadingContent').fadeIn(1000);
		//easeIn();
		
		i++;
		
		delay('contentFadeOut', 5000);
	}
	
	function contentFadeOut()
	{
		$('#fadingContent').fadeOut(700);
		delay('contentSwapper', 700);
	}
	
	var leftOrRight='left';
	
	function easeIn()
	{		
		if(leftOrRight=='left')
		{
			$('#contentImage').css('left', '0');
			$('#contentImage').animate({ left:15 }, {duration: 2500, easing: 'easeOutSine'});
			leftOrRight='right';	
		}
		else
		{
			$('#contentImage').css('left', '15');
			$('#contentImage').animate({ left:0 }, {duration: 2500, easing: 'easeOutSine'});
			leftOrRight='left';
		}
	}	
});
