// Neue Javascript
var xPos;
var yPos; 
var MouseCoord = Class.create();
MouseCoord.prototype = {
	ConfirmText:"Delete this item?",
	initialize:function(){
		Event.observe('frame', 'mousemove', function(event) {
			var elt = Event.element(event);
			//alert(elt.up(0).inspect());
			xPos = Event.pointerX(event);
			yPos = Event.pointerY(event);
		});
		Event.observe('body', 'click', function(event) {
			/*
			var x = Event.pointerX(event);
			var y = Event.pointerY(event);
			var page_x = MouseCoord.prototype._pageWidth();
			var page_y = MouseCoord.prototype._pageHeight()
			var url = '/heat.php?width=' + page_x + '&height=' + page_y + '&x=' + x + '&y=' + y + '&url=' + window.location;
			new Ajax.Request(url);
			*/
			if ($(Event.element(event)).hasClassName("confirm"))
				if(!confirm(MouseCoord.prototype.ConfirmText)) Event.stop(event);
		});
		/*
		Event.observe('head', 'click', function(event) {
			if($('heat').style.visibility='hidden'){
				$('heat').style.visibility='visible';
				$('heat').style.top="0px";
				$('heat').style.left="0px";
				$('heat').style.width=MouseCoord.prototype._pageWidth() + "px";
				$('heat').style.height=MouseCoord.prototype._pageHeight() + "px";
				$('heat_map').style.width=MouseCoord.prototype._pageWidth() + "px";
				$('heat_map').style.height=MouseCoord.prototype._pageHeight() + "px";
			} else {	$('heat').style.visibility='hidden';	}
		});
		Event.observe('heat', 'click', function(event) {
			$('heat').style.visibility='hidden';
		});
		*/
	},
	_innerHeight:function(){
		if(self.innerHeight)								return(self.innerHeight);
		else if(document.documentElement && document.documentElement.clientHeight)	return(document.documentElement.clientHeight);
		else if(document.body)								return(document.body.clientHeight);
	},
	_innerWidth:function(){
		if(self.innerWidth)								return(self.innerWidth);
		else if(document.documentElement && document.documentElement.clientWidth)	return(document.documentElement.clientWidth);
		else if(document.body)								return(document.body.clientWidth);
	},
	_offsetHeight:function(height){
		if(height)
		{
			if(self.pageYOffset)								self.pageYOffset=height;
			else if(document.documentElement && document.documentElement.scrollTop)		document.documentElement.scrollTop=height;
			else if(document.body)								document.body.scrollTop=height;
		}
		else
		{
			if(self.pageYOffset)								return(self.pageYOffset);
			else if(document.documentElement && document.documentElement.scrollTop)		return(document.documentElement.scrollTop);
			else if(document.body)								return(document.body.scrollTop);
		}
	},
	_offsetWidth:function(width){
		if(width)
		{
			if(self.pageXOffset)								self.pageXOffset=width;
			else if(document.documentElement && document.documentElement.scrollLeft)	document.documentElement.scrollLeft=width;
			else if(document.body)								document.body.scrollLeft=width;
		}
		else
		{
			if(self.pageXOffset)								return(self.pageXOffset);
			else if(document.documentElement && document.documentElement.scrollLeft)	return(document.documentElement.scrollLeft);
			else if(document.body)								return(document.body.scrollLeft);
		}
	},
	_pageHeight:function(){
		var test1 = document.body.scrollHeight;
		var test2 = document.body.offsetHeight;
		if(test1 > test2)	return(document.body.scrollHeight);
		else			return(document.body.offsetHeight);
	},
	_pageWidth:function(){
		var test1 = document.body.scrollWidth;
		var test2 = document.body.offsetWidth;
		if(test1 > test2)	return(document.body.scrollWidth);
		else			return(document.body.offsetWidth);
	}	
}


function ViewPic(Id,Plugin,Height,Width,LicenceOwner)
{
  	var adresse = "/image.php?plugin=" + Plugin + "&imagedb:set_id=" + Id + "&view=web";
	$('img_blind').setStyle({
							 width: Width + "px",
							 height: Height + "px"
							});
  	$('div_view').setStyle({
  							width: Width + "px",
  							height: Height + "px",
  							background:"url(" + adresse + ") no-repeat"
  						  });  						  

	$$('#frame select').each(function(e) { e.setStyle({visibility:"hidden"}); }); 

	if (xPos>WindowSize('width')/2) xPos-=Width;
	if (yPos>WindowSize('height')/2) yPos-=Height;

	$('div_border').show();
  	$('div_border').setStyle({
  							top: yPos + "px",
  							left: xPos + "px"
  						  });  						  
  	$('view_label').firstChild.nodeValue = LicenceOwner;

}

function ClosePic()
{
	$('div_border').hide();
	$('img_blind').src="/system/blind.gif";
	$$('#frame select').each(function(e) { e.setStyle({visibility:"visible"}); }); 
}

function WindowSize (obj) {
	if (obj=="width")
	{
	  if (window.innerWidth) {
	    return window.innerWidth;
	  } else if (document.body && document.body.offsetWidth) {
	    return document.body.offsetWidth;
	  } else {
	    return 0;
	  }
  	} else {
	  if (window.innerHeight) {
	    return window.innerHeight;
	  } else if (document.body && document.body.offsetHeight) {
	    return document.body.offsetHeight;
	  } else {
	    return 0;
	  }
  	}
}

function ChangeBackgroundColor(Id,Color)
{
	if(Color!="")
	{
		document.getElementById(Id).style.setAttribute("backgroundColor",Color);
	}
	else
	{
		document.getElementById(Id).style.removeAttribute("backgroundColor");
	}
}

function DisplayElement(ElementId)
{
	$(ElementId).style.backgroundColor="#ff9900";
}
function HideElement(ElementId)
{
	$(ElementId).style.backgroundColor="transparent";
}

var ContextHandler="";

function DisplayMeta(Id,Mode)
{
	if(Mode)
	{
	  	$(Id).setStyle({top: (yPos+10) + "px",left: (xPos+10) + "px"});  						  
		$(Id).style.visibility="visible";
	}
	else
	{
		$(Id).style.visibility="hidden";
	}
}

function MCPMenuToggle(Elmt) 
{
	var Image = Elmt.getElementsByTagName("img")[0];
	if (Image.src.search(/_or.gif/)!=-1)
	{
		Image.src = Image.src.replace(/_or.gif/,".gif");
	} else {
		Image.src = Image.src.replace(/.gif/,"_or.gif");
	}
}		

