//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com [v1.0]

String.prototype.repeat = function(l){
	return new Array(l+1).join(this);
};

//firebugx
if (!window.console || !console.firebug)
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}


function rando (range) {
	return Math.floor(Math.random() * range);
}

$(function () {

	//
	window.ww = $(window).width();
	window.wh = $(window).height();
	
	
	$('div.actor').hide().css({backgroundRepeat:'no-repeat',width:800,height:800}).each(function(){$(this).css({left:rando(ww-800),top:rando(wh-800)})});
	
	//music
	$('#soundtrack').show().css({left:-1000,top:-1000});
	$('#soundtrack').jmp3({showdownload:'false',autoplay:'true',showfilename:'false',repeat:'false'});
	
	window.$robber = $('#robber').css({backgroundImage: 'url(robber.png)'});
	window.$punk = $('#punk').css({backgroundImage: 'url(punk.png)'});
	window.$back = $('#back').css({backgroundImage: 'url(old-jew-back.png)'});
	window.$front = $('#front').css({backgroundImage: 'url(robbers-front.png)'});
	window.$old = $('#old-jew').css({backgroundImage: 'url(old-jew.png)'});
	window.$woman = $('#woman').css({backgroundImage: 'url(woman.png)'});
	window.$joey = $('#joey').css({backgroundImage: 'url(joey.png)'});
	
	
	$('#intro').fadeIn(2000).css({left:rando(ww/4),top:rando(wh/4)});
	
	var time = 0;
	var cues = [
		{t:time+=8,f:function () {$('#intro').fadeOut(2000);}},
		{t:time+=4,f:function () {$back.css({left:rando(ww/4),top:rando(wh/4)}).fadeIn(5000);}},
		{t:time+=10,f:function () {$back.fadeOut(5000);}},
		{t:time+=2,f:function () {$front.fadeIn(8000);}},
		{t:time+=10,f:function () {$front.fadeOut(2000);}},
		{t:time+=2,f:function () {$robber.show();$('body').append('<div id="give">give us your money.</div>');}},
		{t:time+=5,f:function () {$robber.fadeOut(4000);$('#give').remove();}},
		{t:time+=2,f:function () {$old.fadeIn(1000).animate({left:'+=20',top:'+=5'},8000);}},
		{t:time+=10,f:function () {$old.hide(); $woman.show();}},
		{t:time+=10,f:function () {$woman.hide(); $robber.css({zIndex:100}).show();$punk.show().animate({left:'+=100',top:'+=40'}, 5000);$joey.show().animate({left:'-=100',top:'-=10'}, 5000);}},
		{t:time+=10,f:function () {$robber.hide();$punk.hide();$joey.hide();$front.css({zIndex:10,top:0,left:0}).show();$back.css({zIndex:100,top:200,left:200}).show().animate({left:'+=100',top:'+=40'}, 5000);}},
		{t:time+=2,f:function () {$old.fadeIn(1000).animate({left:'+=20',top:'+=5'},8000);}},
		
		
	];
	
	for (var i = 0; i < cues.length; i++) {
		setTimeout(cues[i]['f'], cues[i]['t']*1000);
	}
	
});

