/**
 * @author a.touzon
 * @date:01.06.09
 * @version:1.0
 */
(function($){
	  $.preload={	  	
		width:$(window).width(),
		height:$(window).height(),
		show:false,
		delay:2000,
		alpha:50,
		time:500,
		front_width:480,
		front_height:120,
		text:"",
		container:"",
		iframe:"",
		back:"",
		front:"",
		p:"",
		counter:0
		
	  };
	  ///method:
	  $.fn.extend({	  
	  	preload:function(config, file){			
			//definition			
	  		var config=config;
			config.container="#"+this.attr("id");
			config=$.extend($.preload, do__elementsDefinition(config));
			do__config(config);
			$(window).resize(this__dispose).trigger('resize');			
			return this;	
		},
		showPreloader:function(){
			//alert($("#container").css("marginTop"));
			
			$($.preload.container).fadeIn($.preload.time);
			
			//$($.preload.container).show();	
			return this;
		},
		hidePreloader:function(){

			/*$($.preload.container).css({"display":"inline", "opacity":"1"});
			$(this).delay($.preload.delay, function(){
				$($.preload.container).fadeOut($.preload.time);
			});*/
			$($.preload.container).hide();
			return this;
		},
		quitPreloader:function(){
			$($.preload.container).css({"display":"none"});
		},
		chageText:function(config){
			var config=config;			
			config.container="#"+this.attr("id");	
			var config=$.extend($.preload, do__elementsDefinition(config));
			$($.preload.p).text(config.text)
			return this;
		}
		
	  });
	  function do__elementsDefinition(config){
	  	//iframe		
	  	var iframe=$(config.container).find("iframe");
		config.iframe=iframe;
		//container:
		var back=$(config.container).find(".back");
		config.back=back;
		//front:
		var front=$(config.container).find(".front");
		config.front=front;
		//text
		var p=$(config.container).find("p");
		config.p=p;
		return config;		
	  }
	  function do__config(config){	  	
		$($.preload.container).css({			
			"left":"0px",
			"top":"0px",
			"width":$.preload.width,
			"height":$.preload.height
		});
		$($.preload.back).css({
			"position":"absolute",
			"z-index":"18",
			"top":"0px",
			"left":"0px",						
			"width":$.preload.width,
			"height":$.preload.height
		});
		$($.preload.iframe).css({
			"border":"0px",
			"z-index":"19",
			"position":"absolute",
			"top":"0px",
			"left":"0px",
			"width":"100%",
			"height":"100%"
		});
		
		$.preload.p.text($.preload.text);
	  }
	  function set__fullSize(div){
	  	$(div).css({
			"width":window.innerWidth,
			"height":window.innerHeight		
		});
	  }
	  function center(div){
	  	var top=$(window).height()/2-$.preload.front_height/2;
		var left=$(window).width()/2-$.preload.front_width/2;		
	  	$(div).css({
			"z-index":"1000",
			"position":"absolute",
			"top":top+"px",
			"left":left+"px"
		});
	  }
	  function this__dispose(){
	  	center($.preload.front);
		set__fullSize($.preload.container);
		
	  }	 	  
})(jQuery);
