/*
v 1.0.0
Last modified 2008.01.28 by SK

Creates page-specific-graphics with input from a paragraph-layout.
Sets a given image and has possibility to write a given text on top of it, and making it linking to a given page/url.

Use this class as the following:

	var myGraph =  new pageSpecGraphic( sContainer , sNewImgElement , sNewImgTxtElement , sDefaultImgSrc );
	
	// sContainer	 		: string	: the element-id represented as a string, of the element that stands for the paragraph-layout (the one containing the data, the one that should be hidden when this class is called)
	// sNewImgElement		: string	: the element-id represented as a string, of the element where the graphic should be displayed
	// sNewImgTxtElement	: string	: the element-id represented as a string, of the element where the graphic description (text on top of image) should be displayed
	// sDefaultImgSrc		: string	: image-source of an optional default image (use "" when option not used => if sNewImgElement already has an background image this will remain being displayed)
	
	
	
	myGraph.putGraph();// Moves the graphic

*/



// Class for page-specific-graphic JavaSscript-module
// constructor
function pageSpecGraphic( sContainer , sNewImgElement , sNewImgTxtElement , sDefaultImgSrc )
{
	/*-- Get data methods --*/
	function funcGetImgSrc()
	{
		var oImgContainer = document.getElementById("pagespec_image");
		var aImg = oImgContainer.getElementsByTagName("img");
		if( aImg.length <= 0 ) return '';
		return aImg[0].src;
	}
	
	
	function funcGetImgText()
	{
		var oTextContainer = document.getElementById("pagespec_text");
		if( oTextContainer ) return oTextContainer.innerHTML;
		else return "";
	}
	
	
	function funcGetImgLink()
	{
		var oLinkContainer = document.getElementById("pagespec_link");
		var aLink = oLinkContainer.getElementsByTagName("a");
		if( aLink.length <= 0 ) return '';
		if( !aLink[0].href ) return '';
		return aLink[0].href;
	}
	
	
	/*-- Set data methods --*/
	function funcSetImgSrc( sImgSrc , sDefaultImgSrc )
	{
		if( sImgSrc != "" )
		{
			this.oNewImgElement.style.backgroundImage = "url(" + sImgSrc + ")";
			this.oNewImgElement.style.backgroundRepeat = "no-repeat";
		}
		else if( sDefaultImgSrc != "" )
		{
			this.oNewImgElement.style.backgroundImage = "url(" + sDefaultImgSrc + ")";
			this.oNewImgElement.style.backgroundRepeat = "no-repeat";
		}	
	}
	
	
	function funcSetImgText( sImgText )//Still under development
	{
		if( sImgText != "" )
		{
			//this.oNewImgElement.innerHTML = sImgText;
			var floatEl = document.createElement("div");
			floatEl.id = "pageSpecGraph_text";
			floatEl.style.position = "absolute";
			floatEl.innerHTML = sImgText;
			
			this.oNewImgTxtElement.style.position = "relative";
			this.oNewImgTxtElement.appendChild( floatEl );
		}		
	}
	
	
	function funcSetImgLink( sImgHref )
	{
		if( sImgHref != "" )
		{
			var onclickHandler = document.createAttribute("onclick");
			onclickHandler.value="document.location.href = '" + sImgHref + "'";
			this.oNewImgElement.setAttributeNode(onclickHandler);
			this.oNewImgElement.style.cursor = "pointer";
		}		
	}
	
	
	/*--- public methods --*/
	function funcPutGraph()
	{
		this.oNewImgElement = document.getElementById( this.sNewImgElementId );
		
		// Set image
		var sImgSrc = this.getImgSrc();
		this.setImgSrc( sImgSrc , this.sDefaultImgSrc );
		
		// Set text
		var sImgText = this.getImgText();
		this.setImgText( sImgText );
		
		// Set link
		var sImgHref = this.getImgLink();
		this.setImgLink( sImgHref );

	}
	
	
	function funcHideContainer()
	{
		document.getElementById( this.sContainer ).style.display = "none";
	}
	
	
	
	
	// Class properties
	this.sContainer				 = sContainer;//arg
	this.oContainer				 = document.getElementById( this.sContainer );
	this.sNewImgElementId		 = sNewImgElement;//arg
	this.oNewImgElement			 = document.getElementById( this.sNewImgElementId );
	this.sNewImgTxtElementId	 = sNewImgTxtElement;//arg
	this.oNewImgTxtElement		 = document.getElementById( this.sNewImgTxtElementId );
	this.sDefaultImgSrc			 = sDefaultImgSrc;//arg4
	
	
	//Class methods
	this.putGraph		 = funcPutGraph;
	this.hideContainer	 = funcHideContainer;
	this.getImgSrc		 = funcGetImgSrc;
	this.getImgText		 = funcGetImgText;
	this.getImgLink		 = funcGetImgLink;
	this.setImgSrc		 = funcSetImgSrc;
	this.setImgText		 = funcSetImgText;
	this.setImgLink		 = funcSetImgLink;
	
	
	// 'on load' class
	this.hideContainer();
	
}