//Build Number:318
//Build Date:2010-07-28 13:10
//Build Stamp:1280337034
//Build Config:mods=site:_xx_siteStuff:_xx_nav:_xx_options:_xx_slideShow



/** _xx module **/

// Copyright (c) 2006 Jimbo
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



globalBubbleNudge = false; //Because its cool
globalMessage = false; // error/notice handler for system messages

var XX = {}; //XX framework Class


/***************************************************/
// shows a help bubble
function displayBubble( ev, eId , wid, hei, dir, useNudge){
	
	
	//Return if we can't find it
	if( ! $(eId)){ return true; }

	//Bubble Object
	bubbleObj = $(eId);
	
	//
	useNudge = useNudge || true;
	
	//Mouse XY axis
	mouseX = (Event.pointerX(ev) + 20);
	mouseY = (Event.pointerY(ev) - 10);

	//If this is loaded in an Ajax container then we need to do some extra stuff for positioning
	if( globalBubbleNudge && useNudge != false && useNudge != "false") {
		offset = Position.cumulativeOffset($(globalBubbleNudge));
		mouseX = ( mouseX - offset[0]);
		mouseY = ( mouseY - offset[1]);

	}
	
	//Set width
	if( wid ) { bubbleObj.style.width = wid+"px"; }
	
	//Set Height
	if( hei ){ bubbleObj.style.height = hei+"px"; }
	
	
	//direction position
	if( dir == "left" ) {
		//Bubble Dimensions
		mouseX = mouseX - wid - 70;
	}
	
	// Position X Y
	bubbleObj.style.left = mouseX+"px";
	bubbleObj.style.top = mouseY+"px";
	
	
	//Show bubble
	//bubbleObj.style.position = "absolute";
	bubbleObj.style.display = "block";
}


/***************************************************/
//hides a help bubble
function killBubble( oid ){
	if( !$(oid) ) { return true; }
	Element.hide(oid);
}


/***************************************************/
//Gui Phone
function phone_form_update( objId, del ){
	
	//Delimeter
	del = del || "-";

	//Phone hidden field
	if ( hiddenObj = $(objId)) {
		hiddenObj.value = $F(objId+"_a") + del + $F(objId+"_b") + del + $F(objId+"_c");
	}
	
}


/***************************************************/
//Gui Dates
function date_form_update( objId, del ){
	
	//Delimeter
	del = del || "-";

	//Phone hidden field
	if ( hiddenObj = $(objId)) {
		hiddenObj.value = $F(objId+"_a") + del + $F(objId+"_b") + del + $F(objId+"_c");
	}
	
}


function update_dateform_value( objId ){


	//Hidden Field
	if( hiddenObj = $(objId) ){
		
		//Date TIME mode
		if( $(objId+"_ampm") ) {
		
			if( $F(objId+"_hour") == '12' ) {
				if( $F(objId+"_ampm") == 'am' ) { selectedHour = 0; }
				else { selectedHour = 12; }
			}
			else{
				if( $F(objId+"_ampm") == 'pm' ) {
					selectedHour = Number($F(objId+"_hour")) + 12;
				} else {
					selectedHour = $F(objId+"_hour");
				}
			}

			//Hidden Value
			hiddenObj.value = $F(objId+"_year") + "-" + $F(objId+"_month") + "-" + $F(objId+"_day") + " "+selectedHour+ ":" + $F(objId+"_minute") +":00";
		
			return true;
		}
		
		//Date Mode
		if( $(objId+"_day") ) {
			
			//Hidden Value
			hiddenObj.value = $F(objId+"_year") + "-" + $F(objId+"_month") + "-" + $F(objId+"_day") ;
			
			return true;
		}
		
		//Otherwise we are in just year month mode

		//Hidden Value
		hiddenObj.value = $F(objId+"_year") + "-" + $F(objId+"_month");
			
	}	
	
	return true;
}


/***************************************************/
//Loading Dialog
function initLoadingDialog( dialogId, doEffect ) {
	
	//Check to see if loadingId exists
	if( ! ($(dialogId))) {
		return false;
	}
	
	//Do effect settings
	doEffect = doEffect || true; 
	XX.loadingEffectTimer = false;
	
	//Set loadingEffect 
	loadingEffect = false;
	
	//After finish function for effect
	//effectFinishFunction = new Function("if( Element.visible('"+dialogId+"')){ new Effect.Pulsate('"+dialogId+"');}");
	
	
	//Responder Options
	responderOpts = {
		
		//Start Loading
		onCreate : function(){ 
			
			//Cancel Closer
			if( XX.loadingEffectTimer ) {
				clearTimeout(XX.loadingEffectTimer);
				XX.loadingEffectTimer = false;
				//XX.loadingEffect.cancel();
				XX.loadingEffect = new Effect.Pulsate( dialogId);
			}

			//Check to see if loader is visible
			if( ! Element.visible(dialogId) ) {
				//Show dialog
				Element.show(dialogId);
				//Assign Effect
				if ( doEffect == true ) { 
					XX.loadingEffect = new Effect.Pulsate( dialogId );
				} else {
					XX.loadingEffect = Element.Show( dialogId );
				}

			}
		},
			
		//Finish Loading
		onComplete : function(){ 
			if(Ajax.activeRequestCount == 0){
				//Set timeout
				//XX.loadingEffectTimer = window.setTimeout("Element.hide('"+dialogId+"'); XX.loadingEffect.cancel();", 200);	
				//XX.loadingEffectTimer = window.setTimeout("Element.hide('"+dialogId+"');", 200);	
				Element.hide(dialogId);
			}
		}
	}
	
	//Assign Responder
	Ajax.Responders.register(responderOpts); 
	return true;
}




/** _xx_nav module **/


//Nav Class
XX.nav = Class.create();

