/**
 * jQuery-Plugin "popup"
 * by Timokhin M., loki@indahaus.com
 * http://www.free-lance.ru/users/fdes
 * 
 * Copyright (c) 2008 Timokhin M.V.
 * GNU/GPL
 *
 * Version: 1.0, 22.11.2008

 *?????? popup ??? jQuery
 * ????? ??????? ?.?,., loki@indahaus.com
 * http://www.free-lance.ru/users/fdes
 * 
 * Copyright (c) 2008 Timokhin M.V.
 * GNU/GPL
 *
 * ??????: 1.0, 22.11.2008
 
 ?????? ?????????????:
 
 $("div.popup").popup(interval,hidetime);
 interval - ???????? ????? ?????????? ??????
 hidetime - ????? ??????????? ??????
 
 */
jQuery.fn.popup = function(interval,hidetime) 
{
	var hideTimer, showTimer;
	var els = this;
	var start = 0;
	var count = els.length;
	var hideTimer, showTimer;
	if(!interval) var interval = 4000;
	if(!hidetime) var hidetime = 2000;
	function sUp(el){
		if ($.browser.msie) var height=document.body.clientHeight+$("html").attr("scrollTop");
		if (!height) var height=window.innerHeight+$("html").attr("scrollTop");
		$("body").css("overflow","hidden");
		el.css("top",height+"px").show();
		el.animate({  
		top: '-=' + el.css("height")
		}, 800, 'swing', function() {  
		start++;
		hInt();
	});
	}
	function sInt(){
		clearTimeout(showTimer);
		showTimer = setInterval(function(){
		if(start==count) start = 0;
		sUp($(els[start]));
		},interval);	
	}
	
	function hInt(){
		clearTimeout(hideTimer);
		hideTimer = setTimeout(function(){
			els.fadeOut(400);
			$("body").css("overflow","auto");
			},hidetime);
	}
	
	els.css("display","none");
	els.css("position","top");
	els.css("left","0px");
	
	els.hover(function(){
		clearTimeout(hideTimer);
		clearTimeout(showTimer);
		},function(){hInt(); sInt();});
	
	$("a.close").click(function(){
		$(this).parent("div."+els.attr("className")).hide()
		sInt();
	});

	sInt();

  return this;
};