// JavaScript Document
var imgNUM = 1;
var totIMG = 27;
var oldRnd;
function rand()
{
	return Math.round(Math.random() * 5)
};
function update(imgID)
{

	$('#fadeImg', '#img'+imgID).hide();
	$('#fadeImg', '#img'+imgID).css('background','url("http://'+document.domain+'/images/IMG_SML/IMG_'+imgNUM+'.jpg")'); 
	$('#fadeImg', '#img'+imgID).stop().fadeIn(1200, function(){
		$('#img'+imgID).css('background', $('#fadeImg', '#img'+imgID).css('background-image'));
	});
	imgNUM++;
	if(imgNUM > totIMG){imgNUM = 1;};
	//
	var rnd = rand();
	while(rnd == imgID || rnd == oldRnd)
	{
		rnd = rand();
	};
	oldRnd = imgID;
	//
	var pl = new Image();
	pl.onload = function()
	{
		$('#img'+rnd).timeOut = setTimeout("update("+rnd+")", 2000);
	};
	pl.src = "http://"+document.domain+"/images/IMG_SML/IMG_"+imgNUM+".jpg";
}
$(document).ready(function(){
	$('#holder').append('<div id="gallery"></div>')
	$('#gallery').css({'width' : '750px', 'height' : '230px', 'position' : 'absolute', 'top' : '300px', 'left' : '23px'});
	for(var g=0;g<5;g++)
	{
		$('#gallery').append('<div id="img'+g+'"></div>')
		
		
		$('#img'+g).css('background' , 'url("http://'+document.domain+'/images/IMG_SML/IMG_'+imgNUM+'.jpg")');
		$('#img'+g).css({'width' : '150px', 'height' : '230px', 'float' : 'left'});
		
		$('#img'+g).append('<div id="fadeImg"></div>');
	
		$('#fadeImg', '#img'+g).css({'width' : '150px', 'height' : '230px', 'display' : 'none'});
		
		imgNUM++;
		if(imgNUM > totIMG){imgNUM = 1;};
	};
	var rnd = rand();
	var pl = new Image();
	pl.onload = function()
	{
		$('#img'+rnd).timeOut = setTimeout("update("+rnd+")", 2000);
	};
	pl.src = "http://"+document.domain+"/images/IMG_SML/IMG_"+imgNUM+".jpg"

});