XX.nav.prototype = {
	
	/*********************************/
	//Constructor
	initialize: function( opts ){
		
		//Options
		opts = opts || {};
		
		//Set properties
		this.navName = opts.navName ? opts.navName : "xxNav";
		this.objectName = this.navName;
		this.cmsName = opts.cmsName ? opts.cmsName : false;
		this.startupUrl = opts.startupUrl ? opts.startupUrl : false; //Startup url. If this value is present then it will be loaded immeditly.
		this.loadPageHandler = opts.loadPageHandler ? opts.loadPageHandler : false; //This will be used to override the cms.loadPage function if it esists
		this.resources = opts.resources ? opts.resources : "/js/resources";
		this.dataType = opts.dataType ? opts.dataType : "remote" ; // either local, remote
		this.dataUrl = opts.dataUrl ? opts.dataUrl : false; //url of where to get XML data
		this.dataString = opts.dataString ? opts.dataString : false; //XML string
		//this.recordsPerRequest = opts.recordsPerRequest ? opts.recordsPerRequest : 50; //How many remote records we should return at a time
		//this.detailsCache = {}; //Holds the details.. # records etc..
		//this.dataCache = {}; //Records Cache
		this.currentSet = opts.currentSet ? opts.currentSet : false; //The current set we are viewing
		this.gotoSet = opts.gotoSet ? opts.gotoSet : 0; //The set that we want to view
		this.itemsPerSet = opts.itemsPerSet ? opts.itemsPerSet : 15;
		this.addUrl = opts.addUrl ? opts.addUrl : false; //Location of add form
		this.optionsPageNudgeX = opts.optionsPageNudgeX ? opts.optionsPageNudgeX : 0; //Nudge the options page X
		this.optionsPageNudgeY = opts.optionsPageNudgeY ? opts.optionsPageNudgeY : 0; //Nudge the options page Y
		this.optionsPageToggleEffect = opts.optionsPageToggleEffect ? opts.optionsPageToggleEffect : false; //Nudge the options page Y
		this.scrollAfterInject = opts.scrollAfterInject ? opts.scrollAfterInject : false;
		this.optionsPagePositioned = false;
		this.requestLoad = false; //This is where the ajax request will be held
		this.requestDetails = {}; //This is where the ajax request will be held
		this.afterNav = opts.afterNav ? opts.afterNav : false; //method to call after nav has completed
		

		//Create a config options container to hold values later
		this.config = new XX.options(opts.navName, {});
		
		//Startup Url if available.
		if( this.startupUrl ) {
			this.gotoUrl(this.startupUrl);
			return true;
		}
		
		
		//Setup UI
		this.setupUi();
		
		//Items per set
		this.config.setOption("itemsPerSet", this.itemsPerSet);

		//Get our data
		this.reloadData( true );

	},
	

	/*********************************/
	loadSet : function() {
		
		//If there is already a request going then bail out
		if( this.requestLoad != false ){ return true; } 
		
		//Process our filters
		this.navFilters();
		
		//Also save our data sets
		this.config.setOption("gotoSet", this.gotoSet);
		
		
		//Function to execute when done
		completeFunc = new Function(this.objectName+".injectHtml();");

		//Do Ajax Request
		this.requestLoad = new Ajax.Updater("", this.dataUrl, {
			//onFailure: failFunc ,
			onComplete: completeFunc ,
			evalScripts:true, 
			asynchronous:true
		});
		


	},
	
	
	/*********************************/
	injectHtml : function() {
		
		//Inject source into document
		Element.update( this.objectName+"Records", this.requestLoad.transport.responseText);
		
		//Reset a scroll in case it is a little off
		 if( this.scrollAfterInject ) {
				scrollY = this.scrollAfterInject.scrollY || 0;
		
			//Return if nothing
			if( ! $(this.scrollAfterInject.objectName) ){ return true; }

			//Scroll It
			$(this.scrollAfterInject.objectName).scrollTop = scrollY;
		 }
		
		//reset this request
		this.requestLoad = false;
		
		//afterNav method
		if( this.afterNav ) {
			eval(this.afterNav);
		}
		
	},
	
	
	
	/*********************************/
	reloadData : function( loader ) {
		loader = loader || false;
		
		
		//If there is already a request going then bail out
		if( this.requestLoad != false ){ return true; } 

		//Process our filters
		this.currentSet = false;

		if( !loader ) {
			this.gotoSet = 0;
		}

		//Get new data
		this.loadSet();
		
	},


	/*********************************/
	//Updates our config with form values
	navFilters : function() {
		
		//Get the filters form
		this.formObjHandle = $(this.navName+"FormOptions");
		if( ! this.formObjHandle ){ return true; }
		

		
		//Get all the form elements
		var filters = false;
		var filters = new Form.getElements( this.navName+"FormOptions");
		if( filters.length > 0 ) {
			
			var opts = false;
			var opts = {};
			
			r = "";
			//Build up form values
			for( var i = 0; i < filters.length; i++ ) { 

				//If element is a submit button then skip it
				if( filters[i].type == "button" ){ continue; }
				
				//If element does not have an id then skip it
				if( ! filters[i].id ){ continue; }
				
				//To avoid namespace collision we need to pop the unique navName off the front before we store this value
				idxName = filters[i].id.split(this.navName+"_");
				opts[idxName[1]] = $F(filters[i].id); 
			}

			
			//Update our save config
			this.config.setOption(opts);
		}
	},


	/*********************************/
	// Move to a set of records
	gotoSetNum : function ( num ) {
		this.gotoSet = num;
		this.loadSet();
	},
	
	/*********************************/
	// Navigate to a page
	gotoUrl : function ( urlP, eId ) {
		eId = eId || "";
		
		//If there is a custom loadPageHandler then use it
		if( this.loadPageHandler ) {

			//Load page with our loadPageHandler control
			f = this.loadPageHandler+".loadPage('"+eId+"', '"+urlP+"');";
			//evaluate the function
			eval(f);
			
		}
		
		//If there is a CMS then open it in the cms page
		else if( this.cmsName ) {
			
			//Load page with our CMS control
			f = this.cmsName+".loadPage('"+eId+"', {output:'html', url:'"+urlP+"'});";

			//evaluate the function
			eval(f); 
			
		} else {
			//Else just go there
			window.location = ""+url+"";
		}
		
	},
	
	
	/*********************************/
	// setup Ui elements, give buttons actions
	setupUi : function ( ) {
		
		//Back Button
		if ( btnObj = $(this.navName+"ButtonBack")) {
			btnObj.onmousedown = new Function("Element.addClassName('"+this.navName+"ButtonBack', 'navButtonClicked');");
			btnObj.onmouseover = new Function("Element.addClassName('"+this.navName+"ButtonBack', 'navButtonHover');");
			btnObj.onmouseup = new Function("Element.removeClassName('"+this.navName+"ButtonBack', 'navButtonClicked'); this.blur();");
			btnObj.onmouseout = new Function("Element.removeClassName('"+this.navName+"ButtonBack', 'navButtonHover'); Element.removeClassName('"+this.navName+"ButtonBack', 'navButtonClicked'); this.blur();");
		}
		
		//Next Button 
		if ( btnObj = $(this.navName+"ButtonNext")) {
			btnObj.onmousedown = new Function("Element.addClassName('"+this.navName+"ButtonNext', 'navButtonClicked');");
			btnObj.onmouseover = new Function("Element.addClassName('"+this.navName+"ButtonNext', 'navButtonHover');");
			btnObj.onmouseup = new Function("Element.removeClassName('"+this.navName+"ButtonNext', 'navButtonClicked');  this.blur();");
			btnObj.onmouseout = new Function("Element.removeClassName('"+this.navName+"ButtonNext', 'navButtonHover'); Element.removeClassName('"+this.navName+"ButtonNext', 'navButtonClicked');  this.blur();");
		}

		//Back Button FOOTER
		if ( btnObj = $(this.navName+"ButtonBackFooter")) {
			btnObj.onmousedown = new Function("Element.addClassName('"+this.navName+"ButtonBackFooter', 'navButtonClicked');");
			btnObj.onmouseover = new Function("Element.addClassName('"+this.navName+"ButtonBackFooter', 'navButtonHover');");
			btnObj.onmouseup = new Function("Element.removeClassName('"+this.navName+"ButtonBackFooter', 'navButtonClicked'); this.blur();");
			btnObj.onmouseout = new Function("Element.removeClassName('"+this.navName+"ButtonBackFooter', 'navButtonHover'); Element.removeClassName('"+this.navName+"ButtonBackFooter', 'navButtonClicked'); this.blur();");
		}
		
		//Next Button FOOTER
		if ( btnObj = $(this.navName+"ButtonNextFooter")) {
			btnObj.onmousedown = new Function("Element.addClassName('"+this.navName+"ButtonNextFooter', 'navButtonClicked');");
			btnObj.onmouseover = new Function("Element.addClassName('"+this.navName+"ButtonNextFooter', 'navButtonHover');");
			btnObj.onmouseup = new Function("Element.removeClassName('"+this.navName+"ButtonNextFooter', 'navButtonClicked');  this.blur();");
			btnObj.onmouseout = new Function("Element.removeClassName('"+this.navName+"ButtonNextFooter', 'navButtonHover'); Element.removeClassName('"+this.navName+"ButtonNextFooter', 'navButtonClicked');  this.blur();");
		}
		
		//Add Button
		if ( btnObj = $(this.navName+"ButtonAdd")) {
			btnObj.onclick = new Function(this.objectName+".gotoUrl('"+this.addUrl+"');");
			btnObj.onmousedown = new Function("Element.addClassName('"+this.navName+"ButtonAdd', 'navButtonClicked');");
			btnObj.onmouseover = new Function("Element.addClassName('"+this.navName+"ButtonAdd', 'navButtonHover');");
			btnObj.onmouseup = new Function("Element.removeClassName('"+this.navName+"ButtonAdd', 'navButtonClicked');  this.blur();");
			btnObj.onmouseout = new Function("Element.removeClassName('"+this.navName+"ButtonAdd', 'navButtonHover'); Element.removeClassName('"+this.navName+"ButtonAdd', 'navButtonClicked');  this.blur();");
		}
		
		//Options Button
		if ( btnObj = $(this.navName+"ButtonOptions")) {
			btnObj.onclick = new Function(this.objectName+".toggleOptions();");
			btnObj.onmousedown = new Function("Element.addClassName('"+this.navName+"ButtonOptions', 'navButtonClicked');");
			btnObj.onmouseover = new Function("Element.addClassName('"+this.navName+"ButtonOptions', 'navButtonHover');");
			btnObj.onmouseup = new Function("Element.removeClassName('"+this.navName+"ButtonOptions', 'navButtonClicked');  this.blur();");
			btnObj.onmouseout = new Function("Element.removeClassName('"+this.navName+"ButtonOptions', 'navButtonHover'); Element.removeClassName('"+this.navName+"ButtonOptions', 'navButtonClicked');  this.blur();");
		}
		
		//Options Cancel Button
		if ( btnObj = $(this.navName+"ButtonOptionsCancel")) {
			btnObj.onclick = new Function(this.objectName+".toggleOptions();");
			btnObj.onmousedown = new Function("Element.addClassName('"+this.navName+"ButtonOptionsCancel', 'navButtonClicked');");
			btnObj.onmouseover = new Function("Element.addClassName('"+this.navName+"ButtonOptionsCancel', 'navButtonHover');");
			btnObj.onmouseup = new Function("Element.removeClassName('"+this.navName+"ButtonOptionsCancels', 'navButtonClicked');  this.blur();");
			btnObj.onmouseout = new Function("Element.removeClassName('"+this.navName+"ButtonOptionsCancel', 'navButtonHover'); Element.removeClassName('"+this.navName+"ButtonOptionsCancel', 'navButtonClicked');  this.blur();");
		}
		
		//Options Submit Button
		if ( btnObj = $(this.navName+"ButtonOptionsSubmit")) {
			btnObj.onclick = new Function(this.objectName+".reloadData(); "+this.objectName+".toggleOptions();");
			btnObj.onmousedown = new Function("Element.addClassName('"+this.navName+"ButtonOptionsSubmit', 'navButtonClicked');");
			btnObj.onmouseover = new Function("Element.addClassName('"+this.navName+"ButtonOptionsSubmit', 'navButtonHover');");
			btnObj.onmouseup = new Function("Element.removeClassName('"+this.navName+"ButtonOptionsSubmit', 'navButtonClicked');  this.blur();");
			btnObj.onmouseout = new Function("Element.removeClassName('"+this.navName+"ButtonOptionsSubmit', 'navButtonHover'); Element.removeClassName('"+this.navName+"ButtonOptionsSubmit', 'navButtonClicked');  this.blur();");
		}
		
		//options form onsubmit
		if ( formObj = $(this.navName+"FormOptions")) {
			formObj.onsubmit = new Function(this.objectName+".reloadData(); "+this.objectName+".toggleOptions();" + " return false;");
		}
		
		
	},
	
	
	/*********************************/
	// Updates our display after a request has been made
	updateUi : function ( ) {
		
		//Show record position
		if( this.requestDetails.numRecords > 0 ) {
			txtHeader = "Viewing "+this.requestDetails.setStartNumber+"-"+this.requestDetails.setEndNumber+" ("+this.requestDetails.numRecords+")";
		} else { 
			txtHeader = "0 Items";
		}
		
		Element.update(this.objectName+"TextHeader", txtHeader);

		//Text FOOTER
		if( $(this.navName+"TextFooter") && this.requestDetails.numRecords > 0 ) {
			Element.update(this.objectName+"TextFooter", txtHeader);
		}

		
		//Next Button
		if( this.requestDetails.numRecords != 0  && this.requestDetails.setEndNumber < this.requestDetails.numRecords ) {
			//Show button
			Element.show($(this.navName+"ButtonNext"));
			$(this.navName+"ButtonNext").onclick = new Function(this.objectName+".gotoSetNum("+(this.requestDetails.currentSet + 1)+");");

			//Show button FOOTER
			if( $(this.navName+"ButtonNextFooter") ) {
				Element.show($(this.navName+"ButtonNextFooter"));
				$(this.navName+"ButtonNextFooter").onclick = new Function(this.objectName+".gotoSetNum("+(this.requestDetails.currentSet + 1)+");");
			}
		} else {
			//Hide Button
			$(this.navName+"ButtonNext").onclick = new Function("");
			Element.hide($(this.navName+"ButtonNext"));

			//Hide Button FOOTER
			if( $(this.navName+"ButtonNextFooter") ) {
				$(this.navName+"ButtonNextFooter").onclick = new Function("");
				Element.hide($(this.navName+"ButtonNextFooter"));
			}
		}
		


		//Back Button
		if( this.requestDetails.currentSet > 0 ) {
			//Show button
			Element.show($(this.navName+"ButtonBack"));
			$(this.navName+"ButtonBack").onclick = new Function(this.objectName+".gotoSetNum("+(this.requestDetails.currentSet - 1)+");");

			//Show button FOOTER
			if( $(this.navName+"ButtonBackFooter") ) {
				Element.show($(this.navName+"ButtonBackFooter"));
				$(this.navName+"ButtonBackFooter").onclick = new Function(this.objectName+".gotoSetNum("+(this.requestDetails.currentSet - 1)+");");
			}

		} else {
			//Hide button
			$(this.navName+"ButtonBack").onclick = new Function("");
			Element.hide($(this.navName+"ButtonBack"));

			//Hide button FOOTER
			if( $(this.navName+"ButtonBackFooter") ) {
				$(this.navName+"ButtonBackFooter").onclick = new Function("");
				Element.hide($(this.navName+"ButtonBackFooter"));
			}
		}

		
		
	},
	

	/*********************************/
	//Show / Hide options page
	toggleOptions : function() {
		

		if( ! this.optionsPagePositioned ) {
			//Objects Elements
			this.optionsBtnHandle = $(this.navName+"ButtonOptions");
			this.optionsPageHandle = $(this.navName+"OptionsPage");

			//Offsets
			Position.prepare();
			btnOffset = Position.cumulativeOffset(this.optionsBtnHandle);
			pageOffset = Position.cumulativeOffset(this.optionsPageHandle);

			
			//If this is loaded in the CMS then we need to do some extra stuff for positioning
			if( this.cmsName ) {
				f = "p ="+this.cmsName+".currentPage();";
				eval(f);
				navOffset = Position.cumulativeOffset($(p+"Page"));
				btnOffset[0] = ( btnOffset[0] - navOffset[0]);
				btnOffset[1] = ( btnOffset[1] - navOffset[1]);
			}

		
			//Dimmensions
			Position.prepare();
			btnDim = Element.getDimensions(this.optionsBtnHandle);
			pageDim = Element.getDimensions(this.optionsPageHandle);
		
		
			//Position the Options Page 
			this.optionsPageHandle.style.left = ( ( btnOffset[0] + btnDim.width) - pageDim.width + this.optionsPageNudgeX )+"px";
			this.optionsPageHandle.style.top = ( ( btnOffset[1] + btnDim.height) + this.optionsPageNudgeY )+"px";
			
			//set options page as positioned so we don't have to do it anymore
			this.optionsPagePositioned = true;
		}

		
		//Toggle page via effect or plain toggle
		if( this.optionsPageToggleEffect ) {
			//Duration string
			durStr = this.optionsPageToggleEffect.duration ? "duration:"+this.optionsPageToggleEffect.duration : "";

			if( this.optionsPageHandle.style.display != "none" ) {
				//Page is open.. so lets close it
				eval("Effect."+this.optionsPageToggleEffect.hide+"("+this.navName+".optionsPageHandle, {"+durStr+"});");
			} else {
				//Page is closed.. so lets open it
				eval("Effect."+this.optionsPageToggleEffect.show+"("+this.navName+".optionsPageHandle, {"+durStr+"});");
				
			}

		} else {
			//Toggle element with plain hide/show 
			Element.toggle(this.optionsPageHandle);
		}
		
	},


	/*********************************/
	//Send message to cms dialog if we have it loaded
	message : function( msg ) {
		if( ! this.cmsName ) { return true; }
		eval( this.cmsName +".message('"+msg+"');");
		//this.cmsName.message( msg );
		
	
	}
	
	
	
}	



