/*
	Designerdroge JS/jQuery routines and functions
*/

	jQuery.extend(
		{
			random: function(X)
				{
		    		return Math.floor(X * (Math.random() % 1));
				},
			randomBetween: function(MinV, MaxV)
				{
	  				return MinV + jQuery.random(MaxV - MinV + 1);
				}
		});

	$(document).ready(function()
		{
			numElements = 83;										// Define how much elements are used
			thumbArr = new Array();									// Create an array

			function randOrd()										// Function for randomizing an array
				{
					return (Math.round(Math.random()) - 0.5);
				}

			// Define and control status message
			$("#statusBox").fadeTo(0, 0);
			$("#statusBox").delay(400).html("Loading ...");
			$("#statusBox").fadeTo(1000, 1);
			$("#statusBox").effect('pulsate', {times: 40}, 1000);

			for(i = 1; i <= numElements; i++)
				{
					$("#box"+i+" img").fadeTo(0, 0);				// Make all elements invisible
					$("#box"+i+" img").css('cursor', 'default')		// Set default cursor for element
					thumbArr.push(i);								// Push id into array
				}

			thumbArr.sort(randOrd);									// Randomize array

			beginFade = setInterval("fadeInRandom()", 500);			// Start a interval


			$(".thumbbox img").hover(
				function()
					{
						value = $(this).css('opacity');
						if(value > 0)
							{
								$(this).fadeTo(300, 1);
								$(this).css('cursor', 'pointer')
							}
					},
				function()
					{
						value = $(this).css('opacity');
						if(value >= 0.35)
							{
								$(this).fadeTo(600, 0.4);
								$(this).css('cursor', 'none')
							}
					}
					);

			$("a[rel^='prettyPhoto']").prettyPhoto({				// prettyPhoto Lightbox
					animationSpeed: 'normal', 						/* fast/slow/normal */
					default_width: 848,
					default_height: 480,
					opacity: 0.20, 									/* Value between 0 and 1 */
					showTitle: true, 								/* true/false */
					counter_separator_label: '/', 					/* The separator for the gallery counter 1 "of" 2 */
					theme: 'light_square' 							/* light_rounded / dark_rounded / light_square / dark_square / facebook */

				});



		});

	var index = 0;

	function fadeInRandom()
		{
			$("#box"+thumbArr[index]+" img").fadeTo(2000, 0.4);		// Show the next element
			index++;

			if(index > numElements)
				{
					clearInterval(beginFade);						// Stop interval after showing all available elements

					$("#statusBox").fadeTo(800, 0, function()
						{
							$("#statusBox").fadeTo(800, 1).delay(4000).fadeTo(1000, 0).html("Done!");
						});
				}
		}
