/***************************************************************************
 *       ___ _   _                    ____           _       _
 *      |  _| | | |_ __  _ _  ___    / ___|  ___ _ _(_)_ __ | |_
 *      | |_| |_| | '_ \| '_)/ _ \   \___ \ / __| '_) | '_ \| __| 
 *      |  _|  _  | |_) | | | (_) |   ___) | (__| | | | |_) | |_ 
 *      |_| |_| |_| .__/|_|  \___/   |____/ \___|_| |_| .__/ \__|
 *                |_|  www.fhpro.de                   |_|
 *
 *   Copyright            : (c) 2006 Frank Hinkel
 *   Kontakt              : info@fhpro.de
 *
 ***************************************************************************/

/*** IMAGE LAYER ***/
function FhproSnapLink() {
    this._isLayerOpen;
    this._currentImage;
    this._currentTitel;
    this._currentFavid;
    this._showLayer;
    this._objType;    
    this._borderRight; 
    this._currentLink;
    this.objImgLayer;  
    this.objPos;  
    this._xPadding, this._yPadding;
    
    // d= dynamisch, l=links, r=rechts    
    this._LayerPos = 'l';
}
FhproSnapLink.prototype = {
    
	initialize: function() 
	{
		this._isLayerOpen  = false;
		this._showLayer    = true;
		this._objType      = -1; 
		this._xPadding     = 15;
		this._yPadding     = 10;
		this._borderRight  = 40;
		this._currentFavid = -1;		
		this._currentLink  = "";
		this._currentTitel = "";
		this.objPos = {x : 0, y : 0};		
		
		var objBody = document.getElementsByTagName("body").item(0);					
		var objImg  = document.createElement("div");
		
		
		objImg.setAttribute('id','FhproImgLayer');
		objImg.style.display  = 'none';
		objImg.style.position = 'absolute';
		objImg.style.top    = '0px';
		objImg.style.left   = '0px';
		objImg.style.zindex = '793';
		objImg.style.cursor = 'default';
		objImg.style.backgroundColor = '#fff';
		objImg.style.backgroundImage = "url('/templates/default/images/gif/spacer.gif')";
				
		//CLweb2.addEvent(objImg,'mouseout','CLsnaplink.end()');		
		//objImg.onmouseout = function() { CLsnaplink.end(); return false; }
		
		this.objImgLayer  = objImg;
		objBody.insertBefore(objImg, objBody.firstChild);
		
	},
	mouseMove: function(e)
	{
		if (!this._isLayerOpen)
			return;		
		
		var coordObj = this.getLayerPosition(e);

		//this.objImgLayer.style.top  = coordObj.y + 'px';
		//this.objImgLayer.style.left	= coordObj.x + 'px';	
		this.objImgLayer.style.top  = this.objPos.y + 'px';
		this.objImgLayer.style.left	= this.objPos.x + 'px';		
		
		this.objImgLayer.style.display = 'block';			
	},
	mouseOut: function()
	{
		this.end();
	},
	start: function(el, favid, titel, link, type)
	{	
		CLsnaplink.end();
		
		if (this._isLayerOpen)
			return;		
				
		if (!this._showLayer)
			return				
		
		this.objPos.x = CLweb2.getAbsPosition(el).x-((320-el.width)/2);
		this.objPos.y = CLweb2.getAbsPosition(el).y-((260-el.height)/2);
			
		this._objType = type;				
		this._isLayerOpen = true;					
		this.objImgLayer.innerHTML = CLsnaplink.createHTML('loading');
			
		this._currentFavid = favid;
		this._currentLink  = link;
		this._currentTitel = titel;
		
		if (this._objType == 'snapware')
            link = 'http://www.kulmbach-aktuell.de/snapware/?' + escape(link);

		//if (this._objType == 'img')
			this.loadImage(link);
			
			
	},
	end: function()
	{
		this.objImgLayer.style.display = 'none';
		this._isLayerOpen = false;	
	},
	getLayerPosition: function(e)
	{	
		var xObj, yObj;
		var xCoord, yCoord;
		var topHeight;		
		var winSize = this.getWindowSize();
		
		/** object size **/
		//if (this._objType == 'img')
		//{
			xObj = this._currentImage.width;
			yObj = this.objImgLayer.offsetHeight;
		//}
		/** object position **/
		if (typeof e != 'undefined')
		{
			topHeight = document.body.scrollTop ? document.body.scrollTop : window.pageYOffset;
			xCoord = e.pageX;
			yCoord = e.pageY;
			//yCoord = e.pageY + topHeight;			
		}
		else
		{
            topHeight = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
			xCoord = window.event.clientX;
			yCoord = window.event.clientY + topHeight;	
		}	
		
		/** check position **/
		if ((xCoord + xObj) >= (winSize.x-this._borderRight))
			xCoord -= xObj + (this._xPadding+15);
		else
			xCoord += this._xPadding;
			
		if ((yCoord + yObj) >= (winSize.y+topHeight))
			yCoord = (winSize.y+topHeight)-(yObj+this._yPadding);
		else
			yCoord += this._yPadding;

		if (this._LayerPos == 'l')
		    xCoord -= xObj + (this._xPadding+25);
		if (this._LayerPos == 'r')
		    xCoord += this._xPadding;
        return {"x":xCoord,"y":yCoord};		
	},
	getWindowSize: function()
	{
		var windowWidth, windowHeight;
		if (self.innerHeight) {
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
				
		return {"x":windowWidth,"y":windowHeight};		
	},
	loadImage: function(link)
	{		
		this._currentImage = new Image();
		this._currentImage.onload = function()
		{
			CLsnaplink.objImgLayer.innerHTML = CLsnaplink.createHTML('img');	
		}
		this._currentImage.src = link;
		
	},
	deleteItem: function(elemId)
	{
		top.location = '/web-186/meine_favoriten.html?do=delFav:favid=' + elemId;
	},
	createHTML: function(type)
	{	    
		var _html = '';
		_html += '<div style="padding: 5px; background-color: #fff; border: 1px solid #888;">';
		_html += '<div align="center" style="padding: 2px 2px 2px 2px;background-image:url(/templates/default/images/gif/loading.gif);background-repeat:no-repeat;background-position:center center;">';
		
		if (type == 'loading')	
			_html += '<div style="height:25px;width:25px;"></div>';
		if (type == 'img')
		{
			//_html += '<img src="' + this._currentImage.src + '" border="0" />';
			_html += '<div style="background-image:url('+this._currentImage.src+');background-repeat:no-repeat;background-position:center center;">';
			_html += '<div style="width:320px;height:240px;cursor:pointer" onclick="window.open(\''+this._currentLink+'\')"></div></div>';
			_html += '<div class="layerURL"><b>' + this._currentTitel + '</b></div>';
			_html += '<div class="layerURL">' + this._currentLink + '</div>';
			_html += '<div style="text-align:center;padding-top:2px;"><img src="/templates/default/images/gif/link_loeschen.gif" onclick="CLsnaplink.deleteItem(\''+this._currentFavid+'\');" width="66" height="16" style="cursor:pointer" border="0" alt="" /></div>';
		}
		_html += '</div>';		
		_html += '</div>';
		return _html;
	}
}
function FhproSnapLinkMove(e)
{
	CLsnaplink.mouseMove(e);
}
function FhproSnapLinkUP(e)
{
	CLsnaplink.end();
}
function initSnapLink()
{        
	CLsnaplink.initialize();
}
var CLsnaplink = new FhproSnapLink(); 
CLweb2.setOnLoad("initSnapLink()"); 
document.onmousemove = FhproSnapLinkMove;
document.onmouseup = FhproSnapLinkUP;
/*** IMAGE LAYER END ***/

