$(document).ready(function(){
	
	//SCROLLBAR
	$('.infoScroll').jScrollPane({
		showArrows:true,
		scrollbarWidth:10,
		arrowSize:30
	});
	
	if ( platform == 'iphone' ){
		clickIphone();
	}else{
		clickMobile();
	}
	
	//IPHONE - MOBILE SWITCHER
	function clickIphone(){
		$('#mobileContainer').hide();
		$('#screenshotsMobile').hide();
		$('#videoMobile').hide();
		$('#infoContentMobile').hide();
		$('#btnIphone').animate({opacity:1},1);
		$('#btnMobile').animate({opacity:0.5},1);
		$('#iphoneContainer').fadeIn(400);
		$('#screenshotsIphone').fadeIn(400);
		$('#videosIphone').fadeIn(400);
		$('#infoContent').fadeIn(400);
	}
	
	function clickMobile(){
		$('#iphoneContainer').hide();
		$('#screenshotsIphone').hide();
		$('#videosIphone').hide();
		$('#infoContent').hide();
		$('#btnMobile').animate({opacity:1},1);
		$('#btnIphone').animate({opacity:0.5},1);
		$('#mobileContainer').fadeIn(400);
		$('#screenshotsMobile').fadeIn(400);
		$('#videoMobile').fadeIn(400);
		$('#infoContentMobile').fadeIn(400);
	}
	
	$('#btnIphone').click(function(){
		platform = 'iphone';
		clickIphone();
	});
	$('#btnMobile').click(function(){
		platform = 'mobile';
		clickMobile();
	});
	
	$('#btnIphoneIT').click(function(){
		platform = 'iphone';
		$('#screenshotsMobile, #videoMobile, #infoContentMobile').hide();
		$('#screenshotsIphone, #videosIphone, #infoContent').fadeIn(400);
	});
	$('#btnMobileIT').click(function(){
		$('#screenshotsIphone, #videosIphone, #infoContent').hide();
		$('#screenshotsMobile, #videoMobile, #infoContentMobile').fadeIn(400);
	});


	// HOVERS
	/*
	$('#iphoneContainer .links a').hover(
		function(){ $(this).animate({opacity:0.7},100); },
		function(){ $(this).animate({opacity:1},100); }
	);
	*/
	
	// FIX
	$('#submitBtns input:first').css({'margin-right':'5px'});
	
	//IPHONE SCREENSHOTS PAGER
	$('#iphoneScreens_0 li div:first').show();
	$('#iphoneScreens_0 li label').animate({opacity:0.5},1);
	$('#iphoneScreens_0 li label:first').animate({opacity:1},1);
	
	$('#screenshotsIphone ul li label').click(function(){
		$('#screenshotsIphone ul li label').animate({opacity:0.5},100);
		$(this).animate({opacity:1},100);
		$('#screenshotsIphone ul li div').hide();
		$(this).parent('li').children('div').fadeIn(300);
	});
	
	var init = 0;
	var maximo = 1; // PAGER MAX VALUE
	
	$('#btnPrev').click(function(){
		if (init > 0)
		{
			$('#iphoneScreens_'+init).hide();
			init--;
			$('#iphoneScreens_'+init+' li label').animate({opacity:0.5},1);
			$('#iphoneScreens_'+init+' li label:first').animate({opacity:1},1);
			$('#iphoneScreens_'+init+' li div:first').show();
			$('#iphoneScreens_'+init).fadeIn(300);
		}
	});
	
	$('#btnNext').click(function(){
		if (init < maximo)
		{
			$('#iphoneScreens_'+init).hide();
			init++;
			$('#iphoneScreens_'+init+' li label').animate({opacity:0.5},1);
			$('#iphoneScreens_'+init+' li label:first').animate({opacity:1},1);
			$('#iphoneScreens_'+init+' li div:first').show();
			$('#iphoneScreens_'+init).fadeIn(300);
		}
	});
	
	//MOBILE SCREENSHOTS PAGER
	$('#mobileScreens_0 li div:first').show();
	$('#mobileScreens_0 li label').animate({opacity:0.5},1);
	$('#mobileScreens_0 li label:first').animate({opacity:1},1);
	
	$('#screenshotsMobile ul li label').click(function(){
		$('#screenshotsMobile ul li label').animate({opacity:0.5},100);
		$(this).animate({opacity:1},100);
		$('#screenshotsMobile ul li div').hide();
		$(this).parent('li').children('div').fadeIn(300);
	});
	
	var mobile_init = 0;
	var mobile_maximo = 1; // PAGER MAX VALUE
	
	$('#mobileBtnPrev').click(function(){
		if (mobile_init > 0)
		{
			$('#mobileScreens_'+mobile_init).hide();
			mobile_init--;
			$('#mobileScreens_'+mobile_init+' li label').animate({opacity:0.5},1);
			$('#mobileScreens_'+mobile_init+' li label:first').animate({opacity:1},1);
			$('#mobileScreens_'+mobile_init+' li div:first').show();
			$('#mobileScreens_'+mobile_init).fadeIn(300);
		}
	});
	
	$('#mobileBtnNext').click(function(){
		if (mobile_init < mobile_maximo)
		{
			$('#mobileScreens_'+mobile_init).hide();
			mobile_init++;
			$('#mobileScreens_'+mobile_init+' li label').animate({opacity:0.5},1);
			$('#mobileScreens_'+mobile_init+' li label:first').animate({opacity:1},1);
			$('#mobileScreens_'+mobile_init+' li div:first').show();
			$('#mobileScreens_'+mobile_init).fadeIn(300);
		}
	});
	
	//IPHONE VIDEOS PAGER
	$('#videos_0 li div:first').show();
	$('#videos_0 li label').animate({opacity:0.5},1);
	$('#videos_0 li label:first').animate({opacity:1},1);
	
	$('#videosIphone ul li label').click(function(){
		$('#videosIphone ul li label').animate({opacity:0.5},100);
		$(this).animate({opacity:1},100);
		$('#videosIphone ul li div').hide();
		$(this).parent('li').children('div').fadeIn(300);
	});
	
	var videos_init = 0;
	var videos_maximo = 1;
	
	$('#videosBtnPrev').click(function(){
		if (videos_init > 0)
		{
			$('#iphoneScreens_'+videos_init).hide();
			videos_init--;
			$('#iphoneScreens_'+videos_init+' li label').animate({opacity:0.5},1);
			$('#iphoneScreens_'+videos_init+' li label:first').animate({opacity:1},1);
			$('#iphoneScreens_'+videos_init+' li div:first').show();
			$('#iphoneScreens_'+videos_init).fadeIn(300);
		}
	});
	
	$('#videosBtnNext').click(function(){
		if (videos_init < videos_maximo)
		{
			$('#iphoneScreens_'+videos_init).hide();
			videos_init++;
			$('#iphoneScreens_'+videos_init+' li label').animate({opacity:0.5},1);
			$('#iphoneScreens_'+videos_init+' li label:first').animate({opacity:1},1);
			$('#iphoneScreens_'+videos_init+' li div:first').show();
			$('#iphoneScreens_'+videos_init).fadeIn(300);
		}
	});
	
});
