// JavaScript Document

IE = false, oldIE = false, AOL = false, SF = false, MZ = false, OP = false;

if( navigator.appName == "Microsoft Internet Explorer" ) {
	IE = true;
	if( navigator.userAgent.indexOf( "AOL" ) >= 0 ) AOL = true;
	if( parseFloat( navigator.userAgent.split( "MSIE" )[ 1 ] ) <= 6 ) oldIE = true;
}
else if( navigator.userAgent.indexOf( "Safari" ) >= 0 )
	SF = true;
else if( navigator.appName == "Netscape" )
	MZ = true;
else if( navigator.appName == "Opera" )
	OP = true;

winOS = ( navigator.platform.substring( 0, 3 ) == "Win" );
winIE = ( winOS && IE );
macOS = ( navigator.platform.substring( 0, 3 ) == "Mac" );
macIE = ( macOS && IE );

theHost = document.location.hostname;

local = ( /^\d+\.\d+\.\d+\.\d+$/.test( theHost ) || theHost == "" || theHost == "localhost" );
// if( theHost = "74.208.97.125" ) local = false; // Activate if remote site is available via an IP address
live = !local;

qStr = unescape( document.location.search ).substring( 1 );

homePage = "index.aspx"
path = document.location.pathname;
delimeter = ( path.indexOf( "\\" ) >= 0 ) ? "\\" : "/";
if( path.charAt( path.length - 1 ) == delimeter ) path += homePage;
Path = path.split( delimeter );
fileName = Path[ Path.length - 1 ];


//////////////////////////////// Start PreLoader: PL ////////////////////////////////

function PreLoader() {

	var Files = new Array();

	Files.push( "Flash/header_v7.swf" );
	
	Files.push( "3DWall.swf" );

	Files.push( "photos.aspx" );
	
	Files.push( "details.aspx" );

	Files.push( "contact.aspx" );

	Files.push( "calendar.html" );
	
	Files.push( "RaveReviews.aspx" );

	this.Files = Files;

	this.debug = 0;
	try {
		if( top.qStr && top.qStr.indexOf( "preloader=show" ) != -1 )
			this.debug = 1;
	}
	catch( Err ) { }

	if( this.debug )
		DeleteCookie( "nFilesCached" );

	this.Request = null;
	this.timer = 0;
	this.nFilesCachedCookie = GetCookie( "nFilesCached" );
	this.nFilesCached = ( this.nFilesCachedCookie ) ? parseInt( this.nFilesCachedCookie ) : 0;
	this.run = run;

	//------------------------------------- Method PL -------------------------------------

	function run() {

		this.Request = getAjaxRequest();

		clearTimeout( PL.timer );

		if( this.Request ) {

			if( this.nFilesCached < this.Files.length ) {

				this.Request.onreadystatechange = function() {
					try {
						if( PL.Request.readyState == 4 ) {
							if( PL.Request.status == 200 || PL.Request.status == 304 ) {
								if( PL.debug )
									top.document.title = PL.Files[ PL.nFilesCached ] + " preloaded; #" + ( ( PL.nFilesCached + 1 ) + " of " + PL.Files.length );
							}
							else {
								if( PL.debug )
									alert( "File preloader encountered an error retrieving: \n " + PL.Files[ PL.nFilesCached ] + "\n Status: " + PL.Request.status + "\n StatusText: " + PL.Request.statusText + "\n Number " + ( ( PL.nFilesCached + 1 ) + " of " + PL.Files.length ) );
							}

							PL.nFilesCached++;
							SetCookie( "nFilesCached", PL.nFilesCached );
							PL.timer = setTimeout( "if( window.PL ) PL.run();", 100 );

						}
					}
					catch( Err ) {
						var eMsg = "Exception at PL.run()\n\n";
						for( var i in Err ) eMsg += i + ": " + Err[ i ] + "\n";
						try{ if( PL.debug ) alert( eMsg ); } catch( Err ) { }
					}
				}

				this.Request.open( "GET", this.Files[ this.nFilesCached ], true );
				this.Request.send( null );

			}
		}

		// Browser cannot make http request
		else if( PL.debug )
			top.document.title = "Browser does not support the HttpRequest Request Protocol";
	}

} PL = new PreLoader();

