// Create namespace for out classes
if (!window.heateddetails) { window.heateddetails = {}; }
var hd = window.heateddetails;
hd.classes =
{
	_nFadeSpeed		: 5,						            	// fade speed
	_nMaxAlpha		: 100,								// how much opacity do we want it to-be when complete
	_objCurrentPU	: [],
	_objCurrentRO	: [],
	_objFocus		: null,
	_bNavBtnAction	: false,
	qpFORM			: "",
	qpPUBL			: "",
	qpCREA			: "",
	qpDEFAULT		: "&FORM=M00FCA&Publ=XSEARCH&Crea=STND_M00FCA_PrdTourCA_PrdTourCA_ExploreBingOrganic_1x1",
	setMaxHeight: function( idElement )
	{
		if ( this._bNavBtnAction == false )
			return;
		this._bNavBtnAction = false;
	
		var oFrame = document.getElementById ? document.getElementById( idElement ) : null;
		var nHeight = this._getWindowHeight();
		if(oFrame)
			oFrame.height = (nHeight-(56+6)); // 37 is height of frameNav, not sure where the other 6 came from, but good to seperate it for now. (+6 for FF, +7 for IE)
		
		this._showPopups();
		
		if ( this._objFocus )
		{
			try{ this._objFocus.focus(); }
			catch(er){}
		}
		
	},
	getCosmosParameters: function()
	{
		var strParam = "";
		if ( this.qpFORM.length > 0 )
			strParam += "&FORM=" + this.qpFORM;
		if ( this.qpPUBL.length > 0 )
			strParam += "&Publ=" + this.qpPUBL;
		if ( this.qpCREA.length > 0 )
			strParam += "&Crea=" + this.qpCREA;
		if ( strParam.length == 0 )
			strParam = this.qpDEFAULT;
		return strParam;
	},
	navigate: function( objSource )
	{
		var objHandler;
		if ( objSource == undefined )
			objHandler = eval("hd.handlers.defaulthandler");
		else
			objHandler = eval( objSource.getAttribute("handler") );
		
		this._bNavBtnAction = true;
		this._hidePopups();
		this._objCurrentPU = objHandler.pu;
		var objFrame = hd.utils.browser.getObject( 'frameBing' );
		if ( objFrame )
		{
			var strURL = objHandler.href;
			if ( strURL != hd.handlers.defaulthandler.href )
				strURL += this.getCosmosParameters();
			objFrame.src = strURL;
		}
		this._objFocus = objSource;
	},
	handleClick: function( objSource )
	{
		try
		{
			var objHandler = eval( objSource.getAttribute("handler") );
			var ot = "Navigation Click";
			var evt = "event2";
			if ( objHandler != undefined )
			{
				ot = objHandler.ot;
				evt = objHandler.evt;
			}
			var s=s_gi("mswlsrccrmcabingtourcom");
			s.linkTrackVars="prop1,prop3,prop4,prop27,eVar1,eVar3,events";
			s.linkTrackEvents=evt;
			s.prop1=ot;
			s.prop3=ot;
			s.prop4=s.prop27 + ' - ' + s.prop1;
			s.eVar1=ot;
			s.eVar3=ot;
			s.events=evt;
			s.tl(objSource,"o",ot);
		}
		catch(ex){}
		// now navigate the frame to show the correct page
		this.navigate( objSource );	
	},
	handleExit: function()
	{
		try
		{
			var ot = "Exit: Button";
			var s=s_gi("mswlsrccrmcabingtourcom");
			s.linkTrackVars="prop1,prop3,prop4,prop27,eVar1,eVar3,events";
			s.linkTrackEvents="event9";
			s.prop1=ot;
			s.prop3=ot;
			s.prop4=s.prop27 + ' - ' + s.prop1;
			s.eVar1=ot;
			s.eVar3=ot;
			s.events="event9";
			s.tl(this,"e",ot);
		}
		catch(ex){}
		//var objFrame = hd.utils.browser.getObject( 'frameBing' );
		//if ( objFrame )
		//	window.location = objFrame.src;
		window.location = "http://www.bing.com";
	},
	rollover: function( objHandler, objSource )
	{
		//if ( objSource.ro != undefined )
			//hd.utils.browser.showObject( objSource.ro, false );
		this._objCurrentRO = objHandler.ro;
		this._showRollover( objSource, objHandler.ro );
	},
	_hidePopups: function()
	{
		for( var nIndex in this._objCurrentPU )
		{
			var strID = this._objCurrentPU[nIndex].name;
			var objPU = hd.utils.browser.getObject( strID );
			if ( objPU )
			{
				hd.utils.browser.setObjectPos( objPU, null, this._objCurrentPU[nIndex].x, this._objCurrentPU[nIndex].y );
				this._showPopupObject(  objPU, false );
			}
		}
	},
	_showPopups: function()
	{
		for( var nIndex in this._objCurrentPU )
		{
			var strID = this._objCurrentPU[nIndex].name;
			var objPU = hd.utils.browser.getObject( strID );
			//alert( strID );
			if ( objPU )
			{
				hd.utils.browser.setObjectPos( objPU, null, this._objCurrentPU[nIndex].x, this._objCurrentPU[nIndex].y );
				this._showPopupObject(  objPU, true );
			}
		}
	},
	_hideRollover: function()
	{
		if ( this._objCurrentRO != "" )
		{
			var strID = this._objCurrentRO[0].name;
			var objRO = hd.utils.browser.getObject( strID );
			if ( objRO )
			{
				this._showPopupObject(  objRO, false );
			}
		}
	},
	_showRollover: function( objSource, objCurrentRO )
	{
		var strID = objCurrentRO[0].name;
		var objRO = hd.utils.browser.getObject( strID );
		//alert( strID );
		if ( objRO )
		{
			hd.utils.browser.setObjectPos( objRO, null, objCurrentRO[0].x, objCurrentRO[0].y );
			objRO.objSource = objSource;
			objSource.ro = objRO;
			this._showPopupObject(  objRO, true );
		}
	},
	onMouseDown: function(oEvent)
	{
		//alert( "down" );
		this._hidePopups();
	},
	resetRollOverObjects: function()
	{
		hd.mm.handleMouseOut();
	},
	_getWindowHeight: function()
	{
		var nWidth = 0;
		var nHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) 
		{
		  //Non-IE
		  nWidth = window.innerWidth;
		  nHeight = window.innerHeight;
		} 
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		{
		  //IE 6+ in 'standards compliant mode'
		  nWidth = document.documentElement.clientWidth;
		  nHeight = document.documentElement.clientHeight;
		} 
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
		{
		  //IE 4 compatible
		  nWidth = document.body.clientWidth;
		  nHeight = document.body.clientHeight;
		}
		return nHeight;
	},
	_showPopupObject: function( objCurrent, bShow )
	{
		if ( !objCurrent ) return;

		if ( bShow ) 
			this._fadeIn( objCurrent, this._nFadeSpeed );
		else
			this._fadeOut( objCurrent );
		
	},
	fadeIn: function( strID, fs )
	{
		var obj = hd.utils.browser.getObject( strID );
		if ( obj )
		{
			obj.className = "navMenu";
		}
		//this._fadeIn( obj, fs );
	},
	_fadeIn: function( objCurrent, fs ) 
	{
		if ( objCurrent )
		{
			hd.utils.browser.showObject( objCurrent, true );
			this._fadeIn2( objCurrent, 0, fs );
		}
	},
	_fadeIn2: function( objCurrent, nFader, fs) 
	{
		if ( objCurrent )
		{
			var obj;
			nFader += fs;
			nFader = (this._nFader > 100) ? 100 : nFader;
			this._fadeObject( objCurrent, nFader, true );
			if (nFader < this._nMaxAlpha)
				hd.utils.setTimeout( hd.classes._fadeIn2, 20, this, objCurrent, nFader, fs );
			
		}
	},
	_fadeObject: function( obj, opa, bNoFilter )
	{
		opa *= .01;
		if ( hd.utils.browser.is_nav4 )
		{
			hd.utils.browser.showObject( obj, true );
		}
		else if ( hd.utils.browser.is_nav6 )
		{
			obj.style["-moz-opacity"] = opa;
		}
		else
		{
			if ( !bNoFilter )
				obj.style["filter"] = "alpha(opacity=" + parseInt( 100 * opa ) + ")";
			obj.style["opacity"] = opa;
		}
	},
	fadeOut: function( strID )
	{
		var obj = hd.utils.browser.getObject( strID );
		if ( obj )
		{
			obj.className = "navMenuOff";
		}
		//this._fadeOut( obj );
	},
	_fadeOut: function( objCurrent ) 
	{
		if ( !objCurrent ) return;
		hd.utils.browser.showObject( objCurrent, false );
	}
};
