/**
 * window size and location can only be set during page load - you create and position is same page load event.
 * @param {Object} elementId
 * @param {Object} values
 */
function ContentWindow(elementId,values)
{
	
	if ( null != document.getElementById(elementId))
	{
		alert(elementId + 'already exists in DOM - please try again with a new elementId');
		return null;
	}
	var self = this;
	
	this.Id = elementId;
	this.setId = function(x) { this.Id = x;}
	this.getId = function() {return this.Id;}
	
	this.name = elementId;
	this.setName = function(x) { this.name = x;}
	this.getName = function() { return this.name;}
	
	this.width = 0;
	this.setWidth = function(x) { this.width = x ; document.getElementById( this.getId() ).style.width = x + "px";}
	this.getWidth = function() { return this.width ;}
	
	this.height = 0;
	this.setHeight = function(x) { this.height = x ; document.getElementById( this.getId() ).style.height = x + "px";}
	this.getHeight = function() { return this.height;}
	
	this.backgroundImageDivId = null; //"divBackgroundImage";
	this.getBackgroundImageDivId = function() { return this.backgroundImageDivId; }
	this.setBackgroundImageDivId = function(x) { this.backgroundImageDivId = x; } 
	
	this.backgroundImageSrc = null;
	this.setBackgroundImageSrc = function(x) { this.backgroundImageSrc = x; }
	this.getBackgroundImageSrc = function() { return this.backgroundImageSrc; }
	
	this.backgroundImageId = '_ContentWindow_imgBackground';
	this.setBackgroundImageId = function(x) { this.backgroundImageId = x; }
	this.getBackgroundImageId = function() { return this.backgroundImageId; }
	
	this.allowtransparency;
	this.getAllowTransparency = function() { return this.allowtransparency;}
	this.setAllowTransparency = function(x) { this.allowtransparency = x;}
	
	this.setLocation = function(x,y)
	{
		//alert('setLocation called for ' + this.getId() + ": " + x + " - " + y);
		var _divContent = document.getElementById( this.getIframeDivId() ); //getId()
		_divContent.style.left = x + "px"; // parseInt( findPosX( divContentAnchor ) )+ passedX ;  // , findPosY( _divContent )+ _x );
		_divContent.style.top = y + "px"; //parseInt( findPosY( divContentAnchor ) ) + passedY ;


		var _divContentImg = document.getElementById( this.getBackgroundImageDivId() );
		_divContentImg.style.left = (x )  + "px"; // -25 // parseInt( findPosX( divContentAnchor ) )+ passedX ;  // , findPosY( _divContent )+ _x );
		_divContentImg.style.top = (y - 25) + "px"; // -25 //parseInt( findPosY( divContentAnchor ) ) + passedY ;

	}

	this.URL = "javascript:void(0)";
	this.getURL = function() { return this.URL;}
	this.setURL = function(x) { document.getElementById( this.getId() ).src = x; URL = x;}
	
	this.style = "";//display: none;"
	this.setStyle = function(x) { this.style = x;}
	this.getStyle = function() { return this.style;}
	
	this.parentElement = "divContent";
	this.getParentElement = function() { return this.parentElement;}
	this.setParentElement = function(x) { this.parentElement = x;}
	
	this.marginWidth =0;
	this.getMarginWidth = function(){ return this.marginWidth; }
	this.setMarginWidth = function(x) { this.marginWidth = x;}
	
	this.marginHeight=0;
	this.getMarginHeight = function(){ return this.marginHeight; }
	this.setMarginHeight = function(x) { this.marginHeight = x;}
		
	this.scrolling='no';
	this.getScrolling = function(){ return this.scrolling; }
	this.setScrolling = function(x) { this.scrolling = x;}
	
	this.frameborder="0";
	this.getFrameborder = function(){ return this.frameborder; }
	this.setFrameborder = function(x) { this.frameborder = x;}
	
	this.shadow;
	
	
	this.iframeDivId
	this.getIframeDivId = function() { return this.iframeDivId; }
	this.setIframeDivId = function(x) { this.iframeDivId = x; }
	
	this.showBackgroundImage = 'false';
	this.getShowBackgroundImage = function() { return this.showBackgroundImage; }
	this.setShowBackgroundImage = function(x) { this.showBackgroundImage = x; }
	
	this.renderNewWindow = function()
	{
		//  http://msdn2.microsoft.com/en-us/library/ms536389.aspx
		//  As of Internet Explorer 5, you can create all elements programmatically, except frame and iframe.
		if ( navigator.appName.indexOf('Explorer') != -1 )
		{
				//alert("render for IE called to make id " + this.getId() );
				var iFrame = "";
				
				//Detect IE5.5+
				var version=0
				if (navigator.appVersion.indexOf("MSIE")!=-1)
				{
					temp=navigator.appVersion.split("MSIE")
					version=parseFloat(temp[1])
					//alert(version);
				}
				if (version <= 6) //NON IE browser will return 0
				{
					this.setBackgroundImageSrc("/lib/ContentWindow/1.0/backgroundIE6.gif");
					//this.setBackgroundImageSrc("/lib/ContentWindow/1.0/background.png");
				}
				//alert(this.getShowBackgroundImage());
				//alert( this.getBackgroundImageSrc() );
				if (1 == 1)
				{
					//iFrame += "<div id='divBackground' style=\"background-image: url('http://build.aaaohio.com/lib/ContentWindow/1.0/background.png'); height:435px; width:665px;\"></div>";
					iFrame += "<div id='" + this.getBackgroundImageDivId() + "'>";
						if ( this.getShowBackgroundImage() == 'true' )
						{
							//alert("showing background image for " + this.getId() );
							iFrame += "<img src='" + this.getBackgroundImageSrc() + "' id='" + this.getBackgroundImageId() + "' onclick='javascript:" + this.getId() + ".hideWindow();'>";
						}
					iFrame += "</div>"
				}

				iFrame +=  "<div id='" + this.getIframeDivId() + "'><iframe id ='" + this.getId() + "' width='" + this.getWidth() + "' height='" + this.getHeight() + "' src='" + this.getURL() + "' marginwidth='" + this.getMarginWidth() + "' marginheight='" + this.getMarginHeight() + "' scrolling='" + this.getScrolling() + "' frameborder='" + this.getFrameborder() + "' allowtransparency='" + this.getAllowTransparency() + "'></iframe></div>";
				//alert(iFrame);
				document.getElementById( this.getParentElement() ).innerHTML += iFrame;
				return;
		}
		
		var iframe;
		//alert( this.getId() + " " + this.getStyle() + " " + this.getParentElement() );
		var newIframe = document.createElement("iframe");
		var newDiv = document.createElement("div");
		var newImage = document.createElement("img");
		var newIframeDiv = document.createElement("div");

		document.getElementById( this.getParentElement() ).appendChild(newDiv);
		if ( this.getShowBackgroundImage() == 'true')
		{
			newDiv.appendChild(newImage);
		}
			
		document.getElementById( this.getParentElement() ).appendChild(newIframeDiv);
		newIframeDiv.appendChild( newIframe );
		
		//document.getElementById( this.getParentElement() ).appendChild(newIframe);
	
		newIframe.setAttribute('id', this.getId() );
		newIframe.setAttribute('width', this.getWidth() );
		newIframe.setAttribute('height', this.getHeight() );
		newIframe.setAttribute('src', this.getURL() );
		//newIframe.setAttribute('style', this.getStyle() );
		newIframe.setAttribute('marginWidth', this.getMarginWidth() );
		newIframe.setAttribute('marginHeight',this.getMarginHeight() );
		newIframe.setAttribute('scrolling',this.getScrolling() );
		newIframe.setAttribute('frameborder', this.getFrameborder() );
		
		newDiv.setAttribute('id', this.getBackgroundImageDivId() );
		newDiv.setAttribute('style', this.getStyle() );
		
		newImage.setAttribute('src', this.getBackgroundImageSrc() );
		newImage.setAttribute('id', this.getBackgroundImageId() );
		
		var _newImage = document.getElementById(this.getBackgroundImageId() );
		//_newImage.addEventListener('click', function() { self.hideWindow() }, false);
		
		newIframeDiv.setAttribute('id', this.getIframeDivId() );
		
		return iframe;		
	}
	
	this.hideWindow = function() 
	{ 
		//document.getElementById( this.getId() ).style.display = 'none';
		//document.getElementById( this.getBackgroundId() ).style.display = 'none';
		document.getElementById( this.getParentElement() ).style.display = 'none';
	}
	
	this.showWindow = function() 
	{ 
		//document.getElementById( this.getId() ).style.display = 'block';
		document.getElementById( this.getBackgroundImageDivId() ).style.display = 'block';
		document.getElementById( this.getParentElement() ).style.display = 'block';
	}

	this.setURLVoid = function() { document.getElementById( this.getId() ).src = ""; this.URL = "javascript:void(0)";}
	
	this.focus = function() { document.getElementById( this.getId() ).focus(); }
	
	this.hideWindowSetURLVoid = function()
	{
		//alert("hideWindowSetURLVoid called...");
		this.hideWindow();this.setURLVoid();
	}
	
	// iterate through all the configurations and populate local variables
	for (var n in values) 
	{ 
		//alert( n + "=" + values[n] );
		this[n] = values[n]; 
		 
	}
	
		if ( typeof window[elementId] != 'undefined')
		{
			alert("window " + elementId + " already exists");
			return;	
		}
		
}

