var timerId = 0;
var images = new Array('IMG_5597.jpg','IMG_5607.jpg','IMG_5609.jpg','IMG_5610.jpg','IMG_5613.jpg','IMG_5614.jpg','IMG_5616.jpg','IMG_5622.jpg','IMG_5627.jpg','IMG_5629.jpg','IMG_5631.jpg','IMG_5635.jpg','IMG_5639.jpg','IMG_5646.jpg','IMG_5647.jpg','IMG_5655.jpg','IMG_5671.jpg','IMG_5678.jpg','IMG_5699.jpg','IMG_5710.jpg','IMG_5716.jpg','IMG_5726.jpg','IMG_5744.jpg','IMG_5749.jpg','IMG_5757.jpg','IMG_5798.jpg','IMG_5802.jpg','IMG_5810.jpg','IMG_5817.jpg','IMG_5820.jpg','IMG_5824.jpg','IMG_5825.jpg','IMG_5828.jpg','IMG_5834.jpg','IMG_5837.jpg','IMG_5838.jpg','IMG_5839.jpg','IMG_5842.jpg','IMG_5843.jpg','IMG_5850.jpg','IMG_5862.jpg','IMG_5869.jpg','IMG_5874.jpg','IMG_5882.jpg','IMG_5883.jpg','IMG_5888.jpg','IMG_5889.jpg','IMG_5891.jpg','IMG_5894.jpg','IMG_5900.jpg','IMG_5902.jpg','IMG_5911.jpg','IMG_5926.jpg','IMG_5927.jpg','IMG_7409.jpg','_9EI9940.jpg','_D6X1383.jpg');
var pointer = 0;

jQuery(document).ready( function(){

	jQuery('#joboverlay').fadeIn('slow');
	
	jQuery('#joboverlay .close').click( function() {
		jQuery('#joboverlay').fadeOut('slow');	
	});

	/* DIASHOW */
		
	images.shuffle();

	jQuery('#bild_fwd').replaceWith('<img id="bild_fwd" src="fileadmin/content/Agenturfotos/'+images[pointer+1]+'" />');
	jQuery('#bild_rew').replaceWith('<img id="bild_rew" src="fileadmin/content/Agenturfotos/'+images[pointer-1]+'" />');

	jQuery('#entrance').click( function() {
		stageOn();
	});
	
	jQuery('.home-news-latest-container:first').click( function() {
		stageOn();
	});
	
	jQuery('#btn_off').click( function() {
		stageOff();
	});

	jQuery('#btn_fwd').click( function() {
		pointer++;
		if (pointer >= images.length) pointer = 0;
	
		Pixastic.process(document.getElementById("bild"), "blurfast", {
			amount : .50
		});
		
		jQuery('#bild').wait(250).animate({
			marginLeft: -700
		}, 200, function() {
			jQuery('#bild').replaceWith('<img id="bild" src="fileadmin/content/Agenturfotos/'+images[pointer]+'" style="margin-left:-700px" />').wait(500);
						
			Pixastic.process(document.getElementById("bild"), "blurfast", {
				amount : .50
			});
			
			jQuery('#bild').animate({
				marginLeft: 0
			}, 200, function() {
				jQuery('#bild').wait(250).replaceWith('<img id="bild" src="fileadmin/content/Agenturfotos/'+images[pointer]+'" style="margin-left:0px" />');
				jQuery('#bild_fwd').replaceWith('<img id="bild_fwd" src="fileadmin/content/Agenturfotos/'+images[pointer+1]+'" />');
			});	
		});	
	});


	jQuery('#btn_rew').click( function() {
		pointer--;
		if (pointer < 0) pointer = images.length-1;
		
		Pixastic.process(document.getElementById("bild"), "blurfast", {
			amount : .50
		});
		
		jQuery('#bild').wait(250).animate({
			marginLeft: -700
		}, 200, function() {
			jQuery('#bild').replaceWith('<img id="bild" src="fileadmin/content/Agenturfotos/'+images[pointer]+'" style="margin-left:-700px" />').wait(500);
						
			Pixastic.process(document.getElementById("bild"), "blurfast", {
				amount : .50
			});
			
			jQuery('#bild').animate({
				marginLeft: 0
			}, 200, function() {
				jQuery('#bild').wait(250).replaceWith('<img id="bild" src="fileadmin/content/Agenturfotos/'+images[pointer]+'" style="margin-left:0px" />');
				jQuery('#bild_rew').replaceWith('<img id="bild_rew" src="fileadmin/content/Agenturfotos/'+images[pointer-1]+'" />');
			});	
		});	
	});
	
});

function defuse() {
	alpha = .7 + (Math.random() / 30);
	jQuery("#vignette1").css('opacity', alpha);
}

function stageOn() {
	jQuery('#bild').wait(250).replaceWith('<img id="bild" src="fileadmin/content/Agenturfotos/agenturgalerie.gif" style="margin-left:0px" />');

	jQuery('#stage').animate({
		top: 0
	}, 500, function() {
	});

	jQuery('#remote').wait(250).animate({
		top: 450
	}, 500, function() {
	});

	jQuery('#vignette1').css('display', 'block');
	jQuery('#vignette1').css('opacity', 0);
	jQuery('#vignette1').animate({
		opacity: .7
	}, 500, function() {
	});

	jQuery('#vignette2').css('display', 'block');
	jQuery('#vignette2').css('opacity', 0);
	jQuery('#vignette2').animate({
		opacity: .4
	}, 500, function() {
		timerId = setInterval('defuse()',40);
	});

}

function stageOff() {
	jQuery('#stage').wait(250).animate({
		top: -540
	}, 500, function() {
	});

	jQuery('#remote').animate({
		top: -150
	}, 500, function() {
	});

	jQuery('#vignette1').animate({
		opacity: 0
	}, 500, function() {
		jQuery('#vignette1').css('display', 'none');
	});

	clearInterval(timerId);
	jQuery('#vignette2').animate({
		opacity: .0
	}, 500, function() {
		jQuery('#vignette2').css('display', 'none');
	});

}

jQuery.fn.wait = function(time, type) {
	time = time || 1000;
	type = type || "fx";
	return this.queue(type, function() {
		var self = this;
		setTimeout(function() {
			$(self).dequeue();
		}, time);
	});
};


function arrayShuffle(){
	var tmp, rand;
	for(var i =0; i < this.length; i++){
		rand = Math.floor(Math.random() * this.length);
		tmp = this[i]; 
		this[i] = this[rand]; 
		this[rand] =tmp;
	}
}

Array.prototype.shuffle = arrayShuffle;


