(function($) {

	var op 			= new Array;
	var img			= new Array;
	var positions	= new Array;
	var playInterval = new Array;
	
	$.fn.tgPreload= $.fn.tgPreload = function(options){
		
		init = function(tg){
			op[tg.id] = $.extend({}, $.fn.tgPreload.defaults, options);
			$('#'+tg.id+' .' + op[tg.id].childClass + '').addClass('ploader');
			
			 
					img[tg.id]			= new Array();
					positions[tg.id]	= -1;
					
					
					$.each($('#'+tg.id+' .' + op[tg.id].childClass + ''), function(i,item){
						img[tg.id][i] = $(item).find('img');

						img[tg.id][i].css({'display': 'block', 'z-index' : '1001','visibility' : 'hidden', 'opacity' : '0', 'position' : 'absolute', 'top' : '-' + $(window).height() + 'px', 'left' : '0px'});
					});
				
					$.transition(tg);
			
		};
		
		// transitions
		$.transition = function(tg){
			playInterval[tg.id] = setInterval(function() { $.np(tg) }, op[tg.id].speed);
			positions[tg.id]++;
		};
		
		$.np = function(tg){
				
				if  (positions[tg.id] == img[tg.id].length) {
					clearInterval(playInterval[tg.id]);
					return;
				}

					$(img[tg.id][positions[tg.id]]).bind('load', function() {
						$(img[tg.id][positions[tg.id]]).css('visibility', 'visible').animate({top : '0px', opacity: 1.00});
						positions[tg.id]++;
					}).trigger('load');
				
		};
		


		this.each (
			function(){ init(this); }
		);


	};
	
	// default values
	$.fn.tgPreload.defaults = {	
		speed : 200,
		animateSpeed : 400,
		childClass : ""
	};	
	
})(jQuery.noConflict());
	
