﻿// Generic Limelight JScript File
var Master =
{
	m_path : "",
	m_theme : "LimeTheme",
	
	Init:function( thepath, thetheme )
	{
		if( typeof thepath !== "undefined" )
			this.m_path = thepath;
		if( typeof thetheme !== "undefined" )
			this.m_theme = thetheme;
	},

	Load:function(  ) 
	{
		var ctrl = $get( "footer");
		if( ctrl != null )
		{
			$clearHandlers( ctrl );
			$addHandler( ctrl, "click", Master.openInfoWindow );
		}
	},
	
	mainMenuHover:function( ) 
	{     
		var elements = document.getElementById("menucontainer").getElementsByTagName("LI");     
		for (var i=0; i<elements.length; i++) 
		{         
			elements[i].onmouseover=function() 
			{ 	Master.hoverMenu(  this, "menuover" );	}         
			elements[i].onmouseout=function() 
			{  Master.unhoverMenu(  this ); }     
		} 
	},
	
	hoverMenu:function(  ctrl, hoverclass )
	{
		ctrl.$oldClass = typeof( ctrl.className ) != 'undefined' ?  ctrl.className : "";
		ctrl.className = ctrl.className + " " + hoverclass;
	},  

	unhoverMenu:function(  ctrl )
	{
		if( typeof( ctrl.$oldClass ) != 'undefined' )
			ctrl.className = ctrl.$oldClass;
	} ,

	hoverColour:function(  ctrl, colour)
	{
		if( typeof ctrl !== "undefined"  )
	   { 
			ctrl.$oldColour = ctrl.style.backgroundColor;
			ctrl.style.backgroundColor = colour;
		}
	} , 

	unhoverColour:function(  ctrl )
	{
		if( typeof ctrl !== "undefined" && ctrl.$oldColour )
			ctrl.style.backgroundColor = ctrl.$oldColour;
	} ,

	stopDefault:function( e )
	{
		if(  e && e.preventDefault )
			e.preventDefault( );
		else
			window.event.returnValue = false;    
		return false;  
	} ,

	stopBubble:function( e )
	{
		if(  e && e.stopPropagation )
			e.stopPropagation( );
		else
			window.event.cancelBubble = true;    
	} ,

	swapImage:function( ctrl, url )
	{
		if( ctrl ) ctrl.src = url;
	},

	setOpacity:function( ctrl, level )
	{
		if( ctrl.filters )
			ctrl.filters.alpha.opacity=level;	
		else
			ctrl.style.opacity = level / 100;
	},

	pageHeight:function( )
	{ 
		if( self.scrollMaxY )
			return Master.viewHeight( ) + self.scrollMaxY;
		return document.body.scrollHeight; 
	},

	pageWidth:function( )
	{ 
		if( self.scrollMaxX )
			return Master.viewWidth( ) + self.scrollMaxX;
		return document.body.scrollWidth; 
	},

	viewHeight:function( )
	{
		var de = document.documentElement;
		return self.innerHeight ||
			(de && de.clientHeight) ||
			document.body.clientHeight;
	},

	viewWidth:function( )
	{
		var de = document.documentElement;
		return self.innerWidth ||
			(de && de.clientWidth) ||
			document.body.clientWidth;
	},

	scrollY:function( )
	{
		var de = document.documentElement;
		return self.pageYOffset || (de && de.scrollTop) || document.body.scrollTop;
	},

	scrollX:function( )
	{
		var de = document.documentElement;
		return self.pageXOffset || (de && de.scrollLeft) ||	document.body.scrollLeft;
	},

	getElementText:function( ctrl )
	{
		ctrl = ctrl.childNodes || ctrl;
		for( var j= 0; j < ctrl.length; j++ )
		{
			if( ctrl[j].nodeType != 1 )
				return ctrl[j].nodeValue;
		}
		return "";
	},

	openPopupWindow:function( e, url, attr )
	{
		window.open(url,'_blank', attr ); 
		return Master.stopDefault( e );
	},

	openInfoWindow:function( eventElement )
	{
		if( eventElement.target.tagName == "A" && eventElement.target.childNodes[1] )
		{
			window.scrollTo( Master.scrollX( ), 0 );
			$get( "bottomcontent").getElementsByTagName("IFRAME")[0].src = Master.m_path + eventElement.target.childNodes[1].getAttribute( "value" );
			return Master.stopDefault( eventElement );
		}
		return true;
	},

	closeInfoWindow:function( e )
	{
		parent.document.getElementById( "bottomcontent").getElementsByTagName("IFRAME")[0].src = "";
		return Master.stopDefault( e );
	},

	// Popup HTML specific functions.
	loadInfoWindow:function( )
	{
		if( parent.document.location.href.indexOf( /Info/ ) >= 0 ) return;
		parent.document.getElementById( "bottomcontent").style.display = "block";
		var ctrln = parent.document.getElementById( "normalcontent" ); 	ctrln.style.display = "none";	
		
		var parentcell = ctrln.parentNode;
		while( parentcell != null && parentcell.nodeName != 'TD' )
				parentcell = parentcell.parentNode;
		if( parentcell != null && parentcell.nodeName == 'TD' )
			parentcell.className = parentcell.className + " themebackground";
	},

	unloadInfoWindow:function( )
	{
		if( parent.document.location.href.indexOf( /Info/ ) >= 0 ) return;
		var ctrln = parent.document.getElementById( "normalcontent" ); 	ctrln.style.display = "block"; 
		parent.document.getElementById( "bottomcontent" ).style.display = "none";

		var parentcell = ctrln.parentNode;
		while( parentcell != null && parentcell.nodeName != 'TD' )
				parentcell = parentcell.parentNode;
		if( parentcell != null && parentcell.nodeName == 'TD' )
			parentcell.className = parentcell.className .replace( / themebackground/, "" );
	},
		
	bookmarksite:function ( )
	{
		if ( window.sidebar )
			window.sidebar.addPanel(document.title,self.location,'')
		else if (window.external) 
			window.external.AddFavorite( location.href, document.title );
	},

	homepagesite:function (ctrl)
	{
		ctrl.style.behavior='url(#default#homepage)'; 
		ctrl.setHomePage('http://www.limelight.co.nz');
	},
	
	showoverlay:function( type )
	{
		if( type == 3 ) Master.lemonman( document, 3, 500, null, 500, 'Limelight is currently processing your request and I will disappear as soon as it is complete' );
		else if( type == 2 ) Master.lemonman( document, 2, 500, null, 500, 'I&#180;m sorry. We were unable to process your request.' );
	},

	hideoverlay:function( )
	{
		Master.closelemonman( document );
	},

	// popup pipy window.
	lemonman:function( source, type, xl, xr, y, text, img )
	{
		var ctrl1 = source.getElementById( "lemonman" );
		var ctrl2 = source.getElementById( "balloon" );
		var ctrl3 = source.getElementById( "speak" );
		var ctrl4 = source.getElementById( "loading" );
		if( ctrl1 == null || ctrl2 == null || ctrl3 == null || ctrl4 == null ) return;

		ctrl1.$type = type;
		ctrl1 .src = Master.m_path + "Images/lemonman1.gif";
		if( type == 1 ) { ctrl2.src = Master.m_path + "Images/balloonlime.gif"; }
		else if( type == 2 ) { ctrl2.src = Master.m_path + "Images/balloonalert.gif"; }
		else if( type == 3 ) { ctrl2.src = Master.m_path + "Images/balloonload.gif"; ctrl4.src = Master.m_path + "Images/loading.gif"; }
		else if( type == 4 ) { ctrl2.src = Master.m_path + "Images/balloonwarn.gif"; text = "<span class='warn'>WARNING  </span>" + text; }
		else if( typeof(img) !== "undfined" ) { ctrl2.src = Master.m_path + img; } 
		ctrl3.innerHTML = text;

		ctrl1.style.top = y + "px";
		ctrl2.style.top = y - 130 + "px";
		ctrl3.style.top = y - 128 + "px";
		ctrl4.style.top = y - 45 + "px";
		if( xl !== null )
		{	xl = Math.max( xl, 260 );
			ctrl1.style.left = xl + "px"; ctrl2.style.left = xl - 260 + "px"; ctrl3.style.left = xl -260 + "px"; ctrl4.style.left = xl -240 + "px";
			ctrl1.style.right = ""; ctrl2.style.right = ""; ctrl3.style.right = ""; ctrl4.style.right = "";	}
		else if( xr !== null )
		{	ctrl1.style.right = xr + "px"; ctrl2.style.right = xr + 50 + "px";  ctrl3.style.right = xr + 50 + "px";  ctrl4.style.right = xr + 350 + "px";
			ctrl1.style.left = ""; ctrl2.style.left = ""; ctrl3.style.left = ""; ctrl4.style.left = "";	}
		ctrl1.style.display = "block";
		ctrl2.style.display = "block";
		ctrl3.style.display = "block";
		if( type == 3 )
			ctrl4.style.display = "block";
		else
			ctrl4.style.display = "none";
	},
	
	clicklemonman:function( e, source )
	{
		var ctrl1 = source.getElementById( "lemonman" );
		if( ctrl1 != null && ctrl1.$type != 3 )
			Master.closelemonman( source );
		return Master.stopDefault( e );
	},
	
	closelemonman:function( source )
	{
		var ctrl1 = source.getElementById( "lemonman" );
		var ctrl2 = source.getElementById( "balloon" );
		var ctrl3 = source.getElementById( "speak" );
		var ctrl4 = source.getElementById( "loading" );
		if( ctrl1 != null ) ctrl1.style.display = "none";	
		if( ctrl2 != null ) ctrl2.style.display = "none";	
		if( ctrl3 != null ) ctrl3.style.display = "none";	
		if( ctrl4 != null ) ctrl4.style.display = "none";	
	}
}

// Notify ScriptManager that this is the end of the script.
if ( typeof(Sys) !== 'undefined' ) Sys.Application.notifyScriptLoaded( );