/** _xx_options module **/


//Options Container Class
XX.options = Class.create();

XX.options.prototype = {
	
	/*********************************/
	initialize: function( cookieName, options ){
		//Set the cookie name that stores our XML string
		this.cookieName = cookieName;
		this.optionsXml = false;
		this.options = {};

		// Explode all the cookies
		cookieAr = new String(document.cookie).split("; ");
		
		//Loop through the cookies to see if our options cookie exists
		if( cookieAr.length != 0 ) {
			for(c=0; c < cookieAr.length; c++ ){
				crumbAr = new String(cookieAr[c]).split("=");
				//Import this cookie
				if( new String(crumbAr[0]).search(this.cookieName) != -1 ){ 
					this.optionsXml = unescape(crumbAr[1]);
					this._xml2obj();
					return true;
				}
			}
		}
		
		// If the cookie is not set yet, set it using the passed default options
		this.options = options || { defaultOption:"default Value 1" };
		
		this._saveOptions();
	},
	

	/*********************************/
	//destroy object
	destroy : function( ) {
		
		//Expire Cookie
		dater = new Date();
		dater.setDate(dater.getDate()-4);
		document.cookie = ""+this.cookieName+" = 0; expires="+ dater.toGMTString();

		this.cookieName = false;
		this.optionsXml = false;
		this.options = false;
	},
	

	/*********************************/
	//Return an option
	getOption : function( opt ){
		if( opt.length != 0 ) {
			if( ! this.options[opt] ) { return false; }
			return this.options[opt];
		}
		return this.options;
	},
	
	
	/*********************************/
	//Set an option
	setOption : function( opt, value ) {
		
		opt = opt || false;
		
		//Return if no opt is passed
		if( ! opt ) { return false; }
		
		//If opt string then set the option
		if( typeof opt == "string" ) {
			this.options[opt] = value;
			this._saveOptions();
		} else if( typeof opt == "object" ) {
			//If opt is object then loop and set values
			for( var val in opt ) {
				this.options[val] = opt[val];
			}
			this._saveOptions();
		}
	},
	
	
	/*********************************/
	//Saves the options to a session cookie
	_saveOptions : function ( ) {
		
		//Update the optionsXml value
		this.optionsXml = Sarissa.xmlize(this.options, this.cookieName);
		
		//Write Cookie
		document.cookie = ""+this.cookieName+"=" +escape(this.optionsXml)+";";
	},

	
	/*********************************/
	//Internal method. Transforms this.optionsXml -> this.options (object)
	_xml2obj : function( )  {
		if( ! this.optionsXml ) { return false; }
		
		//Get our options xmlObj
		var optionsObj = (new DOMParser()).parseFromString(this.optionsXml, "text/xml").getElementsByTagName(this.cookieName);
		
		//Loop the XML and build object
		for( var i =0; i < optionsObj[0].childNodes.length; i++ ) {
			if( optionsObj[0].childNodes[i].nodeType != 1 ) { continue; }
			if( ! optionsObj[0].childNodes[i].childNodes[0] ) {
				this.options[optionsObj[0].childNodes[i].nodeName] = "";
			} else {
				this.options[optionsObj[0].childNodes[i].nodeName] = optionsObj[0].childNodes[i].childNodes[0].nodeValue;
			}
		}
	},
	


	/*********************************/
	//Prints all the options
	dump : function() {
		if( ! this.cookieName ) { return false; }
		var ret = "";
		ret += "[cookieName]="+this.cookieName+"\n\n";
		ret += "[options]=\n";
		for (var val in this.options ) {ret += val+":"+this.options[val]+"\n"; }
		ret +="\n";
		ret += "[optionsXml]=\n"+ this.optionsXml +"\n\n";
		return ret;
	}
	
}	





