var p= {
    loaderSrc: null, init:function() {
	p.backToTop();
	p.tweet();
	p.inputs();
	p.loaderSrc=$("#ajax_loader").attr("src");
    }
    , preload: function() {
	for(var a=["images/global/ajax-loader.gif"], b=0;
	    b<a.length;
	    b++)(new Image).src=Phantom.STATIC_URL+a[b];
    }
    , inputs: function() {
	$(".inits").each(function() {
		if(!$(this).val()||!$(this).data("initval"))!$(this).data("initval")&&$(this).val()?$(this).data("initval", $(this).val()): $(this).val($(this).data("initval"));
	    }
	    ).live("focus blur", function(a) {
		    switch(a.type) {
		    case "focusin": !$(this).data("initval")||
		    $(this).val()===$(this).data("initval")?$(this).val(""):$(this).data("initval")!==$(this).val()&&$(this).select();
		    break;
		    case "focusout": $(this).val()===""&&$(this).val($(this).data("initval"));
		    }
		});
    }, backToTop:function() {
	$("#back_to_top").click(function(a) {
		a.preventDefault();
		$("html,  body").animate( {
			scrollTop: "0px"}
		    , 500);
	    });
    }, tweet:function() {
	$("#phantom-tweet p.tweet_quote").length==0?$.getJSON("/latest-tweet/", function(a) {
		$("#phantom-tweet").append($('<p class="tweet_quote"></p>').html(a.text), $('<p class="tweet_info"><span id="tweet_timestamp"></span> <a href="http: //twitter.com/fireworks" target="_blank" rel="nofollow">@Fireworks</a></p>'));
    
		$("#tweet_timestamp").text(p.howLongAgo(a.date));
	    }
	    ): $("#tweet_timestamp").text(p.howLongAgo($("#tweet_timestamp").data("timestamp")));
    }, howLongAgo:function(a) {
	a=(new Date(a)).getTime();
	a=((new Date).getTime()-a)/1E3/60;
	if(a>1&&a<2)return"about a minute ago";
	else if(a>2&&a<60)return Math.floor(a)+" minutes ago";
	else if(a<1)return Math.floor(a*60)+" seconds ago";
	else if(a>=60&&a<120)return"about an hour ago";
	else if(a>=120&&a<1440)return Math.floor(a/60)+" hours ago";
	else if(a>=1440&&a<2880)return"a day ago";
    
	else if(a>=2880)return Math.floor(a/60/24)+" days ago"}
};
$(document).ready(p.init);
$(window).load(p.preload);
    
jQuery.fn.slideShow=function(a) {
    var b=jQuery.extend( {
	    delay: 3E3, slideDuration:500, indicators:".indicators"}
	, a);
    this.each(function() {
	    function a() {
		i.each(function() {
			$(this).removeClass("active");
		    }
		    );
		$(i[c]).addClass("active");
	    }
	    function f() {
		c<j-1?c++: c=0;
		g();
	    }
	    function g() {
		d.stop().animate( {
			left: -(c*k)+"px"}
		    , b.slideDuration);
		a();
		l();
	    }
	    function l() {
		var a=d.children("li:eq("+c+")").children("a").attr("href");
		h.find(".slideshow_link").attr("href", a);
	    }
	    var h=$(this), d=h.find(".slideshow_list"), j=d.children("li").length, 
		k=d.children("li").outerWidth(!0), i=h.find(b.indicators), c=0, e=null;
	    d.width(j*k);
	    (function() {
		h.find(".controls").live("click", function(a) {
			a.preventDefault();
			clearInterval(e);
			$(this).hasClass("next")?f(): $(this).hasClass("prev")&&(c!==0?c--:c=j-1, g());
			e=setInterval(f, b.delay+b.slideDuration);
		    }
		    );
		i.live("click", function(a) {
			a.preventDefault();
			clearInterval(e);
			c=$(this).index(b.indicators);
			g();
			e=setInterval(f, b.delay+b.slideDuration);
		    }
		    );
	    })();
	    l();
	    g();
	    e=setInterval(f, b.delay+b.slideDuration);
	}
	);
    return this;
}
    ;
    
$(document).ready(function() {
	$(".slideshow").slideShow();
    }
    );
    
