var current = 'paleo';
$(document).ready(function() {
	
	$("#android").animate({
			marginTop: "231px"
		}, {
			duration: 1300,
			easing: "easeOutBounce"
		}
	);	
	$("#apple").animate({
				marginTop: "231px"
			}, {
				duration: 2000,
				easing: "easeOutBounce"
			}
		);
	
	$("#paleo.smartphone").click(function(){
		current='nexus';
		$("#android").addClass('selected');
		$("#paleo.smartphone").hide();
		$("#nexus.smartphone").show();
	});
	$("#android").hover(function(){
		if (current != 'nexus') $(this).addClass('hover');
	},function() {
		$(this).removeClass('hover');
	});	
	$("#apple").hover(function(){
		if (current != 'iphone') $(this).addClass('hover');
	},function() {
		$(this).removeClass('hover');
	});
	
	$("#android").click(function() {
		$("#paleo.smartphone").hide();
		current= 'nexus';
		$(this).addClass('selected');
		$("#apple").removeClass('selected');
		$("#iphone.smartphone").hide();
		$("#nexus.smartphone").show();
	});
	
	$("#apple").click(function() {
		$("#paleo.smartphone").hide();
		current= 'iphone';
		$(this).addClass('selected');
		$("#android").removeClass('selected');
		$("#nexus.smartphone").hide();
		$("#iphone.smartphone").show();
	});
	
	$(".previous_pic").click(function() {
		if ($('#'+current+'.smartphone > img.pictures:first').is("#"+current+".smartphone > img.selected")) {
			$("#"+current+".smartphone > img.pictures").last().fadeIn('slow').addClass('selected');
			$("#"+current+".smartphone > img.selected").first().removeClass('selected').hide();					
		}
		else {
			$("#"+current+".smartphone > img.selected").prev().fadeIn('slow').addClass('selected');
			$("#"+current+".smartphone > img.selected").last().removeClass('selected').hide();
		}
	});

	$(".next_pic").click(function() {
		if ($('#'+current+'.smartphone > img.pictures:last').is("#"+current+".smartphone > img.selected")) {
			$("#"+current+".smartphone > img.pictures").first().fadeIn('slow').addClass('selected');
			$("#"+current+".smartphone > img.selected").last().removeClass('selected').hide();					
		}
		else {
			$("#"+current+".smartphone > img.selected").next().fadeIn('slow').addClass('selected');
			$("#"+current+".smartphone > img.selected").first().removeClass('selected').hide();
		}
	});

        var uagent = navigator.userAgent.toLowerCase();
        if (uagent.search("android") <= -1) {
            $("a#dl_market").fancybox({
                'titleShow'		: false
            });
        } else {
            $("a#dl_market").attr("href","market://details?id=ch.iict.myfest");
        }

});
