/*******************************************************************************
Author : Roger D. Hosto Jr.
Version : Version 1.0 - Oct 3, 2006
*******************************************************************************
Notes :
*******************************************************************************
The code display in the usage area should be placed in the body of the HTML 
document at the end of the page.
*******************************************************************************
Usage :
*******************************************************************************
<script type="text/javascript" src="floatwindow.js"></script>
<script type="text/javascript">
//Create a new float in window object.
var floater = new floatInWinder( "floater" );
// Set the object height
floater.Height = 500;
// Set the object width.
floater.Width = 550;
// Set the timeout to iconify or set to 0 to turn off this feature.
floater.icontime = 0;
// Set the url for the content window.
floater.url = "http://www.example.net/index.html";
// Set the icon graphic.
floater.icon = "http://www.example.net/picture.gif";
// Sets the delay time before showing float in window.
floater.delay = 1000;
// To enable cookie checking and for one time view per session. Set this to 1.
floater.enableCookieCheck = 1;
// Call Initization processes
floater.init();
document.onmousemove=floater.MoveWin;
</script>
*******************************************************************************/
/*
 * ONLY EDIT ANYTHING BELOW HERE IF YOU TRUELY KNOW WHAT YOU ARE DOING
 */
function floatInWinder( setName ) {
	// Adjustable Variables
	this.name = setName;
	this.Height = 200;
        this.Width = 550;
	this.icontime = 0;
	this.url = "";
	this.icon = "";
	this.delay = 1000;
        this.X = 0;
        this.Y = 0;
	this.offsetx = 0;
	this.offsety = 0;
	this.move = 0;
	this.enableCookieCheck=0;
	// Private Variables
	var CookieArray = new Array();
	var documentHeight=0;
	var documentWidth=0;
	var targetobj = null;
	var ns=(document.layers);
	var ie=(document.all);
	var w3=(document.getElementById && !ie);
	/*
	 * BEGIN PUBLIC FUNCTIONS
	 */
	// floatWindow.init()
        this.init = function(){
		if( this.enableCookieCheck ) {
			parseCookie();
			if( ! getCookie('sawfw') ) {
				this.create();
				setCookie();
			}
		} else {
			this.create();
		}

	}// end floatWindow.init();
	this.create = function(){
		if (ie){
			this.documentWidth = truebody().offsetWidth;
			this.documentHeight = truebody().offsetHeight;
		} else if (ns){
			this.documentWidth = window.innerWidth;
			this.documentHeight = window.innerHeight;
		} else if (w3){
			this.documentWidth = self.innerWidth;
			this.documentHeight = self.innerHeight;
		} 
		this.buildWindow();
		setTimeout( this.name+'.slideWindow()', this.delay );
		if( this.icontime > 0 ) {
			setTimeout( this.name+'.iconify()', ( this.delay + this.icontime ) );
		}
	}
	// floatWindow.showBody();
	this.showBody = function(){
		document.getElementById("TextBody").style.visibility = "visible";
	}// end floatWindow.showBody();
	// floatWindow.buildWindow
	this.buildWindow = function(){
		document.writeln("<div id=\"fIcon\" style=\"position:absolute;top:0px;left:0px;width:72px;height:62px;display:none;z-index:80;\"><a href=\"javascript:"+this.name+".deiconify();\"><img src=\""+this.icon+"\" border=\"0\" width=\"72\" height=\"62\"></a></div>\n");
		document.writeln("<div id=\"fWin\" style=\"position:absolute;width:"+this.Width+"px;height:"+this.Height+"px;z-index:80;\">" );
		document.writeln("<table cellpadding=0 cellspacing=0 border=1 width=\""+this.Width+"\">" );
		document.writeln("<tr><td align=\"right\" onmousedown=\""+this.name+".MoveWinOn(event);\" onmouseup=\""+this.name+".MoveWinOff(event);\" bgcolor=\"#5372a9\">" );
		document.writeln("<a href=\"javascript:"+this.name+".iconify();\"><img src=\"https://www.x10.com/images/floating_window_min_button.gif\" border=0></a><a href=\"javascript:"+this.name+".close();\"><img src=\"https://www.x10.com/images/floating_window_exit_button.gif\" border=0></a>");
		document.writeln("</td></tr><tr><td bgcolor=\"#000000\">" );
		document.writeln("<div id=\"fWinContent\" style=\"position:relative;width:"+this.Width+"px;height:"+this.Height+"px;\">" );
		document.writeln("<iframe onmouseover=\""+this.name+".MoveWinOff(event);\" src=\""+this.url+"\" frameborder=\"0\" scrolling=\"yes\" width=\""+this.Width+"\" height=\""+this.Height+"\" marginwidth=\"0\" marginheight=\"0\" hspace=\"0\" vspace=\"0\"></iframe>" );
		document.writeln("</div>");
		document.writeln("</td></tr></table>");
		document.writeln("</div>\n");
        	document.getElementById("fWin").style.top = ( ( this.documentHeight - this.Height ) / 2 );
		document.getElementById("fWin").style.left =  0 - ( this.Width + 20 );
	}// end floatWindow.buildWindow
	// floatWindow.slideWindow
	this.slideWindow = function(){
		var position = 0-this.Width;
		var position2 = ( position + 6 );
		var pause = 0;
		var i = 0;
		var movement = ( ( this.documentWidth / 2 ) + ( this.Width / 2 ) ) / 80;
		document.getElementById("fWin").style.top = ( document.documentElement.scrollTop > 0 )?( document.documentElement.scrollTop + 50 )+"px":( document.body.scrollTop + 50 )+"px";
		for ( i=0; i < 80; i++ ){
			pause=i*15;
			position = ( position + movement );
			position2 = ( position + 6 );
			setTimeout('document.getElementById("fWin").style.left='+position2+'+"px";', pause);
		}
		setTimeout( this.name+".MoveWinDown();", 500 );
	}// end floatWindow.slideWindow
	// floatWindow.close();
	this.close = function(){
		document.getElementById("fWin").style.display = "none";
	}// end floatWindow.close();
	// floatWindow.iconify();
	this.iconify = function(){
		document.getElementById("fWin").style.display = "none";
		document.getElementById("fIcon").style.top = ( this.documentHeight - 72 );
		document.getElementById("fIcon").style.display = "block";
	}// end floatWindow.iconify();
	// floatWindow.deiconify();
	this.deiconify = function(){
		document.getElementById("fWin").style.display = "block";
		document.getElementById("fIcon").style.display = "none";
	}// end floatWindow.deiconify();
	// floatWindow.MoveWinOn(event);
	this.MoveWinOn = function(e){
		var evtobj = ( window.event ) ? window.event : e;
		this.targetobj = ( window.event ) ? event.srcElement : e.target;
		if ( evtobj.preventDefault ) {
			evtobj.preventDefault();
		}
		this.move = 1
		this.X = parseInt( evtobj.clientX );
		this.Y = parseInt( evtobj.clientY );
		this.offsetx = parseInt( document.getElementById("fWin").style.left );
		this.offsety = parseInt( document.getElementById("fWin").style.top );
		return false;
	}// end floatWindow.MoveWinOn(event);
	// floatWindow.MoveWinoff(event);
	this.MoveWinOff = function(e){
		this.move = 0;
		return false;
	}// end floatWindow.MoveWinoff(event);
	// floatWindow.MoveWin(event);
	this.MoveWin = function(e){
		var evtobj = window.event ? window.event : e;
		if( floater.move ) {
			document.getElementById("fWin").style.top = ( floater.offsety + evtobj.clientY - floater.Y ) + "px"; 
			document.getElementById("fWin").style.left = ( floater.offsetx + evtobj.clientX - floater.X ) + "px";
		}
	}// end floatWindow.MoveWin(event);
	// floatWindow.MoveWinDown();
	this.MoveWinDown = function() {
		if( ! floater.move ) {
			scrollT = (document.documentElement.scrollTop)?document.documentElement.scrollTop:document.body.scrollTop;
			if( parseInt(document.getElementById("fWin").style.top )  < scrollT || 
			    parseInt(document.getElementById("fWin").style.top )  > ( scrollT + this.documentHeight ) ) {
				document.getElementById("fWin").style.top = ( scrollT + 20 ) + "px";
			}
			document.getElementById("fIcon").style.top = ( this.documentHeight - 72 );
		}
		setTimeout( this.name+".MoveWinDown();", 500 );
	}// end floatWindow.MoveWinDown();
	/*
	 * BEGIN PRIVATE FUNCTIONS
	 */
	// truebody
	function truebody(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	} // end truebody();
		//parses the document.cookies and places them into array of key/value
	function parseCookie() {
		var CookieStr = document.cookie;
		var CookieSt = CookieStr.split( ';' );
		var StSize = CookieSt.length;
		for ( x = 0; ( x < StSize ); x++ ){
			CookiePces = CookieSt[x].split( '=' );
			var len = CookieArray.length;
			CookieArray[ len ] = new Array();
			// Make the remove the leading white space
			CookieArray[ len ][0] = CookiePces[0].replace( /^\s/, "");
			CookieArray[ len ][1] = unescape( CookiePces[1] );
		}
		return null;
	}//end parseCookie
	// returns the value of the key
	function getCookie( str ) {
		var len = CookieArray.length;
		for( x = 0; x < len; x++ ) {
			if( str == CookieArray[x][0] ) {
				return CookieArray[x][1];
			}
		}
		return null;
	}//end getCookie
	// seta Cookie
	function setCookie() {
		document.cookie = "sawfw=1; path=/ ;";
	}//end setCookie
} //END 
