/*
image pre-loader
parameters:
container: id/class/tag of container that holds all the images
onComplete: callback to fire after load complete
progressContainer: id/class/tag that shows the progress
*/

var iPreLoad = function(o){
	var ths = new Object(o);
	ths.images = $(ths.container+" img");
	ths.loaded = 0;
	ths.onComplete = ths.onComplete?ths.onComplete:function(){alert('load complete');};
	if( !$(ths.progressContainer).length ){
		$(ths.container).append('<div class="iLoadProgress"></div>');
		ths.progressContainer = ths.container+' .iLoadProgress';
		}
	$(ths.progressContainer).html('<div class="barr">Loading Images Please Wait...</div>');
	$(ths.progressContainer).css({margin:'0px auto',width:'200px', height:'15px',padding:'2px', border:'2px solid #dfdfdf', overflow:'hidden'});
	$(ths.progressContainer+' div').css({textAlign:'center',fontSize:'10px',height:'15px',background:'#2a2a2f',color:'#fff',fontWeight:'bold'});
	ths.preLoad = function(src){
		var im = new Image();
		im.onload = function(){
			if( ths.loaded++ == ths.images.length-1 ){
				$(ths.progressContainer).remove();
				ths.onComplete();
				}
			else{
				$(ths.progressContainer+' div').css({width:Math.round(ths.loaded/ths.images.length*100)+'%'});
				$(ths.progressContainer+' div').html('loded: '+ths.loaded+'\/'+ths.images.length);
				}
			//alert('loading: '+ths.loaded);
			}
		im.src = src;
		}
	for(var i = 0; i < ths.images.length; i++ ) ths.preLoad(ths.images[i].src);
	};