var myFloatBlocks = new Array(); 

var myFloat = function(myObj, myID) {
	this.myObj = myObj; //������ � �������
	this.myID = myID; //ID ������� � ������� workObjects
	this.floatID = 0;
	this.fogID = 'backgroundFloat';
	
	this.construct = function() {
		if (!this.myObj || !this.myID) return;
		this.createFon();
		
		this.floatID = myFloatBlocks.length;
		myFloatBlocks[this.floatID] = this.myObj;		
		updateCoords(this.floatID);
		$(this.myObj).hide();
		$('#'+this.fogID).hide();
	}
	
	this.createFon = function() {
		//������� ������
		$('#'+this.fogID).remove();
		$('<div>&nbsp;</div>')
			.attr("id",this.fogID)
			.insertBefore(this.myObj)
			.css({
			'position':'absolute',
			'top' : '0px',	
			'left' : '0px',
			'width' : '100%',
			'height' :  $(document).height(),
			'opacity' : 0.6
			});
		if (/*@cc_on!@*/false == true && navigator.userAgent.indexOf("MSIE 6.") != -1) {
			$('#'+this.fogID).css({
				'background':'black',
				'height':($(document).height() > 1500) ? 1500 :  $(document).height()
		});
	}

	}
	
	this.open = function(myFunc) {
		this.doOpen(myFunc);
		//setTimeout("workObjects['"+this.myID+"'].doOpen()",250); 
	}
	
	this.doOpen = function(myFunc) {
		$('#'+this.fogID).show('fast');	
		$(this.myObj).show("scale",300,function() {apdateAllCords();(myFunc)?myFunc():false});
	}
	
	this.close = function(myFunc) {
		$('#'+this.fogID).hide('fast');
		$(this.myObj).hide("scale");
	}
		
	this.construct();
}

function updateCoords(myID) {
	if (!myFloatBlocks[myID]) return (false);
	
	var myTop = parseInt(($(window).height() - $(myFloatBlocks[myID]).height())/2) + $(document).scrollTop();	
	if (myTop < 10) myTop = 10;
	if ($(window).height() < $(myFloatBlocks[myID]).height())  myTop = 10;
	$(myFloatBlocks[myID]).animate({top:myTop},{duration:500,queue:false});
}


function apdateAllCords() {
	for (var key in myFloatBlocks)	updateCoords(key);
}

$(function() {
	$(window).scroll(function() {apdateAllCords()});
	$(window).resize(function() {apdateAllCords()});	
});

