var images = new Array(
	'etc/contact.gif','etc/back.gif','etc/logostub1.gif','etc/logotail1.gif',
	'etc/music.jpg','etc/travel.jpg','etc/portrait1.jpg','etc/wedding1.jpg','etc/landscape1.jpg','etc/john1.jpg'
);

var _images = $H({	
	'music' : false,
	'travel' : false,
	'portrait1' : false,
	'wedding1' : false,
	'landscape1' : false
});

var loadingImages = new Array('etc/bw1.jpg','etc/col1.jpg');

var progress = 0;

function setLoadedFlag(img){

	_images.update({img : true});
	progress = progress + 20;

}

function preloadImages()
{
	//setTimeout(function(){pre_preloadImages(0)},1000);
	pre_preloadImages(0);
	recenter('loading');
	$('loading').style.visibility = 'visible';
	revealImg(0);
}

function pre_preloadImages(i)
{
	if(i<loadingImages.length)
	{
		var im = new Image();
		im.src = loadingImages[i];		
		im.onLoad=pre_preloadImages(i+1);
	}	
	else{
		preloadImage(0);
	}
}

function preloadImage(i)
{
	if(i<images.length)
	{
		var im = new Image();
		progress = Math.round(i/images.length*100);
		im.src = images[i];		
		im.onLoad=preloadImage(i+1);
	}
	else
		progress = 100;
		
}

function revealImg(width)
{
	if(width<404)
	{
		if(width <= (404/100)*progress)
		{
			width=width+5
			$('loadingCol').style.width = width+'px';
			$('percent').innerHTML = 'LOADING ' + Math.round(width/404*100) +'%';
			setTimeout('revealImg('+width+')',100);
		}
	}
	else
	{
		onLoaded();	
	}
}

function onLoaded()
{
	var div = $('contentWindow');

	var url = '' + document.location;
	if(url.indexOf('?')!=-1)
	{
		var galleryName = url.substring(url.indexOf('?')+1, url.length);
		var gallery = clientGalleries.get(galleryName.toLowerCase());
		
		if(gallery)
		{
			defaultGallery = gallery;
			doGalleryLoad();
		}
		else
			doStandardLoad();
	}
	else
	{
		doStandardLoad();
	}
}

function doStandardLoad()
{
	var functions = new Array(
		function(){fadeOut('loading', 100, null)},
		function(){setDivVis('contentWindow', 'visible')},
		function(){resizeWidth('contentWindow', 15, 600, null)},
		function(){resizeHeight('contentWindow', 15, 400, 'getIntValue(div.style.height) == goal')},
		function(){fadeInLogo(0)},			
		function(){showGallery()}			
	);
	setTimeout(function(){executeFunctions(functions)},1000);
}

function doGalleryLoad()
{
	var functions = new Array(
		function(){fadeOut('loading', 100, null)},
		function(){setDivVis('contentWindow', 'visible')},
		function(){resizeWidth('contentWindow', 15, 600, null)},
		function(){resizeHeight('contentWindow', 15, 400, 'getIntValue(div.style.height) == goal')},
		function(){fadeInLogo(0)},
		//function(){fadeIn('contact',100,null)},
		function(){fadeIn('login',100,null)},
		function(){fadeIn('back',100,null)},
		function(){showClientGallery(defaultGallery)}			
	);
	setTimeout(function(){executeFunctions(functions)},1000);
}

var defaultGallery;