﻿function ExitLightBox( intWidth, intHeight, strShadowCssClass, strContentCssClass, strHtmlContent){ //per ali's circulation request [knguyen/20100308]
	this.Width = intWidth;
	this.Height = intHeight;
	this.XPos = 0;
	this.YPos = 0;

	this.ShadowCssClass = strShadowCssClass;
	this.ContentCssClass = strContentCssClass;
	this.HtmlContent = strHtmlContent;

	this.DivContent = null;
	this.DivExitLightBox = null;

	this.blnIsActive = false;

	this.EntryClickMode = 0;

	this.m_WindowWidth = 0; 
	this.m_WindowHeight = 0;

	/*-----------------------------------------------------------------------------------------------*/
	//Browser detect script originally created by Peter Paul Koch at http://www.quirksmode.org/

	this.m_strDetect = navigator.userAgent.toLowerCase();
	this.m_strOs = null;
	this.m_strBrowser = null;
	this.m_strVersion = null;
	this.m_strTheString = null;
	this.m_intPlace = -1;

	this.GetBrowserInfo = function(){
		if( this.CheckIt('konqueror')){
			this.m_strBrowser = "Konqueror";
			this.m_strOs = "Linux";
		}
		else if( this.CheckIt('safari')) this.m_strBrowser = "Safari"
		else if( this.CheckIt('omniweb')) this.m_strBrowser = "OmniWeb"
		else if( this.CheckIt('opera')) this.m_strBrowser = "Opera"
		else if( this.CheckIt('webtv')) this.m_strBrowser = "WebTV";
		else if( this.CheckIt('icab')) this.m_strBrowser = "iCab"
		else if( this.CheckIt('msie')) this.m_strBrowser = "Internet Explorer"
		else if( !this.CheckIt('compatible')) {
			this.m_strBrowser = "Netscape Navigator"
			this.m_strVersion = this.m_strDetect.charAt(8);
		} else this.m_strBrowser = "An unknown browser";

		if( !this.m_strVersion) this.m_strVersion = this.m_strDetect.charAt( this.m_intPlace + this.m_strTheString.length);

		if( !this.m_strOs) {
			if( this.CheckIt('linux')) this.m_strOs = "Linux";
			else if( this.CheckIt('x11')) this.m_strOs = "Unix";
			else if( this.CheckIt('mac')) this.m_strOs = "Mac"
			else if( this.CheckIt('win')) this.m_strOs = "Windows"
			else this.m_strOs = "an unknown operating system";
		}
	}

	this.CheckIt = function( strValue) {
		this.m_intPlace = this.m_strDetect.indexOf( strValue) + 1;
		this.m_strTheString = strValue;
		return this.m_intPlace;
	}

	// Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
	this.PrepareIe = function( intHeight, strOverflow){
		var objHtmlBody = document.getElementsByTagName('body')[0];
		objHtmlBody.style.height = intHeight;
		objHtmlBody.style.overflow = strOverflow;
  
		var objHtmlTag = document.getElementsByTagName('html')[0];
		objHtmlTag.style.height = intHeight;
		objHtmlTag.style.overflow = strOverflow;
	};

	// In IE, select elements hover on top of the lightbox
	this.HideSelects = function( strVisibility){
		lstHtmlSelect = document.getElementsByTagName('select');
		for( var intIndex=0; intIndex<lstHtmlSelect.length; intIndex++) {
			if( lstHtmlSelect[ intIndex].id.indexOf( 'LightBox') == -1)
				lstHtmlSelect[ intIndex].style.visibility = strVisibility;
		}
	};
	
	// Taken from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
	this.GetScroll = function(){
		if (self.pageYOffset) {
			this.yPos = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){
			this.yPos = document.documentElement.scrollTop; 
		} else if (document.body) {
			this.yPos = document.body.scrollTop;
		}
	};
	
	this.SetScroll  = function( intX, intY){
		window.scrollTo( intX, intY); 
	};

	this.Show = function(){  // do not activate if regular lightbox is on
		if( this.blnIsActive || blnLightBoxOn || get_cookie('ExitLightBox')=='yes'){ return false;}
		objExitLightBox.FixUpDimensions();
		blnExitLightBoxOn = this.blnIsActive=true;

		if( this.m_strBrowser == "Internet Explorer"){
			this.GetScroll();
			this.PrepareIe('100%', 'hidden');
			this.SetScroll(0,0);
			this.HideSelects('hidden');
		}

		this.DivExitLightBox.style.display = 'block'; 
		 
		this.DivContent.style.top = this.YPos + 'px'; 
		this.DivContent.style.left = this.XPos + 'px'; 
		this.DivContent.style.display = 'block'; 
		return false;
	};

	this.Hide = function(){ 
		this.blnIsActive = false; 

		if( this.m_strBrowser == "Internet Explorer"){
			this.SetScroll(0,this.yPos);
			this.PrepareIe("auto", "auto");
			this.HideSelects("visible");
		}

		this.DivExitLightBox.style.display = 'none';
		this.DivContent.style.display = 'none'; 

		document.cookie="ExitLightBox=yes"
		return false; 
	}; 

	this.FixUpDimensions = function(){ 
		if( typeof( window.innerWidth ) == 'number' ) { 
			this.m_WindowWidth = window.innerWidth; 
			this.m_WindowHeight = window.innerHeight; 
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
			this.m_WindowWidth = document.documentElement.clientWidth; 
			this.m_WindowHeight = document.documentElement.clientHeight; 
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
			this.m_WindowWidth = document.body.clientWidth; 
			this.m_WindowHeight = document.body.clientHeight; 
		} 
		objExitLightBox.XPos = this.m_WindowWidth/2 - objExitLightBox.Width/2; 
		objExitLightBox.YPos = this.m_WindowHeight/2 - objExitLightBox.Height/2 + document.body.scrollTop;

		return false;
	};

	this.MouseButtonListener = function( e)
	{
		if( objExitLightBox.EntryClickMode==0) return true;
		if( this.blnIsActive) return true; 		
		objExitLightBox.Show();
		return true;
	}

	this.MouseListener = function( e)
	{
		if( this.blnIsActive || objExitLightBox.EntryClickMode==1) return true; 

		var intCheckXPos = 0; 
		var intCheckYPos = 0;

		if (!e) var e = window.event; 
		if (e.pageX || e.pageY){ 
			intCheckXPos = e.pageX; 
			intCheckYPos = e.pageY; 
		} else if (e.clientX || e.clientY){ 
			intCheckXPos = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; 
			intCheckYPos = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; 
		} 

		if( intCheckYPos<10+document.body.scrollTop && (intCheckXPos!=-32768 && intCheckYPos!=-32768)){ //fix ie
			if( e.target && ( e.target.tagName.toLowerCase()=='select' || e.target.tagName.toLowerCase()=='option')) //fix ff 
				return true;
				
			objExitLightBox.Show(); 
			return true;
		}
		return true; 
	}; 


	this.Init = function(){		
		this.GetBrowserInfo();
		document.onmousemove = this.MouseListener; 
		document.onmousedown = this.MouseButtonListener; 

		this.DivExitLightBox = document.createElement('div'); 
		this.DivExitLightBox.id = 'ExitLightBox';
		this.DivExitLightBox.className = this.ShadowCssClass

		document.body.appendChild( this.DivExitLightBox); 

		this.DivContent = document.createElement('div'); 
		document.body.appendChild( this.DivContent); 

		this.DivContent.className = this.ContentCssClass

		this.DivContent.style.width = this.Width+'px'; 
		this.DivContent.style.height = this.Height+'px'; 

		this.DivContent.innerHTML = this.HtmlContent		
	}
}

