$(document).ready(function(){

	var clickable = false;
	var page = 0;

	$("#bg").attr('src', 'electerious/images/bg.png').load(function() {
		$("#ajax").load('electerious/ajax/index.html', function() {
	    	$("#bg").fadeIn(1000);
	    	$("#footer").fadeIn(1000);
	    	$("#description").delay(400).fadeIn(1000);
	    	$.timer(1000,function(){
	    		clickable = true;
	    		$("#slider").animate ({
	    			marginTop: "14px"
	    		}, {
	    			duration: 3000,
        	        easing: 'easeOutElastic'
	    		});
	    	});
	    });
	});

	$("#b_cloudboard").live('click', function() {
		page_switch("electerious/ajax/cloudboard.html", "45px", "Back");
	});

	$("#b_remoteload").live('click', function() {
		page_switch("electerious/ajax/remoteload.html", "45px", "Back");
	});

	$("#b_jspictureviewer").live('click', function() {
		page_switch("electerious/ajax/jspictureviewer.html", "45px", "Back");
	});

	$("#b_galixs").live('click', function() {
		page_switch("electerious/ajax/galixs.html", "45px", "Back");
	});

	$("#b_skygift").live('click', function() {
		page_switch("electerious/ajax/skygift.html", "45px", "Back");
	});

	$("#b_morestuff").live('click', function() {
		location.href = "http://tobiasre.picsengine.com/work/#album=741";
	});
	
	$("img").live('click', function() {
		var title = $(this).attr("title");
		if (title!='') {
			location.href = title;
		}	
	});

	$("#next_step").click(function() {
		if (clickable==true) {
			if (page==0) {
				clickable = false;
				location.href = "http://twitter.com/electerious";
			}else{
				page_switch("electerious/ajax/index.html", "14px", "Twitter");
				page=0;
			}
		}
	});

	$("#footer").live('click', function() {
		location.href = "mailto:contact@electerious.com";
	});

	function page_switch(site, pixel, text) {
	    $("#description").fadeOut(700);
		$("#slider").stop().animate ({
	    	marginTop: "-390px"
	    }, 400);
	    $("#next_step").html(text);
	    page=1;
	    $.timer(800,function(){
	    	$("#ajax").load(site, function() {
	    		$("#description").fadeIn(700);
	    		$("#list").delay(300).fadeIn(0);
	    		$("#slider").animate ({
	    			marginTop: pixel
	    		}, {
	    			duration: 3000,
        	        easing: 'easeOutElastic'
	    		});
	   		});
	   	});
	}

});