$(document).ready(function(){

	function init(){
		$('a.zoom').each(function(){
			$(this).fancyZoom({
				closeOnClick: true, 
				scaleImg: true,
				width:800, 
				height:500
			});
		});
/*
		$('a.video').each(function(){
			$(this).fancyZoom({
				width:600, 
				height:480
			});
		});
*/		
		var hash = window.location.hash;
		hash = hash.replace("#!/", "");
		if (hash == 'touch' || $.os.ios) {
			switchToiOSView();		
		} else if (hash == 'mac') {
			switchToMacView();
		}
		
		if ($.os.ios) { $('#blog ul li').css('line-height','25px'); }
		if (!($.os.ios)) { $('#blog ul li').css('line-height','40px'); }
			
	}

	function switchToiOSView(){
		var duration = 400;
		
		$('#back').animate({
			opacity: 0
		,	left: '+=8px'
		}, duration/2);		

		$('#hardware').animate({
			opacity: 0.2
		}, duration, function(){

			$('#ios').addClass('active');
			$('#mac').removeClass('active');
			$('#hardware').removeClass('ios mac').addClass('ios');	
			$('#amount').text('9.99');
			$('#buy a').attr('href', 'http://itunes.apple.com/app/mindnode/id312220102?mt=8');	

			$('#hardware').animate({
				opacity: 1 
			}, duration*0.8);		
			$('#back').animate({
				opacity: 1
			,	left: '640px'
			}, duration);		

		});
	}
	
	function switchToMacView(){
		var duration = 400;

		$('#back').animate({
			opacity: 0
		,	left: '-=8px'
		}, duration/2);		
		
		$('#hardware').animate({
			opacity: 0.2
		}, duration, function(){

			$('#mac').addClass('active');
			$('#ios').removeClass('active');
			$('#hardware').removeClass('ios mac').addClass('mac');	
			$('#amount').text('19.99');
			$('#buy a').attr('href', 'http://itunes.apple.com/app/mindnode-pro/id402398561?mt=12');	

			$('#hardware').animate({
				opacity: 1			
			}, duration*0.8);		
			$('#back').animate({
				opacity: 1
			,	left: '10px'
			}, duration);		

		});		
	}
	
	$('#ios').click(function(){
		switchToiOSView();
	});

	$('#mac').click(function(){
		switchToMacView();
	});
	
	init();

});