//////////////////////////////// End PreLoader: PL ////////////////////////////////




///////////////////////////////// BEGIN COOKIE FUNCTIONS /////////////////////////////////

function getCookieDomain() {

	var cookieDomain = null;
	if( live && theHost ) {
		var Host = theHost.split( "." ), hLen = Host.length;
		if( hLen >= 2 )
			cookieDomain = "." + Host[ hLen - 2 ] + "." + Host[ hLen - 1 ];
	}
	return cookieDomain;

}
//--------------- Cookie Library ---------------

function getCookieVal( offset ) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

//--------------- Cookie Library ---------------
function GetCookie( name ) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

//--------------- Cookie Library ---------------
//                  req,  req,   opt
function SetCookie( name, value, expires ) {
	var path = "/", domain = getCookieDomain(), secure = null;
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

//--------------- Cookie Library ---------------
function DeleteCookie( name ) {
	var path = "/", domain = getCookieDomain();
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

//--------------- Cookie Library: String Prototype ---------------
//                       req,  req,       opt
function recordToCookie( key, value, CookieExpDate ) {

	var cookieName = this.toString();
	var data = GetCookie( cookieName ); if( !data ) data = "";

	// In unlikely event user input special delimiters, replace them english definitions
	value = value.toString();
	value = value.replace( /&/g, "and" ).replace( /=/g, "is" );

	// Split old cookie data
	var KeyVals = data.split( "&" );
	var existingKey = 0;

	// Scan old cookie data. If key already exists then update the value it contains
	for( var i = 0; i < KeyVals.length; i++ ) {
		var ThisPair = KeyVals[ i ].split( "=" );
		if( key == ThisPair[ 0 ] ) {
			if( value ) // Set new value
				KeyVals[ i ] = key + "=" + value;
			else // value is empty string so remove this entry
				KeyVals.splice( i, 1 );
			data = KeyVals.join( "&" );
			existingKey = 1;
			break;
		}
	}

	// Otherwise, existing key does not exist so append new key/value pair to end of string
	if( value && !existingKey )
		data += ( ( data ) ? "&" : "" ) + key + "=" + value;

	if( data )
		SetCookie( cookieName, data, ( ( CookieExpDate ) ? CookieExpDate : null ) );
	else
		DeleteCookie ( cookieName );

	// alert( GetCookie( cookieName ) );
}
String.prototype.recordToCookie = recordToCookie;

var expDate12Mon = new Date();
expDate12Mon.setTime ( expDate12Mon.getTime() + ( 24 * 60 * 60 * 365 * 1000 ) ); // 1 year

///////////////////////////////// END COOKIE FUNCTIONS /////////////////////////////////


function getAjaxRequest() {

	var Request = null;

	// W3C
	if( window.XMLHttpRequest ) {
		try { Request = new XMLHttpRequest(); }
		catch( Err ) { Request = null; }
	}

	// IE 6-
	else if( window.ActiveXObject ) {
		try { Request = new ActiveXObject( "Msxml2.XMLHTTP" ); }
		catch( Err ) {
			try { Request = new ActiveXObject( "Microsoft.XMLHTTP" ); }
			catch( Err ) { Request = null; }
		}
	}

	return Request;
}

//////////////////////////////// START HIDE BLANK DATA FIELDS ////////////////////////////////

function hideBlankDataFields() {

	try {
		var SpanTags = document.getElementsByTagName( "span" );

		// Loop all SpanTags on page locating those with the db class. If they contain empty data then locate the parent node and set it's display to none. This action will hide any hard-coded html field names where there is no values for them
		for( var i = 0; i < SpanTags.length; i++ ) {
			if( SpanTags[ i ].className == "xml" ) {
				if( SpanTags[ i ].innerHTML == "" )
					SpanTags[ i ].parentNode.style.display = "none";
			}
		}
		self.status = "";
	}

	catch( Err ) {
		self.status = "Initializing hideBlankDataFields function, one moment please...";
		setTimeout( "hideBlankDataFields();", 250 );
	}
}


//////////////////////////////// PLUS/ MINUS METHOD ///////////////////////////////////
/////////////////////////////// START DYNAMIC INDEX DI ////////////////////////////////

/*

ACCESSOR VARIABLES: fileName
ACCESSOR FUNCTIONS: Cookie
ACCESSOR STYLES: di*, img.diTn, img.diTnOn
*/

//-------------------------------- OBJECT CONSTRUCTOR DI --------------------------------
//                     bool optional
function DynamicIndex( setEvtHandlers ) {

	// Begin User Settings -------------------------
	this.Msg = new Array();
	this.Msg.show = "Show content";
	this.Msg.hide = "Hide content";

	// Do not edit past this line -------------------------
	this.getPlusMinus = getPlusMinus;
	this.onClickMore = onClickMore;
	this.reset = reset;
	this.switchDisplay = switchDisplay;
	this.showTip = showTip;
	this.maintainState = maintainState;
	this.setEventHandlers = setEventHandlers;
	if( setEvtHandlers ) this.setEventHandlers();


	//------------------------------------ METHOD DI ------------------------------------
	// This method to be customized on a per/client basis. It contains additional onClick functionality (if any)

	function onClickMore( Link, evt ) { }
	//------------------------------------ METHOD DI ------------------------------------

	function setEventHandlers() {

		try {
			var AllLinks = document.getElementsByTagName( "a" );
			for ( var i = 0; i < AllLinks.length; i++ ) {

				// Clickable Link
				if( AllLinks[ i ].className == "diHeading" ) {
					AllLinks[ i ].onclick = function( event ) { if( window.DI ) { DI.onClickMore( this, event ); DI.switchDisplay( this ); } }
					AllLinks[ i ].onmouseover = function() { if( window.DI ) DI.showTip( this ); return true; }
				}
				// Plus/Minus Sign
				if( AllLinks[ i ].className == "diPlusMinus" ) {
					AllLinks[ i ].onclick = function( event ) { if( window.DI ) { DI.onClickMore( this.nextSibling, event ); DI.switchDisplay( this.nextSibling ); } }
					AllLinks[ i ].onmouseover = function() { if( window.DI ) DI.showTip( this.nextSibling ); return true; }
				}
			}
			self.status = "";
		}
		catch( Err ) {
			self.status = "Initializing DI.setEventHandlers() method, one moment please...";
			setTimeout( "DI.setEventHandlers();", 250 );
		}

	}


	//------------------------------------ METHOD DI ------------------------------------

	function maintainState() {

		try {
			// Use the file name as cookie name
			var path = document.location.pathname;
			var delimeter = ( path.indexOf( "\\" ) >= 0 ) ? "\\" : "/";
			this.cookieName = fileName.split( "." )[ 0 ];
			var diState = GetCookie( this.cookieName );

			if( diState ) {

				var AllLinks = document.getElementsByTagName( "a" );
				var DiState = diState.split( "_" );

				// Loop all links on page
				for ( var i = 0; i < AllLinks.length; i++ ) {
					for( var k in DiState ) {
						if( DiState[ k ] && parseInt( DiState[ k ] ) == i ) {
							try{ DI.switchDisplay( AllLinks[ i ], AllLinks[ i ].id ) } catch( e ){};
						}
					}
				}
			}
			self.status = "";
		}
		catch( Err ) {
			self.status = "Initializing DI.maintainState() method, one moment please...";
			setTimeout( "DI.maintainState();", 250 );
		}
	}

	//------------------------------------ METHOD DI ------------------------------------

	function getPlusMinus( Link ) { return Link.previousSibling; }

	//------------------------------------ METHOD DI ------------------------------------

	function reset( OtherID ) {
		for( var i = 0; i < OtherID.length; i++ ) {
			var PlusMinus = document.getElementById( "plusMinus_" + OtherID[ i ] );
			if( PlusMinus ) {
				PlusMinus.innerHTML = "-";
				this.switchDisplay( null, OtherID[ i ] );
			}
			else {
				alert( "ERROR: DI.reset unable to initialize PlusMinus as an Object.\nPROBLEM: \"plusMinus_" + OtherID[ i ] + "\" cannot be found." );
				return;
			}
		}
	}
	//------------------------------------ METHOD DI ------------------------------------

	function switchDisplay( Link, contentID, focuserID ) {

		if( !Link ) Link = document.getElementById( contentID );
		var PlusMinus = getPlusMinus( Link );
		var expanding = ( PlusMinus.innerHTML == "+" ), contracting = !expanding;

		// It there is a photo caption then activate it
		var Caption = document.getElementById( "caption_" + Link.id );
		if( Caption)
			Caption.className = ( expanding ) ? "diCaptionOn" : "diCaptionOff";

		// It there is an image then activate it
		var Img = document.getElementById( "img_" + Link.id );
		if( Img )
			Img.className = ( expanding ) ? "diTnOn" : "diTn";

		PlusMinus.innerHTML = ( expanding ) ? "-" : "+";

		var AllLinks = document.getElementsByTagName( "a" );

		var valOld = GetCookie( this.cookieName ), valNew = "";

		// Record State; loop all links on page
		for ( var i = 0; i < AllLinks.length; i++ ) {

			// Found link just clicked
			if( AllLinks[ i ] == Link ) {
				// Existing cookie present
				if( valOld ) {
					var key = "_" + i + "_";
					// this i value already recorded
					if( valOld.indexOf( key ) >= 0 ) {
						// Remove this entry
						if( contracting ) {
							var ValOld = valOld.split( key );
							valNew = ( ( ValOld[ 0 ] ) ? ValOld[ 0 ] : "" ) + "_" + ( ( ValOld[ 1 ] ) ? ValOld[ 1 ] : "" );
							( valNew == "_" ) ? DeleteCookie( this.cookieName ) : SetCookie( this.cookieName, valNew );
						}
						break;
					}
					if( expanding ) valNew = valOld + i + "_";
				}
				else if( expanding ) // First expansion; no cookie set
					valNew = "_" + i + "_";

				if( valNew )
					SetCookie( this.cookieName, valNew );
				break;
			}
		}

		if( contentID )
			var Content = document.getElementById( "content_" + contentID );
		else
			var Content = ( Link.parentNode.nextSibling.style ) ? Link.parentNode.nextSibling : Link.parentNode.nextSibling.nextSibling;

		try{
			Content.style.display = ( contracting ) ? "none" : "block";
		}
		catch( Err ) {
			var problem = ( contentID ) ? "\nPROBLEM: \"content_" + contentID + "\" cannot be found." : "";
			alert( "ERROR: DI.switchDisplay unable to initialize Content as an Object." + problem );
		}

		if( focuserID && expanding ) {
			var FocusCont = document.getElementById( focuserID );
			FocusCont.innerHTML = "<a href='javascript:void(0);'>.</a>";
			var FocusLink = FocusCont.firstChild;
			FocusLink.focus();
			Link.focus();
			FocusCont.innerHTML = "";
		}
		showTip( Link );

	}

	//------------------------------------ METHOD DI ------------------------------------

	function showTip( Link, msgOn, msgOff ) {

		var PlusMinus = getPlusMinus( Link );

		if( PlusMinus.innerHTML == "+" ) {
			Link.title = ( msgOn ) ? msgOn : DI.Msg.show;
			PlusMinus.title = ( msgOn ) ? msgOn : DI.Msg.show;
		}
		else {
			Link.title = ( msgOff ) ? msgOff : DI.Msg.hide;
			PlusMinus.title = ( msgOff ) ? msgOff : DI.Msg.hide;
		}

	}

} //////////////////////////////// END DYNAMIC DI ////////////////////////////////