$(document).ready(function(){
	
	//IE6 HOVER FIX (PNG's fucking IE6...)
	$('#footerLinks a, #footerFlags li a').hover(
		function() {$(this).parent('li').css({'background-position':'top right'})},
		function() {$(this).parent('li').css({'background-position':'top left'})}
	);
	
	//HISTORY SUBSECTIONS TOGGLER
	$('#btnEvolution').css({'background-position':'top right'});

	$('#historyNavbar li a').click(function(){
		$('#historyNavbar li a').css({'background-position':'top left'});
		$(this).css({'background-position':'top right'});
	});
	
	$('#btnEvolution').click(function(){
		$('#subStory, #subName, #subSecret').fadeOut(300);
		setTimeout("$('#subEvolution').fadeIn(400);",500);
	});
	$('#btnStory').click(function(){
		$('#subEvolution, #subName, #subSecret').fadeOut(300);
		setTimeout("$('#subStory').fadeIn(400);",500);
	});
	$('#btnName').click(function(){
		$('#subEvolution, #subStory, #subSecret').fadeOut(300);
		setTimeout("$('#subName').fadeIn(400);",500);
	});
	$('#btnSecret').click(function(){
		$('#subEvolution, #subStory, #subName').fadeOut(300);
		setTimeout("$('#subSecret').fadeIn(400);",500);
	});
	
	//EVOLUTION SCREENS TOGGLER
	$('#subEvolution ul li img:first').css({'width':'290px','height':'208px'});
	$('#subEvolution ul li img').click(function(){
		$('#subEvolution ul li img').animate({width:133,height:103});
		$(this).animate({width:290,height:208});
	});
	
	//MOBILE+IPHONE+DSI SUBSECTIONS TOGGLER
	$('#btnDesc').css({'background-position':'top right'});
	
	$('#subNavbar li a').click(function(){
		$('#subNavbar li a').css({'background-position':'top left'});
		$(this).css({'background-position':'top right'});
	});
	
	$('#btnDesc').click(function(){
		$('#subScreens, #subTrailer, #subBuy, #subKey').fadeOut(300);
		$('#screenshotsContainer ul li div').fadeOut(1);
		$('#iphoneSSContainer ul li div').fadeOut(1);
		$('#dsiSScontainer ul li div').fadeOut(1);
		setTimeout("$('#screenSizedBackground').animate({top:20});",500);
		setTimeout("$('#subDesc').fadeIn(400);",500);
	});
	$('#btnScreens').click(function(){
		$('#subDesc, #subTrailer, #subBuy, #subKey').fadeOut(300);
		setTimeout("$('#subScreens').fadeIn(400);",500);
		setTimeout("$('#screenSizedBackground').animate({top:-64});",500);
		setTimeout("$('#screenshotsContainer ul li div:first').fadeIn(300);",1000);
		setTimeout("$('#iphoneSSContainer ul li div:first').fadeIn(300);",1000);
		setTimeout("$('#dsiSScontainer ul li div:first').fadeIn(300);",1000);
	});
	$('#btnTrailer').click(function(){
		$('#subDesc, #subScreens, #subBuy, #subKey').fadeOut(300);
		$('#screenshotsContainer ul li div').fadeOut(1);
		$('#iphoneSSContainer ul li div').fadeOut(1);
		$('#dsiSScontainer ul li div').fadeOut(1);
		setTimeout("$('#screenSizedBackground').animate({top:20});",500);
		setTimeout("$('#subTrailer').fadeIn(400);",500);
	});
	$('#btnBuy').click(function(){
		$('#subDesc, #subScreens, #subTrailer, #subKey').fadeOut(300);
		$('#screenshotsContainer ul li div').fadeOut(1);
		$('#iphoneSSContainer ul li div').fadeOut(1);
		$('#dsiSScontainer ul li div').fadeOut(1);
		setTimeout("$('#screenSizedBackground').animate({top:20});",500);
		setTimeout("$('#subBuy').fadeIn(400);",500);
	});
	$('#btnKey').click(function(){
		$('#subDesc, #subScreens, #subTrailer, #subBuy').fadeOut(300);
		$('#screenshotsContainer ul li div').fadeOut(1);
		$('#iphoneSSContainer ul li div').fadeOut(1);
		$('#dsiSScontainer ul li div').fadeOut(1);
		setTimeout("$('#screenSizedBackground').animate({top:20});",500);
		setTimeout("$('#subKey').fadeIn(400);",500);
	});
	
	// SCREENSHOTS GALLERY
	$('#screenshotsContainer ul li img:first').animate({opacity:0.4},300);
	$('#prevScreensLink').hide();
	$('#screenshotsContainer ul li').click(function(){
		$('#screenshotsContainer ul li div').fadeOut(400);
		$('#screenshotsContainer ul li img').animate({opacity:1},100);
		$(this).find('img:first').animate({opacity:0.4},100);
		$(this).find('div').fadeIn(400);
	});
	
	// SCREENSHOTS PAGER
	$('#nextScreensLink').click(function(){
		$('#screens_a').hide();
		$('#nextScreensLink').hide();
		$('#screens_a li div').hide();
		$('#screens_a li img').animate({opacity:1},300);
		$('#screens_b').fadeIn(300);
		$('#prevScreensLink').fadeIn(300);
		$('#screens_b li div:first').fadeIn(300);
		$('#screens_b li img:first').animate({opacity:0.4},300);
	});
	$('#prevScreensLink').click(function(){
		$('#screens_b').hide();
		$('#prevScreensLink').hide();
		$('#screens_b li div').hide();
		$('#screens_b li img').animate({opacity:1},300);
		$('#screens_a').fadeIn(300);
		$('#nextScreensLink').fadeIn(300);
		$('#screens_a li div:first').fadeIn(300);
		$('#screens_a li img:first').animate({opacity:0.4},300);
	});
	
	// iPHONE SCREENSHOTS GALLERY
	$('#iphoneSSContainer ul li img:first').animate({opacity:0.4},300);
	$('#iPhoneprevScreensLink').hide();
	$('#iphoneSSContainer ul li').click(function(){
		$('#iphoneSSContainer ul li div').fadeOut(400);
		$('#iphoneSSContainer ul li img').animate({opacity:1},100);
		$(this).find('img:first').animate({opacity:0.4},100);
		$(this).find('div').fadeIn(400);
	});
	
	// DSI SCREENSHOTS GALLERY
	$('#dsiSScontainer ul li img:first').animate({opacity:0.4},300);
	$('#iPhoneprevScreensLink').hide();
	$('#dsiSScontainer ul li').click(function(){
		$('#dsiSScontainer ul li div').fadeOut(400);
		$('#dsiSScontainer ul li img').animate({opacity:1},100);
		$(this).find('img:first').animate({opacity:0.4},100);
		$(this).find('div').fadeIn(400);
	});
	
	// iPHONE SCREENSHOTS PAGER
	$('#iPhonenextScreensLink').click(function(){
		$('#screens_a').hide();
		$('#iPhonenextScreensLink').hide();
		$('#screens_a li div').hide();
		$('#screens_a li img').animate({opacity:1},300);
		$('#screens_b').fadeIn(300);
		$('#iPhoneprevScreensLink').fadeIn(300);
		$('#screens_b li div:first').fadeIn(300);
		$('#screens_b li img:first').animate({opacity:0.4},300);
	});
	$('#iPhoneprevScreensLink').click(function(){
		$('#screens_b').hide();
		$('#iPhoneprevScreensLink').hide();
		$('#screens_b li div').hide();
		$('#screens_b li img').animate({opacity:1},300);
		$('#screens_a').fadeIn(300);
		$('#iPhonenextScreensLink').fadeIn(300);
		$('#screens_a li div:first').fadeIn(300);
		$('#screens_a li img:first').animate({opacity:0.4},300);
	});
	
	//WALLS PAGER
	$('.wallPrev').hide();
	$('.wallNext').click(function(){
		$('.wallps_a').hide();
		$('.wallNext').hide();
		$('.wallPrev').fadeIn(300);
		$('.wallps_b').fadeIn(300);
	});
	$('.wallPrev').click(function(){
		$('.wallps_b').hide();
		$('.wallPrev').hide();
		$('.wallNext').fadeIn(300);
		$('.wallps_a').fadeIn(300);
	});
	
	//WALLS PAGER iPOD/iPHONE
	$('.wallPodPrev').hide();
	$('.wallPodNext').click(function(){
		$('.wallpod_a').hide();
		$('.wallPodNext').hide();
		$('.wallPodPrev').fadeIn(300);
		$('.wallpod_b').fadeIn(300);
	});
	$('.wallPodPrev').click(function(){
		$('.wallpod_b').hide();
		$('.wallPodPrev').hide();
		$('.wallPodNext').fadeIn(300);
		$('.wallpod_a').fadeIn(300);
	});
});