/** _xx_siteStuff module **/

//Generic Site helpers class
XX.siteStuff = Class.create();

XX.siteStuff.prototype = {
	/*********************************/
	//Constructor
	initialize: function( opts ){
		
		opts = opts || {};

		//General Options
		this.debug = false;
		this.objectName = opts.objectName ? opts.objectName : "xxSiteStuff";
		
		// Options for page loading stuff
		this.defaultPageLoader = opts.defaultPageLoader ? opts.defaultPageLoader : false; //Hard code the element id to use for loading pages into
		this.defaultPageUrl = opts.defaultPageUrl ? opts.defaultPageUrl : false; //If defined this page will loadup when this object inits
		this.currentEleId = opts.currentEleId ? opts.currentEleId : false; //If defined this page will loadup when this object inits
		this.pageLoaders = {}; //Container to hold the states of our elements
		this.toggleEffects = opts.toggleEffects ? opts.toggleEffects : false;
		this.resetScrollOnLoad = opts.resetScrollOnLoad ? opts.resetScrollOnLoad : true; // Sets the scrollBar back to 0px
		
		//Message Settings
 		this.msgHandler = opts.msgHandler ? opts.msgHandler : false; //Pointer to a predefined message Handler
		this.messageAutoClose = opts.messageAutoClose ? opts.messageAutoClose : 5000; //MS how long the message window remains open
		this.messageElement = opts.messageElement ? opts.messageElement : this.objectName+"Message"; // id of message window
		this.messageResources = opts.messageResources ? opts.messageResources : "./";
		this.messageNudgeX = opts.messageNudgeX ? opts.messageNudgeX : false;
		this.messageNudgeY = opts.messageNudgeY ? opts.messageNudgeY : false;

		
		// Preload Images
		this.cImgs = opts.cImgs ? opts.cImgs : false;
		
		
		// Load up a page
		if( this.defaultPageUrl ) {
			this.loadPage( this.defaultPageLoader, this.defaultPageUrl );
		}
		
		// Load up images
		if( this.cImgs ) {
			this.cacheImages( this.cImgs );
		}
		
		
	},


	
	/*********************************/
	showPage: function( eId ){

		//Return if it is already open
		if( this.pageLoaders[eId].state == "open" ) { return true; }
		
		//If page is loaded but closed then show it.
		if( this.pageLoaders[eId].status == "loaded") {

			//Now open the page ..
			Effect.Appear(eId);
			//Element.show(eId);
			this.pageLoaders[eId].status = "ready";
		}
		
		//Set our thing
		this.pageLoaders[eId].state = "open";
		
		
	},

	
	/*********************************/
	// Hide open page(s)
	hidePage: function( eId ){
		
		//Return if it is already closed
		//if( this.pageLoaders[eId].state == "closed" ) { return true; }

		//Now close the page
		//Effect.Fade(eId);

		//Set our thing
		//this.pageLoaders[eId].state = "closed";
		
		//Show the page now if it is already injected
		//if( this.pageLoaders[eId].loaded == "yes" ) {			this.injectHtml(eId);		}
		
		
	},

	
	/*********************************/
	loadPage: function( eId, url ){
		
		//Set to default ElementId If None was given
		eId = eId || this.defaultPageLoader;
		
		//If there is still none then just exit
		eObj = $(eId);
		if( ! eObj ) { return false; }
		
		//Create new state
		if( ! this.pageLoaders[eId] ) {
			this.pageLoaders[eId] = { state:'closed', status:'ready', loadingError:false };
		}

		
		//If this thing is not ready to load a new page then just return
		if( this.pageLoaders[eId].status != "ready" ) { return true; }
		
		
		this.pageLoaders[eId].status = "busy";
		this.pageLoaders[eId].url = url;
		
		//Reset scollBar
		if( this.resetScrollOnLoad ) {
			this.scrollPix();
		}
		
		//Close Page if open
		if( this.pageLoaders[eId].state == "open" ){
			Element.hide(eId);
			this.pageLoaders[eId].state = "closed";
		}
		
		//Do Ajax Request
		this.pageLoaders[eId].request = new Ajax.Updater("", url, {
			onFailure: new Function(this.objectName+".pageLoaders['"+eId+"'].loadingError = true; "+this.objectName+".message('Failed to load page', 'error');"),
			onComplete: new Function(this.objectName+".injectHtml('"+eId+"');") ,
			evalScripts:true, 
			asynchronous:true
		});

	},

	
	/*********************************/
	//Inject the loaded HTML into its page container
	injectHtml: function( eId ){
		//Bailout if this page failed to load
		if( this.pageLoaders[eId].loadingError == true ){ 
			this.pageLoaders[eId] = { state:'closed', status:'ready', loadingError:false };
			return true; 
		}
		
		//Set loaded stuff
		this.pageLoaders[eId].status = "loaded";

		//assign txt to var and then replace dynamic objectNames in source document
		txt = this.replaceObjName(this.pageLoaders[eId].request.transport.responseText);
		
		//Inject source into container
		Element.update(eId, txt);
		this.showPage(eId);
		
	},
	

	/*********************************/
	//Scroll Stuff container
	scrollPix: function( eId, scrollY ){

		//Set to default ElementId If None was given
		eId = eId || this.defaultPageLoader;
		
		scrollY = scrollY || 0;
		
		//Return if nothing
		if( ! eId ){ return true; }
		
		//Scroll It
		$(eId).scrollTop = scrollY;
		
		//Now return
		return true;
	},
	


	/*********************************/
	// Replaces all occurances of {cmsObjectName} with the objectName in the he passed txt argument
	replaceObjName : function(txt) {
		return txt.replace(/\{siteStuffName\}/g, this.objectName );
	},
	

	/*********************************/
	// Replaces all occurances of {cmsObjectName} with the objectName in the he passed txt argument
	cacheImages : function( imgs ) {
		
		if(! this.cacheContainer ) { this.cacheContainer = new Array(); }
    
		var i, j = this.cacheContainer.length; 
		
		for(i=0; i < imgs.length; i++) {
    	if ( imgs[i].indexOf("#") != 0 ){ 
				this.cacheContainer[j] = new Image; 
				this.cacheContainer[j++].src = imgs[i];
			}
		}
		
	},
	

	/*********************************/
	// Submits a form
	formSubmit : function( formId, eId ) {
		formId = formId || "form1";
		eId = eId || this.defaultPageLoader;
		
		//Check to see if we can submit
		if( this.pageLoaders[eId].posting ){ 
			this.message("Posting in process, please wait for the post to finish or cancel post.", "warning");
			return true;
		}
		
		//Assign object
		formObj = $(formId);

		//bail if it does not exist
		if( ! formObj ) { 
			this.message("Error submitting. Could not find "+formId+"", "error");
			return false; 
		}
		
		//Get form data
		formData = Form.serialize(formObj);
		
		//Function for failure
		failFunc = new Function(this.objectName+".message('Failed to post form', 'error');");
		
		//Function for Complete 
		completeFunc = new Function(this.objectName+".pageLoaders['"+eId+"'].posting = false; "+this.objectName+".replaceObjName("+this.objectName+".pageLoaders['"+eId+"'].request.transport.responseText).evalScripts();");
		
		//Display posting message
		this.message("Posting data... please wait.");
		
		//Enter posting mode
		this.pageLoaders[eId].posting = true;
		
		//Do Ajax Request
		this.pageLoaders[eId].request = new Ajax.Updater("", formObj.getAttribute("action"), {
			onFailure: failFunc ,
			onComplete: completeFunc ,
			postBody:formData,
			evalScripts:true, 
			asynchronous:true
		});


	},




	/*********************************/
	// MESSAGE HANDELING
	/*********************************/



	/*********************************/
	message : function( msg, type ) {
		
		//Use a message handler if available
		if( this.msgHandler ) {
			//External message handler
			f = this.msgHandler+".message('"+msg+"', '"+type+"');";
			//evaluate the function
			eval(f);
			return true;
		}
		
		//If the message element is not available then just spit it out junior!
		if (! $(this.messageElement)){
			alert(msg);
			return true;
		}
		
		//Determine the type of message
		type = type || "info";
		if( type == "notice" ) { type = "info"; }
		
		//Open dialog window to display this message
		this.messageOpen();
		
		//Position Message Window
		if( ! this.messagePositioned && (this.messageNudgeX || this.messageNudgeY) ) {
			
			//Current Position of Message Window
			messageOffset = Position.cumulativeOffset($(this.messageElement));

			//Determine Left and Top
			posLeft = this.messageNudgeX ? ( messageOffset[0] + this.messageNudgeX ) : messageOffset[0];
			posTop = this.messageNudgeY ? ( messageOffset[1] + this.messageNudgeY ) : messageOffset[1];
			
			//Set the style
			Element.setStyle(""+this.messageElement+"", {left: posLeft+"px", top:posTop+"px"});
			this.messagePositioned = true;
			
		}
		
		//Convert \n to <br/>
		//msg = msg.escapeHTML();
		msg = msg.replace(/\n/g, "<br/>");
		
		
		var messageTxt = "";
		messageTxt += "<table border='0' cellpadding='3'  cellspacing='0'  style='padding:0px 0px 8px 0px ;'><tr>";
		messageTxt += "<td width='24' valign='top'><img src='"+this.messageResources+"/icon_"+type+".gif'></td> <td class='"+this.messageElement+"Item'>"+msg+"</td>";
		messageTxt += "</tr></table>";
		new Insertion.Top($(this.messageElement+"Text"), messageTxt);

		//alert($(this.dialogName+"Text").childNodes);
		if( $(this.messageElement+"Text").childNodes.length > 10 ) {
			Element.remove($(this.messageElement+"Text").childNodes[10]);
		}
		
	},


	/*********************************/
	//Clears all messages, closes the message box
	messageClose : function () {

		//Cancel existing close timer
		if( this.messageTimer ) {
			clearTimeout(this.messageTimer);
		}

		this.messageTimer = false; 
		
		//Clear all messages Function
		Element.update(this.messageElement+"Text", "");
		
		//Close box dude
		Element.hide(this.messageElement);
		//Effect.Fade(this.messageElement, { afterFinish: new Function( "Element.update('"+this.messageElement+"Text', '');")});
	},
	
	
	
	/*********************************/
	// opens the message container
	messageOpen : function() {

		//Cancel existing close timer
		if( this.messageTimer ) {
			clearTimeout(this.messageTimer);
			this.messageTimer = false; 
		} 
		
		//Set timer
		this.messageTimer = window.setTimeout(""+this.objectName+".messageClose();", this.messageAutoClose);	
		
		
		//Open objects
		Element.show($(this.messageElement));
	},
	
	

	/***************************************************/
	jUploadOpen : function( opts ) {
		//{ loaderPath:'<?=$loader_path?>', windowOptions:'<?=$window_options?>', windowName:'<?=$window_name?>', uploadHandlerName:'<?=$upload_handler?>', params:'<?=urlencode(serialize($_template["params"]))?>'}
		
		//If there is a uploader window open.. close it
		if(this.juploader){ 
			this.juploader.close(); 
		}
		
		//Run after done
		this.juploaderUrlOnComplete = opts.urlOnComplete ? opts.urlOnComplete : false ;
		
		//Create Path
		u = opts.loaderPath+"&upload_handler="+opts.uploadHandlerName+"&params="+escape(opts.params);
		
		//Open juploader window
		this.juploader = window.open(u, ""+opts.windowName+"", ""+opts.windowOptions+"");
	
	},
	
	/***************************************************/
	jUploadUploaded : function( success ) {
		
		success = success || false;
		//Goto url now
		if( this.juploaderUrlOnComplete && success ) {
			this.loadPage('', this.juploaderUrlOnComplete);
		} 
		
		if( ! success ){
			this.juploader.close();
		}
		
	},
	

	/***************************************************/
	jUploadClose : function() {

		//Close Window
		if( this.juploader ) { 
			this.juploader.close();
		}
		window.focus();
	},
	

	
	/*********************************/
	tester : function( inp ) {
		inp = inp || this.objectName;
		alert(inp);
	}
	
	
	
}