function ExitLightBoxInit(){ objExitLightBox.Init();}

//set to 1 for on demand and check for DoLightBox hidden form value [knguyen/20101029]
function OnLoadLightBoxInit(){ objExitLightBox.Init(); objExitLightBox.Show();}

function HideLightBox(){
	objExitLightBox.Hide();
}














/* --------------Fliqz Part--------------------- */

document.cookie="ExitLightBox=";



var objExitLightBox = new ExitLightBox( 610, 531, 'LightBoxShadow', 'LightBoxInnerContent', '<div class="HC_LB_div"></div>');



objExitLightBox.EntryClickMode=1;



function Open_LB_Vid(LB_id_vid) {


document.cookie="ExitLightBox="
OnLoadLightBoxInit();


objExitLightBox.DivContent.innerHTML='<div align="right" style="width: 610px; z-index: 10000; position: relative; background-color: #ffffff; padding:7px; border: solid 1px #000000;"><a href="javascript:Close_LB_Vid();" style="color:#146232; text-decoration:none;">[X] Close</a><br><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" name="Flash_JF_Vid1" width="610" height="531" id="Flash_JF_Vid1"> <param name="movie" value="http://applications.fliqz.com/3ca7eac242194d189fe0a513a9a6bd31.swf" /> <param name="allowfullscreen" value="true" /> <param name="wmode" value="transparent" /> <param name="allowscriptaccess" value="always" /> <param name="flashvars" value="at='+LB_id_vid+'&amp;permalink=http://www.horsechannel.com/editorial-horse-videos/watch-video-'+LB_id_vid+'.aspx?CategoryList=HorseChannel+Editorial" /> <embed src="http://applications.fliqz.com/3ca7eac242194d189fe0a513a9a6bd31.swf" width="610" height="531" id="emb63f9079f657a42edba34ce0f26d1f0b7" allowfullscreen="true" wmode="transparent" allowscriptaccess="always" flashvars="at='+LB_id_vid+'&amp;permalink=http://www.horsechannel.com/editorial-horse-videos/watch-video-'+LB_id_vid+'.aspx?CategoryList=HorseChannel+Editorial" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" name="Flash_JF_Vid1"></embed></object></div>';


}








function Close_LB_Vid(){
            HideLightBox();
			document.cookie="ExitLightBox=yes";
			objExitLightBox.blnIsActive = 0;
            objExitLightBox.DivContent.innerHTML=''; //override layer content
}
