/*Java Script*/
/*
function getPageSize() {
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	
	return [pageWidth,pageHeight];
}
*/


Label = function(obj, draging, moveHandler) { //Конструктир
	this.obj = obj;
	this.delay = 400;
	this.globalOpacity = 0;	
	this.feadTimer = null;
	this.moveTimer = null;

	this.TweenLeft = null;
	this.TweenTop = null;

/*
	this.hendler.incrZIndex = function() {
		_self.incrZIndex();
	}

	var _self = this;
	this.obj.onmousedown = function() {
		_self.incrZIndex();
	}
*/
/*

	if(draging) {
		this.hendler = DragHandler.attach(
			this.obj,
			{ minLeft: minLeft, minTop: minTop, maxLeft: maxLeft, maxTop: maxTop }
		);
	
	}
//	this.hendler.drag = drag;
//	this.hendler.dragEnd = end;
*/
	if (draging) {
		$('#'+obj.id).easydrag(false);
		if (moveHandler)
			$('#'+obj.id).setHandler(obj.id+moveHandler);
		$('#'+obj.id).ondrag(function(e, element){
			$(element).css({'opacity': 0.6});
			checkLimits($(element));
		});
		$('#'+obj.id).ondrop(function(e, element){
			$(element).css({'opacity': 1});
		});
	}

//	
}

function checkLimits(box){
	var box_left   = parseInt(box.css("left"));
	var box_right  = box_left + parseInt(box.css("width"));
	var box_top    = parseInt(box.css("top"));
	var box_bottom = box_top + parseInt(box.css("height"));
	
	if(box_left < minLeft)
		box.css("left", minLeft);
	if(box_top < minTop)
		box.css("top", minTop);
	if(box_right > maxLeft)
		box.css("left", maxLeft - parseInt(box.css("width")));
//	if(box_bottom > maxTop)
//		box.css("top", maxTop - parseInt(box.css("height")));
}

Label.prototype.setPosition = function() {

	var labelWidth = $(this.obj).width();
	var labelHeight = $(this.obj).height();

	var randTop = Math.floor(Math.random() * xy[1]);
	var randLeft = Math.floor(Math.random() * xy[0]);

//	while((minTop > randTop) || ((randTop+labelHeight) > cBottom)) {
	while((minTop > randTop) || ((randTop+labelHeight) > maxTop)) {
		randTop = Math.ceil(Math.floor(Math.random() * xy[1]));
	}

	while((minLeft > randLeft) || ((randLeft+labelWidth) > maxLeft)) {
		randLeft = Math.ceil(Math.floor(Math.random() * xy[0]));
	}
	this.obj.style.top = randTop+'px';
	this.obj.style.left = randLeft+'px';
}

Label.prototype.show = function(xy) {
	this.setPosition();
	
	var _self = this;
	var timer = setTimeout(function() {
		_self.setVisible();
	}, this.delay*delayCount);
}

Label.prototype.setVisible = function() {
//	this.setOpacity(0);
//	this.obj.style.visibility='visible';
	this.fadeElement(1);
}

/*
Label.prototype.setOpacity = function(value) {
	this.obj.style.opacity = value;
	this.obj.style.MozOpacity = value;
	this.obj.style.KhtmlOpacity = value;
	this.obj.style.filter = "alpha(opacity=" + value*100 + ")";
}
*/

Label.prototype.fadeElement = function(dir) {
	if(dir > 0) {
//alert($(this.obj).css("visibility"));
//		$(this.obj).css("visibility", "visible");
		$(this.obj).fadeIn("slow");
//		if(this.globalOpacity == 0) {
//			this.obj.style.visibility='visible';
//			this.fadeElementIn();
//		}
	}else {
		$(this.obj).fadeOut("slow");
//		if(this.globalOpacity == 1) {
//			this.fadeElementOut();
//		}
	}	
} //fadeElement()
/*
Label.prototype.fadeElementIn = function() {
	this.globalOpacity += (document.all?0.1:0.05);

	if (this.globalOpacity > 1) {
		this.setOpacity(1);
		this.globalOpacity = 1;
		clearTimeout(this.feadTimer);
	} else {
		this.setOpacity(this.globalOpacity);
		var _self = this;
		this.feadTimer = setTimeout(function() { _self.fadeElementIn(); }, 20);
	}
} //fadeElementIn()

Label.prototype.fadeElementOut = function() {
	this.globalOpacity -= 0.05;

	if (this.globalOpacity < 0) {
		this.obj.style.visibility='hidden';
		this.setOpacity(0);
		this.globalOpacity = 0;
		clearTimeout(this.feadTimer);
	} else {
		this.setOpacity(this.globalOpacity);
		var _self = this;
		this.feadTimer = setTimeout(function() { _self.fadeElementOut(); }, 20);
	}
} //fadeElementOut()
*/
Label.prototype.moveTo = function(top, left) {

	if ((this.obj.style.top == top) && (this.obj.style.left == left)) return;
	this.TweenTop = new Tween(this.obj.style, 'top', Tween.regularEaseInOut, parseInt(this.obj.style.top), top, .8, 'px');
	this.TweenLeft = new Tween(this.obj.style, 'left', Tween.regularEaseInOut, parseInt(this.obj.style.left), left, .8, 'px');
//"Tween.regularEaseIn" "Tween.regularEaseOut" "Tween.regularEaseInOut" "Tween.strongEaseIn" "Tween.strongEaseOut" 
//"Tween.strongEaseInOut" "Tween.backEaseOut" "Tween.backEaseIn" "Tween.backEaseInOut" "Tween.bounceEaseOut" 
//"Tween.bounceEaseIn" "Tween.bounceEaseInOut" "Tween.elasticEaseIn" "Tween.elasticEaseOut" "Tween.elasticEaseInOut"

	this.TweenTop.start();
	this.TweenLeft.start();

} //moveTo()