/** _xx_slideShow module **/

//Generic Site helpers class
XX.slideShow = Class.create();

XX.slideShow.prototype = {
	/*********************************/
	//Constructor
	initialize: function( opts ){
		
		opts = opts || {};

		//General Options
		this.debug = false;
		this.objectName = opts.objectName ? opts.objectName : "xxSlideSlow";
		
		this.imgs = opts.imgs ? opts.imgs : false; //The image urls to use in the slide show
		this.elementContainer = opts.elementContainer ? opts.elementContainer : "slideShow"; // The id of the element to display the slide show
		this.timePerSlide = opts.timePerSlide ? opts.timePerSlide : 5000; //The time in ms to show each slide
		this.effectIn = opts.effectIn ? opts.effectIn : "Appear"; //the effect that should be used to display new slide
		this.effectOut = opts.effectOut ? opts.effectOut : "Fade"; //the effect that should be used to remove old slide
		this.effectDur = opts.effectDur ? opts.effectDur : 1; // the time the effect should take
		this.maxWidth = opts.maxWidth ? opts.maxWidth : false; // 
		this.maxHeight = opts.maxHeight ? opts.maxHeight : false; // 
		
		this.totalSlides = this.imgs.length;
		this.currentSlide = false;
		
		// Cache the images.
		if( this.imgs ) {
			this.cacheImages( this.imgs );
		} else {
			return true;
		}
		
		
		//Insert images into page
		this.injectSlides();
		
		//Start it up
		this.start();

		
	},


	/*********************************/
	showSlide: function(  ){

		//Stop if slideshow goes away
		if( ! $(this.elementContainer)){ return true; }

		//alert("Going to show slide "+this.currentSlide+" of "+this.imgs.length);
		//Effects option string
		effectFinishFunc = new Function(this.objectName+".startRemoveTimer();");
		
		effectOpts = "duration:"+this.effectDur+", afterFinish:effectFinishFunc";
			
		//Show Slide
		eval("Effect."+this.effectIn+"('"+this.elementContainer+"Slide"+this.currentSlide+"', {"+effectOpts+"});");
		//alert($(this.elementContainer+"Slide"+this.currentSlide));
		
		//If this is the only slide then just quit
		if( this.imgs.length == 1 ) {
			this.stop();
		}
		
	},
	
	
	/*********************************/
	startRemoveTimer: function() {
		//Stop if slideshow goes away
		if( ! $(this.elementContainer)){ return true; }

		//Set a timer to remove this slide
		this.slideTimer = window.setTimeout(""+this.objectName+".removeSlide();", this.timePerSlide);	
	
	},
	
	/*********************************/
	removeSlide: function(  ){

		//Dont remove if stopped
		if( this.running == false ||  ! $(this.elementContainer) ) {
			//Kill timer if it is going
			clearTimeout(this.slideTimer);

			return true;
		}

		//Set old Slide
		this.killSlide = this.currentSlide;
		
		//Determine which slide to show next
		if( (this.currentSlide + 1) == this.imgs.length ) {
			//Reset to 0
			this.currentSlide = 0;
		} else {
			this.currentSlide = (this.currentSlide) + 1;
		}
		
		//Effects option string
		effectFinishFunc = new Function(this.objectName+".showSlide();");
		effectOpts = "duration:"+this.effectDur+", afterFinish:effectFinishFunc";
			
		//Remove Slide
		eval("Effect."+this.effectOut+"('"+this.elementContainer+"Slide"+this.killSlide+"', {"+effectOpts+"});");
		//Effect.Fade("slideShowSlide0");
		
	},
	
	

	/*********************************/
	stop: function(  ){
		
		//Kill timer if it is going
		clearTimeout(this.slideTimer);

		this.running = false;
		
		//Set to start when clicked on element
		if( eObj = $(this.elementContainer)) {
			eObj.onclick = new Function(this.objectName+".start();");
		}
		
		
	},
	
	/*********************************/
	start: function(  ){

		if(! $(this.elementContainer)) { return true; }

		//Set current Slide to 0
		this.currentSlide = 0;
		
		//Kill timer if it is going
		clearTimeout(this.slideTimer);

		this.running = true; // Set running var

		//Make sure that the image are hidden
		for( i=0; i < this.imgs.length; i++) {
			//Insert img code
			Element.hide(this.elementContainer+"Slide"+i);
		}
		
		
		//Set to stop when clicked on element
		if( eObj = $(this.elementContainer)) {
			eObj.onclick = new Function(this.objectName+".stop();");
		}
		
		//Show it
		this.showSlide();
	},
	
	
	/*********************************/
	injectSlides: function(  ){
		
		styleStr = "display:none;";
		styleStr = this.maxWidth ? styleStr+" width:"+this.maxWidth+"px;" : styleStr;
		styleStr = this.maxHeight ? styleStr+" height:"+this.maxheight+"px;" : styleStr;
		
		
		//Loop imgs
		for( i=0; i < this.imgs.length; i++) {
			//Insert img code
			new Insertion.Top(this.elementContainer, "<img id='"+this.elementContainer+"Slide"+i+"' src='"+this.imgs[i]+"' style='"+styleStr+"'>");
		}
		
	},
	
	

	/*********************************/
	// Replaces all occurances of {cmsObjectName} with the objectName in the he passed txt argument
	cacheImages : function( imgs ) {
		
		if(! this.cacheContainer ) { this.cacheContainer = new Array(); }
    
		var i, j = this.cacheContainer.length; 
		
		for(i=0; i < imgs.length; i++) {
    	if ( imgs[i].indexOf("#") != 0 ){ 
				this.cacheContainer[j] = new Image; 
				this.cacheContainer[j++].src = imgs[i];
			}
		}
		
	},
	

	
	

	/*********************************/
	//Test function
	tester : function( inp ) {
		inp = inp || this.objectName;
		alert(inp);

	}
	
	
	
	
}



/** site module **/



/***************************************************/
//Setup nav buttons
// This is not used
function siteNavs( clsName, imgPath, stuffName ) {
	
	//Find objects
	navObjs = document.getElementsByClassName( clsName );
	
	//Die
	if( navObjs.length == 0 ){ return true; }
	
	//Loop found items
	for( i=0; i < navObjs.length; i++ ) {

		//Get object
		nObj = $(""+navObjs[i].id+"");

		
		//Assign events
		nObj.onclick = new Function(""+stuffName+".loadPage('','"+nObj.id+".php'); "+stuffName+".currentEleId = '"+nObj.id+"';");
		nObj.onmouseover = new Function("$('"+nObj.id+"Btn').src = '"+imgPath+"/"+nObj.id+"_over.gif';");
		nObj.onmouseout = new Function("$('"+nObj.id+"Btn').src = '"+imgPath+"/"+nObj.id+".gif';");
		
	}
}


