
/**
* @fileoverview
* Df Global API Library.
*
* @requires  prototype.js v1.5 or above
*/
var Df = {
	
	/**
	* The version of the Df api core.
	* @type Float
	* @public
	*/
	
	version: "1.2.1",
	
	/**
	* load javascript files through inline as the page loads, n waits for n-1 to load
	* @type Void
	* @note uses document.write
	* @public
	*/
	loadJS: function(){
		for(var i = 0; i < arguments.length; i++) {
			document.write('<script type="text/javascript" src="'+arguments[i]+'"></script>');
		}
	},
	
	/**
	* browser detection
	* @type Object
	* @public
	*/
	browser: function(){
		
		var obj = {
			mac : 0,
			safari : 0,
			firefoxMac : 0,
			pc : 0,
			ie : 0,
			ie6 : 0,
			ie7 : 0,
			netscape : 0,
			firefox : 0
		};
		
		var ua = navigator.userAgent.toLowerCase();
		
		if(ua.indexOf("macintosh")!==-1){
			obj.mac = 1;
			if(ua.indexOf("safari")!==-1){
				obj.safari = 1;
			}else if(ua.indexOf("firefox")!==-1){
				obj.firefoxMac = 1;
			}
		}else{
			obj.pc = 1;
			if(ua.indexOf("msie")!==-1){
				obj.ie = 1;
				if(ua.indexOf("msie 6")!==-1 || ua.indexOf("msie 5")!==-1){
					obj.ie6 = 1;
				}else if(ua.indexOf("msie 7")!==-1){
					obj.ie7 = 1;
				}
			}else if(ua.indexOf("netscape")!==-1){
				obj.netscape = 1;
			}else if(ua.indexOf("firefox")!==-1){
				obj.firefox = 1;
			}
		}
		return obj;
	},
	
	/**
	* browser detection
	* @type Object
	* @note shortcut for document.compatMode
	* @public
	*/
	renderMode: function(){
		return document.compatMode;	
	},
	
	/**
	* concatination of function arguments
	* @type String
	* @public
	*/
	concat: function(){
		var ary = [];
		for(var i=0; i<arguments.length; i++){
			ary.push(arguments[i]);
		}
		return ary.join('');
	},
	
	/**
	* create namespace
	* @type void
	* @param {String} str The complete Namespace as a string
	* @param {Node} scope the scope to add the namespace
	* @public
	* @example
	Df.createNS('df.something.somethingelse',$('xxx'))
	// creates
	$('xxx').df.something.somethingelse = {}
	*/
	createNS: function(str,scope){
		var ary = str.split('.');
		
		if(!scope){
			scope = window
		}
		
		if(scope[ary[0]]){
		}else{
			scope[ary[0]] = {};
		}
		
		if(ary[1]){
			next(scope[ary[0]],1);
		}
			
		function next(base,i){
			if(base[i]){
				interate(base,i);
			}else{
				base[ary[i]] = {};
				interate(base,i);
			}
		}
		
		function interate(base,i){
			if(ary[i+1]){
				next(base[ary[i]],i+1);
			}
		}
   }
};

// start: extend prototype 

		//add element methods
		Element.addMethods({

			getContentDims: function(element){
				element = $(element);
				var internalHeights = [];
				var internalWidths = [];
				var children = element.immediateDescendants();

				var val;

				val = parseInt(element.getStyle('paddingTop'));
				if(val){
					internalHeights.push(val);
				}
				val = parseInt(element.getStyle('paddingBottom'))
				if(val){
					internalHeights.push(val);
				}

				val = parseInt(element.getStyle('paddingLeft'));
				if(val){
					internalWidths.push(val);
				}
				val = parseInt(element.getStyle('paddingRight'))
				if(val){
					internalWidths.push(val);
				}	

				if(children){
					var none = false;

					if(element.getStyle('display') == "none"){
						none = true;
						element.style.display = "block";
					}

					for(var i=0; i<children.length; i++){

						val = parseInt(children[i].getHeight());
						if(val){
							internalHeights.push(val);
						}
						val = parseInt(children[i].getStyle('marginTop'));
						if(val){
							internalHeights.push(val);
						}
						val = parseInt(children[i].getStyle('marginBottom'));
						if(val){
							internalHeights.push(val);
						}

						val = parseInt(children[i].getWidth());
						if(val){
							internalWidths.push(val);
						}
						val = parseInt(children[i].getStyle('marginLeft'));
						if(val){
							internalWidths.push(val);
						}
						val = parseInt(children[i].getStyle('marginRight'));
						if(val){
							internalWidths.push(val);
						}
					}

					if(none){
						element.style.display = "none";
					}

				}
				return {height:internalHeights.sum() ,width:internalWidths.max()};
			},

			animator: function(element,para){
				element = $(element);

				Df.createNS('df.animate',element);

				element.df.animate = new Df.Animate(element);	

				if(para){
					element.df.animate.run(para);
				}

				return element;
			},

			tooltip: function(element,para){
				element = $(element);

				Df.createNS('df.tip',element);

				element.df.tip = new Df.Tip(element);	

				if(para){
					element.df.tip.set(para);
				}

			return element;
			},

			dropnav: function(element,para){
				element = $(element);

				var elem = element.immediateDescendants();
				for(var i=0; i<elem.length; i++){

					var elemen = $(elem[i]);

					Df.createNS('df.dropnav',elemen);

					elemen.df.dropnav = new Df.Dropnav(elemen);	

					elemen.df.dropnav.set(para);
				}

				return element;
			},

			tabset: function(element,para){
				element = $(element);

				var elem = element.immediateDescendants();
				for(var i=0; i<elem.length; i++){
					if(elem[i].tagName == "DT" || elem[i].tagName == "dt"){

						var elemen = $(elem[i]);

						Df.createNS('df.tabset',elemen);

						elemen.df.tabset = new Df.Tabset(elemen);	

						elemen.df.tabset.set(para);
					}
				}

				return element;
			},

			cardset: function(element,para){
				element = $(element);

				var elem = element.immediateDescendants();
				for(var i=0; i<elem.length; i++){
					if(elem[i].tagName == "LI" || elem[i].tagName == "li"){

						var elemen = $(elem[i]);

						Df.createNS('df.cardset',elemen);

						elemen.df.cardset = new Df.Cardset(elemen);	

						elemen.df.cardset.set(para);
					}
				}

				return element;
			},

			scrollbar: function(element,para,onset){

				element = $(element);

				Df.createNS('df.scrollbar',element);

				element.df.scrollbar = new Df.Scrollbar(element);	

				element.df.scrollbar.set(para,onset);

				return element;
			}
		});

		//more for strings
		Object.extend(String.prototype,{

			//create a unique String
			uId: function(){
				return this + "u" + new Date().getTime() + parseInt(10000*Math.random());
			},

			//evaluate string
			exe: function(){
				return(eval('[' + this + ']')[0]);
			},

			trim: function(){
				return this.replace(/^[\s]+ |[\s]+$/g,'');	
			}

		});

		//more for arrays
		Object.extend(Array.prototype,{
			sum:function(){
				var s = 0;
				for(var i=0; i<this.length; i++){
					s += this[i];
				}
				return s;
			}
		});

		Object.extend(Number.prototype,
			{
			//JSON object of new paramerters and methods

			//number suffix
			suff: function(){
				var str = this.toString()
				var count = parseInt(str.length -1)
				if(this == 0)return this
				if((str[count]>3 && str[count]<10) || str[count-1]==1 && count != 0 )return this + "th"
				if(str[count] == 1)return this + "st"
				if(str[count] == 2)return this + "nd"
				if(str[count] == 3)return this + "rd"
					return this + "th"
			},

			round: function(places){
				return Math.round((this+1-1)*(Math.pow(10,places)))/Math.pow(10,places);
			},

			dollars: function(){
				var num = this.round(2)
				num = num.toString()
				var dec = num.indexOf(new String('.'))
				if(dec == -1){
					num = num.concat(new String('.00'))   
				}else if(((num.length-1) - dec) == 1){
					num = num.concat(new String('0'))
				}
				return '$'+num
			}

			//END JSON object
			});

		//additional shortcuts

		//create element
		var $E = function(tag,elm,para){
			var obj = document.createElement(tag);
			if(para){
				Object.extend(obj,para);
			}
			elm.appendChild($(obj));
			return $(obj);
		};

// end: extend prototype 



/////////////////////////////////////// Animate /////////////////////////////////////////////////////
Df.Animate = function(re){
    
	var ref = $(re);
	
	var pars = this.pars = {
		time: 250,
		pause: 40,
		skip:false,
		onComplete: false,
		width: false,
		height: false,
		color: false,
		backgroundColor: false,
		backgroundPosition: false,
		left: false,
		top: false,
		opacity: false,
		fontSize: false,
		lineHeight: false,
		paddingLeft: false,
		paddingRight: false,
		paddingTop: false,
		paddingBottom: false,
		marginLeft: false,
		marginRight: false,
		marginTop: false,
		marginBottom: false,
		selectors: []
	}
	
	var possibleSelectors = [
		'width','height','color','left','top','fontSize', 'lineHeight',
		'paddingLeft','paddingRight','paddingTop','paddingBottom',
		'marginLeft','marginRight','marginTop','marginBottom',
		'opacity','backgroundColor', 'backgroundPosition'
	]
	var running = false;
	var iterations = false;
	var currentIteration = false;
	var animators = [];
	var coords = [];
	var history = [];
	var hpointer = 0;
	
	//public methods
	
	this.version = function(){
		return 1.3;
	}
	
	this.requires = function(){
		return [
			'/js/prototype1_6.js',
			'/js/prototype1_6_extend.js'	
			];
	}
	
	var run = this.run = function(para,fromHistory){
		//overide parametersalert(hpointer)
		if(para){
			pars = Object.extend(pars,para);
		}
		
		//load with initial state of element
		if(history.length == 0){
			loadInitialState();
			hpointer = 0;
		}
		
		//load record in history array
		if(!fromHistory){
			loadState();
			hpointer = history.length -1
		}
		
		//create an array of selector to animate
		createAnimators();
		
		if(animators.length == 0 && !fromHistory){
			history.pop()
			hpointer--
		}
		
		//determine the iterations the animation will take
		setIterations();
		
		//create an array of interation steps, how the selectors are set for each iteration
		createCoordHash();
		
		//run though the coords array with the set pause value
		if(coords.length > 0){
			running = true;
			stepThroughAnimation();
		}
		
	}
        
	this.getHistoryCount = function(){
		return history.length;
	}
	
	this.clear = function(){
		running = false;
		animators = [];
		history = [];
		hpointer = 0;
		iterations = false;
		currentIteration = false;
		coords = [];
	}
	
	var back = this.back = function(para){
		if(hpointer > 0){
			hpointer--;	
			finishCall(para);
		}
	}
	
	var next = this.next = function(para){
		if((hpointer + 1) < history.length){
			hpointer++;	
			finishCall(para);
		}
	}
	
	var first = this.first = function(para){
		hpointer = 0;
		finishCall(para);
	}
	
	var last = this.last = function(para){
		hpointer = (history.length-1);
		finishCall(para);
	}
   
	this.toggle = function(para){
		if(history.length == 0){
			finishCall(para);	
		}
		else if(hpointer == 1){
			first(para);
		}
		else if(hpointer == 0){
			last(para);
		}
	}
    
	//private methods
   
	var finishCall = function(para){
		if(para){
			Object.extend(history[hpointer],para);
		}
		run('',true);
	}
	
	var loadInitialState = function(){
		
		createSelectors()
		
		var copy = {}
		copy = Object.extend(copy,pars);
		
		var obj = {}
		for(var i=0; i<copy.selectors.length; i++){
			
			var val = ref.getStyle(copy.selectors[i]);
                        
			if(val != undefined){
                    
				obj[copy.selectors[i]] = val ;  
			}else{
                    
				obj[copy.selectors[i]] = false;  
			}
		}
		
		history.push(Object.extend(copy,obj));
	}
	
	var loadState = function(){
		
		createSelectors()
		
		history.push(Object.extend({},pars));
	}
	
	var createSelectors = function(){
		pars.selectors.length == 0
		possibleSelectors.each(function(v){
			if(pars[v] !== false){
				pars.selectors.push(v)
			}
		});
	}
	
	var createAnimators = function(){
		animators = [];
		
		for(var i=0; i<history[hpointer].selectors.length; i++){
			var elem = history[hpointer].selectors[i];
			
			if(history[hpointer][elem] !== false){
				
				var rawTargetValue = history[hpointer][elem]
                             
				//execute value function
				if(rawTargetValue.constructor == Function){
					rawTargetValue = rawTargetValue(ref);
				}
                             
				var val = ref.getStyle(elem);
         
				var currentValue = getCurrentValue(elem,val);
				
				var targetValue = getCurrentValue(elem,rawTargetValue);
				
				var units = getUnits(rawTargetValue);
				if(!units){
					units = getUnits(val);
				}
				
				var delta = getDelta(targetValue,currentValue);
				
				if(delta){
					animators.push({selector:elem,delta:delta,current:currentValue,units:units});
				}
                                
			}
		}
	}
	
	var setIterations = function(){
		if(history[hpointer].pause && history[hpointer].time){
			iterations = Math.ceil(history[hpointer].time/history[hpointer].pause);
		}
		else if(history[hpointer].skip && history[hpointer].pause){
			iterations = Math.ceil(getMaxAbsVal() / history[hpointer].skip);
		}
		currentIteration = 0;
	}
	
	var createCoordHash = function(){
		coords = [];
		if(animators.length > 0){
			for(var i=0; i<iterations; i++){
				coords.push(buildAnimateStep(i));
			}
		}
	}
	
	//recursive function that steps through the coords array based on pause value
	var stepThroughAnimation = function(){
		if(running){
			if(iterations > currentIteration){
				ref.setStyle(coords[currentIteration]);
				currentIteration++;
				setTimeout(stepThroughAnimation,history[hpointer].pause);
			}else{
				running = false;
				
				if(history[hpointer].onComplete){
					history[hpointer].onComplete(ref);
				}
			}
		}
	}
	
	var getMaxAbsVal = function(){
		var ary = [];
		for(var i=0; i<animators.length; i++){
			var val = animators[i].delta;
			if(val.constructor == Array){
				for(var j=0; j<val.length; j++){
					ary.push(Math.abs(val[j]));
				}
			}else{
				ary.push(Math.abs(val));
			}
		}
		return ary.max();
	}
	
	var buildAnimateStep = function(rec){
		var obj = {}
		
		for(var i=0; i<animators.length; i++){
			var elem = animators[i];
			
			var val = getInteratedValue(elem,rec);
			
			if(rec == (iterations-1)){
				
                                var rawTargetValue = history[hpointer][elem.selector]
                                //execute value function
                                if(rawTargetValue.constructor == Function){
                                     rawTargetValue = rawTargetValue(ref);
                                }
                                
                                val = getCurrentValue(elem.selector,rawTargetValue);
                        }
			obj[elem.selector] = setDisplayValue(elem.selector,val,elem.units);
		}
		return obj;
	}
	
	var getInteratedValue = function(elem,rec){
		var val = false;
		if(elem.delta.constructor == Array){
			val = [];
			
			for(var i=0; i<elem.delta.length; i++){
				if(history[hpointer].pause && history[hpointer].time){
					val.push(elem.current[i] + ((rec+1) * (elem.delta[i]/iterations)));
				}
				else if(history[hpointer].pause && history[hpointer].skip){
					
					val.push(plotSkipValue(elem.current[i],elem.delta[i],rec));
				}
			}
		}else{
			if(history[hpointer].pause && history[hpointer].time){
				val = elem.current + ((rec+1) * (elem.delta/iterations));
			}
			else if(history[hpointer].pause && history[hpointer].skip){
				val = plotSkipValue(elem.current,elem.delta,rec);
			}
			
		}
		return val;
	}
	
	var plotSkipValue = function(current,delta,rec){
		if(delta > 0){
			var plot = current + ((rec+1) * (history[hpointer].skip));
			
			if(plot <= current + delta){
				plot = plot;
			}else{
				plot = current + delta;
			}
		}else if(delta < 0){
			var plot = current - ((rec+1) * (history[hpointer].skip));
			
			if(plot >= current + delta){
				plot = plot;
			}else{
				plot = current + delta;
			}
		}else{
			var plot = 0;
		}
		return plot;
	}
	
	//takes two numeric values or two numeric arrays and returns the difference of the numbers or an array of the differences of each number in the array
	var getDelta = function(targetValue,currentValue){
		var res = false;
		var keepIt = false;
		if(targetValue.constructor == Array | currentValue.constructor == Array){
			res = [];
			for(var i=0; i<targetValue.length; i++){
				var delta = targetValue[i] - currentValue[i]
				if(delta){
					keepIt = true;
				}
				res.push(delta);
			}
			if(!keepIt){
				res = false;	
			}
		}else{
			res = targetValue - currentValue;
		}
		return res;
	}
	
	//takes a raw value and returns the unit measurement of that value
	var getUnits = function(val){
		var str = false;
		if(/px$/.test(val)){
			str = 'px';	
		}else if(/%$/.test(val)){
			str = '%';	
		}else if(/em$/.test(val)){
			str = 'em';	
		}
		return str;
	}
	
	//(NEEDS SOME WORK on UNITS) takes a selector, a number or an array of numbers, and a unit and returns the presentation ready value of the number(s)
	var setDisplayValue = function(elem,val,units){
		if(
			elem == 'width' | elem == 'height' | elem == 'top' | elem == 'left' | elem == 'fontSize'| elem == 'lineHeight'
			| elem == 'paddingLeft' | elem == 'paddingRight' | elem == 'paddingTop' | elem == 'paddingBottom'
			| elem == 'marginLeft' | elem == 'marginRight' | elem == 'margingTop' | elem == 'marginBottom'
		   ){
			val = parseInt(val);
		}else if(elem == 'opacity'){
			val = val/100;
		}
		else if(elem == 'color' | elem == 'backgroundColor'){
			val = hexFromArray(val);
		}
		else if(elem == 'backgroundPosition'){
			val = toBackgroundPositionString(val);
		}
		
		if(units && elem != 'backgroundPosition'){
			val += units;
		}
		
		return val;
	}
	
	//(NEEDS SOME WORK on UNITS) takes a numbers array [1,1] and returns the presentation value 1px 1px
	var toBackgroundPositionString = function(val){
		str = '';
		for(var i=0; i<val.length; i++){
			str += Math.round(val[i]) + 'px ';
		}
		return str;
	}
	
	//takes a numbers array [255,255,255] and returns the presentation value #ffffff
	var hexFromArray = function(val){
		var str = '#';
		for(var i=0; i<val.length; i++){
			str += parseInt(val[i]).toColorPart();
		}
		return str;
	}
	
	// takes a selector and a mixed raw value and returns the value(s) as a number or an array of numbers
	var getCurrentValue = function(elem,val){
		if(
			elem == 'width' | elem == 'height' | elem == 'top' | elem == 'left' | elem == 'fontSize' | elem == 'lineHeight'
			| elem == 'paddingLeft' | elem == 'paddingRight' | elem == 'paddingTop' | elem == 'paddingBottom'
			| elem == 'marginLeft' | elem == 'marginRight' | elem == 'marginTop' | elem == 'marginBottom'
		   ){
			val = parseInt(val);
		}
		else if(elem == 'opacity'){
			val = parseInt(val * 100);
		}
		else if(elem == 'color' | elem == 'backgroundColor'){
			val = toColorArray(val);
		}
		else if(elem == 'backgroundPosition'){
			val = toBackgroundPositionArray(val);
		}
		
		return val;
	}
	
	//(NEEDS SOME WORK) takes background position info in the form of 1px 1px and converts it to [1,1]
	var toBackgroundPositionArray = function(val){
		val = val.split(' ');
		for(var i=0; i<val.length; i++){
			val[i] = parseInt(val[i])
		}
		return val
	}
	
	//(NEEDS SOME WORK) takes color info in the form of #ffffff or rgb(255,255,255) and conterts it to [255,255,255] 
	var toColorArray = function(val){
		if(/^#/.test(val)){
			val = val.replace(/^#/g,'').replace(/(..)/g,"$1,").replace(/,$/g,'').split(',');
			for(var i=0; i<val.length; i++){
				if(val[i].constructor == String){
					val[i] = parseInt(val[i],16);	
				}
				val[i] = Number(val[i])
			}
			
		}else if(/^rgb/.test(val)){
			val = val.replace(/^rgb\(|\)$/g,'').split(',');
			for(var i=0; i<val.length; i++){
				val[i] = Number(val[i])
			}
		}
		return val
	}
}

///// Tabset

Df.Tabset = function(el){
	//BEGIN constructor
	var ele = this.ele = $(el)
	
	var pars = this.pars = {
		animate: false,
		pause:0,
		activeClassName: 'active',
		eventType: 'click',
		onDisplay: false,
		onHide: false,
		scrollbars: false
	}
	
	var def, animation, scrollbars;
	var displayStatus = "closed";
	var status = false;
	
	this.version = function(){
		return 1.0;
	}
	
	this.requires = function(){
		return [
			'/js/Df.js',
			'/js/prototype1_6.js',
			'/js/prototype1_6_extend.js',
			'/js/Df.Animate.js'
			];
	}
	
	this.set = function(para){
		if(para){
			pars = Object.extend(pars,para)
		}
		
		def = ele.next('dd',0);
		
		if(pars.scrollbars){
			scrollbars = new Df.Scrollbar(def);
			if(pars.scrollbars.constructor == Boolean){
				pars.scrollbars = {}
			}	
			scrollbars.set(pars.scrollbars,function(ins){
				if(ins.getElements().y.holder){
					ins.getElements().y.holder.style.display = 'none'
				}
			});
		}
		
		if(pars.animate){
			animation = new Df.Animate(def);
			if(pars.animate){
				animation.pars = Object.extend(animation.pars,pars.animate);
			}
		}
		
		if(pars.eventType == 'click'){
			Event.observe(ele, 'click', activate ,false);
		}
		else if(pars.eventType == 'hover'){
			
			Event.observe(ele, 'mouseover', activate ,false)
		
			Event.observe(ele, 'mouseout', function(){
				status = false;
			},false)
			
		}
	}
	
	this.getState = function(){
		return displayStatus;
	}
	
	var activate = this.activate = function(event){
		status = true;
		setTimeout(waitToActivate,pars.pause);
	}
	
	var display = this.display = function(){
		
		if(displayStatus=='closed'){
		
			displayStatus = "open";
			
			def.style.visibility = "visible";
			
			if(pars.activeClassName){
				ele.addClassName(pars.activeClassName)
			}
			
			if(animation){
				if(animation.getHistoryCount() == 0){
					animation.run();	
				}else{
					animation.last();
				}
			}
			
			if(scrollbars){
				var xholder = scrollbars.getElements().y.holder;
				if(xholder){
					xholder.style.display = "block";
				}
			}
			
			if(pars.onDisplay){
				pars.onDisplay(ele);
			}
		}
	}
	
	var hide = this.hide = function(){
		
		displayStatus = "closed";
		
		if(animation){
			if(animation.getHistoryCount() > 0){
				animation.first({onComplete: function(){
						finishHide();
					}
				});
			}
		}else{
			finishHide();
		}
	}
	
	var finishHide = function(){
		def.style.visibility = "hidden";
			
		if(pars.activeClassName){
			ele.removeClassName(pars.activeClassName)
		}
		
		if(scrollbars){
			var xholder = scrollbars.getElements().y.holder;
			if(xholder){
				xholder.style.display = "none";
			}
		}
		
		if(pars.onHide){
			pars.onHide(ele);
		}
	}
	
	var waitToActivate = this.waitToActivate = function(){
		
		if(status){
			
			var elem = ele.siblings();
			
			for(var i=0; i<elem.length; i++){
				if((elem[i].tagName == "DT" || elem[i].tagName == "dt") && elem[i].df.tabset.getState() == 'open'){
					elem[i].df.tabset.hide();
				}
			}
			
			if(displayStatus == "closed"){
				display();
			}
		}
	}
}


/////////// dropnav


Df.Dropnav = function(el){
	//BEGIN constructor
	var ele = this.ele = $(el)
	
	var pars = this.pars = {
		animate: false,
		pause:200,
		iframe: true,
		activeClassName: 'active',
		eventType: 'hover',
		onDisplay: false,
		onHide: false,
		childElement: 'UL'
	}
	
	var status = false;
	var displayStatus = false;
	var list, animation;
	
	this.version = function(){
		return 1.2;
	}
	
	this.requires = function(){
		return [
			'/js/Df.js',
			'/js/prototype1_6.js',
			'/js/prototype1_6_extend.js',
			'/js/Df.Animate.js'
			];
	}
	
	this.set = function(para){
		if(para){
			pars = Object.extend(pars,para)
		}
		
		list = ele.getElementsByTagName(pars.childElement)[0];
		if(list){
			
			if(pars.animate){
				animation = new Df.Animate(list);
				if(pars.animate){
					animation.pars = Object.extend(animation.pars,pars.animate);
				}
			}
			
			if(pars.eventType == "hover"){
				Event.observe(ele, 'mouseover', display ,false);
				Event.observe(ele, 'mouseout', hide ,false);
			}
			else if(pars.eventType == "click"){
				Event.observe(ele, 'click', waitToDisplay ,false);
			}
		}
	}
	
	this.getState = function(){
		return displayStatus;
	}
	
	var display = this.display = function(event){
		status = true;
		setTimeout(waitToDisplay,pars.pause);
	}
	
	var hide = this.hide = function(event){
		status = false;
		setTimeout(waitToHide,pars.pause);
	}
	
	var waitToDisplay = function(event){
		
		if(pars.eventType == 'click'){
			findOpen();
			status = true;
		}
		
		if(status && !displayStatus){
		
			displayStatus = true;
			
			if(pars.eventType == "click"){
				Event.stop(event)
				Event.stopObserving(ele,'click',waitToDisplay,false)
				Event.observe(ele,'click',waitToHide,false)
				Event.observe(document.body,'click',waitToHide,false)
			}
			
			if(pars.activeClassName){
				ele.addClassName(pars.activeClassName)
			}
			
			if(pars.onDisplay){
				pars.onDisplay(ele);
			}
			
			list.style.display = "block";
			
			if(animation){
				if(animation.getHistoryCount() == 0){
					animation.run();	
				}else{
					animation.last();
				}
			}
			
			if((Df.browser()).ie6 && pars.iframe){
				showIframe();
			}
		}
	}
	
	var waitToHide = this.waitToHide = function(event){
		
		if(pars.eventType == 'click'){
			status = false;
		}
		
		if(!status){
			
			displayStatus = false;
			
			if(animation){
				if(animation.getHistoryCount() > 0){
					animation.first({onComplete: function(){
							finishHide();
						}
					});
				}
				
			}else{
				finishHide()
			}
			
			if((Df.browser()).ie6 && pars.iframe){
				hideIframe();
			}
		}
	}
	
	var finishHide = function(){
		
		list.style.display = "none";
				
		if(pars.activeClassName){
			ele.removeClassName(pars.activeClassName)
		}
		
		if(pars.onHide){
			pars.onHide(ele);
		}
		
		if(pars.eventType == 'click'){
			Event.stopObserving(ele,'click',waitToHide,false)
			Event.stopObserving(document.body,'click',waitToHide,false)
			Event.observe(ele,'click',waitToDisplay,false)
		}
	}
	
	var showIframe = function(){
		var oDiv = ele.select('iframe.oDiv')[0];
		if(oDiv){
			oDiv.style.display = "block";
		}else{
			var html = '<iframe class="oDiv" style="display:block; filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);" scrolling="no" src="javascript:false;" frameborder="0" height="'+ parseInt(list.offsetHeight) +'px" width="'+ parseInt(list.offsetWidth) +'px"></iframe>';
			new Insertion.Top(ele, html);
		}
	}

	var hideIframe = function(){
		var oDiv = ele.select('iframe.oDiv')[0];
		if(oDiv){
			oDiv.style.display = "none";
		}
	}
	
	var findOpen = function(){
		var elem = ele.siblings();
		for(var i=0; i<elem.length; i++){
			if((elem[i].tagName == "LI" || elem[i].tagName == "li") && elem[i].df.dropnav.getState() == true){
				elem[i].df.dropnav.waitToHide();
			}
		}
	}
}

/*----------- slider ------------------*/

Df.Slider = function(el){
	
	var ele = this.ele = $(el);
	
	var pars = this.pars = {
		classNames: {
			mask: 'mask',
			slider: 'slider',
			prev: {
				base: 'prevBase',
				on :'prevOn',
				off : 'prevOff',
				disable: 'prevDisable'
			},
			next: {
				base: 'nextBase',
				on :'nextOn',
				off : 'nextOff',
				disable: 'nextDisable'
			}
		}
	}
	Object.extend(pars,{
		mask: document.getElementsByClassName(pars.classNames.mask,ele)[0],
		maskHeight: false,
		maskWidth: false,
		slider: document.getElementsByClassName(pars.classNames.slider,ele)[0],
		sliderHeight: false,
		sliderWidth: false,
		arrowM: document.getElementsByClassName(pars.classNames.prev.base,ele)[0],
		arrowP: document.getElementsByClassName(pars.classNames.next.base,ele)[0],
		event: 'click',
		stopEvent: false,
		iterateBy: false,
		animate: false,
		direction: 'hor' //('hor'|'vert')
	});
	
	var move = null;
	
	var dir = false;
	
	var left = {
		attribute: 'left',
		offset: 'offsetWidth',
		maskDem: 'maskWidth',
		sliderDem: 'sliderWidth'
	}
	
	var top = {
		attribute: 'top',
		offset: 'offsetHeight',
		maskDem: 'maskHeight',
		sliderDem: 'sliderHeight'
	}
	
	this.version = function(){
		return 1.1;
	}
	
	this.requires = function(){
		return [
			'../js/prototype1_6.js',
			'../js/prototype1_6_extend.js',
			'../js/Df.Animate.js'	
			];
	}
	
	this.set = function(para){
		
		if(para){
			pars = Object.extend(pars,para)
		}
		
		move = new Df.Animate(pars.slider)
		
		if(pars.direction == 'hor'){
			dir = left
		}else if(pars.direction == 'vert'){
			dir = top
		}
		
		move.pars.onComplete = enableLogic
		
		if(pars.animate){
			move.pars = Object.extend(move.pars,pars.animate)
		}
		
		if(!pars.maskWidth){
			pars.maskWidth = parseInt(pars.mask.offsetWidth);
		}
		if(!pars.maskHeight){
			pars.maskHeight = parseInt(pars.mask.offsetHeight);
		}
		
		if(!pars.sliderWidth){
			pars.sliderWidth = parseInt(pars.slider.offsetWidth);
		}
		if(!pars.sliderHeight){
			pars.sliderHeight = parseInt(pars.slider.offsetHeight);
		}
		
		if(pars.iterateBy){
			if(pars.iterateBy.constructor == String){
				pars.iterateBy = parseInt(pars.slider.getElementsByTagName(pars.iterateBy)[0][dir.offset])
			}
		}
		
		if(pars[dir.sliderDem] > pars[dir.maskDem]){
			enableMinus()
			enablePlus()
			disableActions()
			enableLogic()
			
			if(pars.stopEvent){
				pars.arrowM['on'+pars.stopEvent] =  function(){
					enableLogic()
					move.clear()
				}
				pars.arrowP['on'+pars.stopEvent] =  function(){
					enableLogic()
					move.clear()
				}
			}
		}
	}
	
	function plus(){
		var px = 0;
		if(pars.iterateBy){
			px = -1*(parseInt(pars.slider.getStyle(dir.attribute))) + pars.iterateBy
			if(px > pars[dir.sliderDem] - pars[dir.maskDem]){
				px = pars[dir.sliderDem] - pars[dir.maskDem]
			}
		}else{
			px = pars[dir.sliderDem] - pars[dir.maskDem]
		}
		
		if(px || px == 0){
			if(!pars.stopEvent){
				disableActions()
			}
			move.pars[dir.attribute] = -1*(px)
			move.run()
		}
	}
	
	function minus(){
		var px = 0;
		if(pars.iterateBy){
			px = parseInt(pars.slider.getStyle(dir.attribute)) + pars.iterateBy
			if(px > 0){
				px = 0
			}
		}
		
		if(px || px == 0){
			if(!pars.stopEvent){
				disableActions()
			}
			move.pars[dir.attribute] = px
			move.run()
		}
	}
	
	function enableLogic(){
		if(pars.stopEvent){
			disableActions()
		}
		var pos = parseInt(pars.slider.getStyle(dir.attribute))
		if(pos < 0){
			enableMinus()
		}
		if(pos > -1*(pars[dir.sliderDem]-pars[dir.maskDem])){
			enablePlus()
		}
	}
	
	function stopMinusMove(){
		pars.arrowM['on'+pars.event] = null
	}
	
	function stopPlusMove(){
		pars.arrowP['on'+pars.event] = null
	}
	
	function startMinusMove(){
		pars.arrowM['on'+pars.event] = minus
	}
	
	function startPlusMove(){
		pars.arrowP['on'+pars.event] = plus
	}
	
	function turnOffMinusArrow(){
		pars.arrowM.addClassName(pars.classNames.prev.off)
		pars.arrowM.removeClassName(pars.classNames.prev.on)
	}
	
	function turnOffPlusArrow(){
		pars.arrowP.addClassName(pars.classNames.next.off)
		pars.arrowP.removeClassName(pars.classNames.next.on)
	}
	
	function turnOnMinusArrow(){
		pars.arrowM.addClassName(pars.classNames.prev.on)
		pars.arrowM.removeClassName(pars.classNames.prev.off)
		pars.arrowM.removeClassName(pars.classNames.prev.disable)
	}
	
	function turnOnPlusArrow(){
		pars.arrowP.addClassName(pars.classNames.next.on)
		pars.arrowP.removeClassName(pars.classNames.next.off)
		pars.arrowP.removeClassName(pars.classNames.next.disable)
	}
	
	function enableMinus(){
		turnOnMinusArrow()
		startMinusMove()
	}
	
	function disableMinus(){
		turnOffMinusArrow()
		stopMinusMove()
	}
	
	function enablePlus(){
		turnOnPlusArrow()
		startPlusMove()
	}
	
	function disablePlus(){
		turnOffPlusArrow()
		stopPlusMove()
	}
	
	function disableActions(){
		disableMinus()
		disablePlus()
	}
}

/*-------------- Tip -------------------*/

Df.Tip = function(el){
	//BEGIN constructor
	var ele = this.ele = $(el)
	
	var pars = this.pars = {
		dataString:'some sample text for the tool tip',
		dataString: false,
		className:'holder',
		parent: document.body,
		pause:200,
		xOffset: 0,
		yOffset: 0,
		fitInPage: true,
		animate: false,
		direction:'rc' //lt, ltl, ltt, ct, ctc, rt, rtt, rtr, lc, lcc, rc, rcc, rb, rbr, rbb, cb, cbc, lb, lbl, lbb, cc
	}
	
	var pointer, tip, holder, animation, tipHeight, tipWidth, eleHeight, eleWidth, holderHeight, holderWidth, pointerHeight, pointerWidth, elePosTop, elePosLeft, maxHeight, maxWidth, offSetTop, offsetLeft, xcord, ycord, pcord
	var status = false;
	var displayStatus = false;
	var pcord = false;
	//END constructor
	
	this.version = function(){
		return 1.1;
	}
	
	this.requires = function(){
		return [
			'../js/Df.js',
			'../js/prototype1_6.js',
			'../js/prototype1_6_extend.js',
			'../js/Df.Animate.js'
			];
	}
	
	this.set = function(para){
		if(para){
			pars = Object.extend(pars,para)
		}
		
		holder = $E('div',pars.parent,{className:pars.className});
		
		tip = $E('div',holder,{className:'tip'});
		
		xcord = pars.direction.substring(0,1);
		ycord = pars.direction.substring(1,2);
		
		if(pars.direction.substring(2,3)){
			pcord = pars.direction.substring(2,3);
			var cln = 'pointer';
			if(pars.direction == "ltt" | pars.direction == "ctc" | pars.direction == "rtt") {
				cln += 'T';
			}else if(pars.direction == "ltl" | pars.direction == "lcc" | pars.direction == "lbl"){
				cln += 'L';
			}
			else if(pars.direction == "rtr" | pars.direction == "rcc" | pars.direction == "rbr"){
				cln += 'R';
			}
			else if(pars.direction == "lbb" | pars.direction == "cbc" | pars.direction == "rbb"){
				cln += 'B';
			}
			pointer = $E('div',holder,{className:cln});
		}
		
		if(pars.dataNode){
			tip.appendChild($(pars.dataNode));
		}else if(pars.dataString){
			tip.innerHTML = pars.dataString;
		}
		
		setDems();
		setPos();
		
		holder.style.display = 'none';
		
		if(pars.animate){
			animation = new Df.Animate(holder);
			animation.pars = Object.extend(animation.pars,pars.animate);
		}
		
		Event.observe(holder,'mouseover',function(){
			status = true;
		},false);
		
		Event.observe(holder,'mouseout',hide,false);
		
		Event.observe(ele,'mouseover',display,false);
		Event.observe(ele,'mouseout',hide,false);
	}
	
	this.getAnimationObject = function(){
		return animation;
	}
	
	var display = this.display = function(event){
		status = true;
		setTimeout(waitToDisplay,pars.pause);
	}
	
	var hide = this.hide = function(event){
		status = false;
		setTimeout(waitToHide,pars.pause);
	}
	
	var setDems = function(){
		tipHeight = parseInt(tip.getDimensions().height)
		tipWidth = parseInt(tip.getDimensions().width)
		
		eleHeight = parseInt(ele.getDimensions().height)
		eleWidth = parseInt(ele.clientWidth)
		
		holderHeight = parseInt(holder.getDimensions().height)
		holderWidth = parseInt(holder.getDimensions().width)
		
		if(pcord){
			pointerHeight = parseInt(pointer.getDimensions().height)
			pointerWidth = parseInt(pointer.getDimensions().width)
		}
		
	}
	
	var setPos = function(){
		elePosLeft =  parseInt(Position.cumulativeOffset(ele)[0])
		elePosTop =  parseInt(Position.cumulativeOffset(ele)[1])
		maxHeight = parseInt(Element.getDimensions(document.body).height)
		maxWidth = parseInt(Element.getDimensions(document.body).width)
		offSetTop = parseInt(Position.realOffset(holder)[1])
		offsetLeft = parseInt(Position.realOffset(holder)[0])
	}
	
	var waitToDisplay = function(){
		if(status && !displayStatus){
			displayStatus = true
			
			holder.style.display = 'block';
			
			setPos();
			
			holder.style.height = tipHeight + 'px';
			holder.style.width = tipWidth + 'px';
			
			//align to the right
			if(xcord == "r"){
				holder.style.left = elePosLeft + eleWidth + pars.xOffset + 'px';
			}
			//align to the left
			else if(xcord == "l"){
				holder.style.left = elePosLeft - holderWidth - pars.xOffset + 'px';
			}
			//align centered on x axis		
			else if(xcord == "c"){
				holder.style.left = elePosLeft - (holderWidth/2) + ((eleWidth)/2) + pars.xOffset + 'px';
			}
			
			//align on top
			if(ycord == "t"){
				holder.style.top = elePosTop - tipHeight - pars.yOffset + 'px';
			}
			//align to the bottom
			else if(ycord == "b"){
				holder.style.top = elePosTop + eleHeight + pars.yOffset + 'px';
			}
			//align middle on y axis
			else if(ycord == "c"){
				holder.style.top = elePosTop + ((eleHeight/2)-(tipHeight/2)) + pars.yOffset + 'px';
			}
			
			//position for pointer
			if(pcord){
				positionPointer();
			}
			
			//readjust to fit inside window
			if(pars.fitInPage){
				adjustToPage();
			}
			
			if(animation){
				if(animation.getHistoryCount() == 0){
					animation.run();	
				}else{
					animation.last();
				}
			}
		}
	}
	
	var positionPointer = function(){
		pointer.style.display = 'block';
		pointer.style.top = '0px';
		pointer.style.left = '0px';
			
		if(xcord == "l" && ycord == "t"){
			if(pcord == "l"){
				holder.style.width = holderWidth + pointerWidth + 'px';
				holder.style.top = parseInt(holder.style.top) + pointerHeight + 'px';
				holder.style.left = parseInt(holder.style.left) - pointerWidth + 1 + 'px';
				pointer.style.top = tipHeight - pointerHeight + 'px';
				pointer.style.left = holderWidth  - 1 + 'px';
			}
			else if(pcord == "t"){
				holder.style.height = tipHeight + pointerHeight + 'px';
				holder.style.top = parseInt(holder.style.top) - pointerHeight + 1 + 'px';
				holder.style.left = parseInt(holder.style.left) + pointerWidth + 'px';
				pointer.style.top = tipHeight - 1 + 'px';
				pointer.style.left = holderWidth - pointerWidth + 'px';
				
			}
		}
		else if(xcord == "c" && ycord == "t"){
			holder.style.height = tipHeight + pointerHeight + 'px';
			holder.style.top = parseInt(holder.style.top) - pointerHeight + 1 + 'px';
			pointer.style.top = tipHeight - 1 + 'px';
			//if(pcord == "c"){
				pointer.style.left = (parseInt(holder.style.width)/2) - (pointerWidth/2) + 'px';
			//}
		}
		else if(xcord == "r" && ycord == "t"){
			if(pcord == "r"){
				holder.style.width = holderWidth + pointerWidth + 'px';
				holder.style.top = parseInt(holder.style.top) + pointerHeight + 'px';
				holder.style.left = parseInt(holder.style.left) + 'px';
				tip.style.left = pointerWidth - 1 + "px";
				pointer.style.top = tipHeight - pointerHeight + 'px';
			}
			else if(pcord == "t"){
				holder.style.height = tipHeight + pointerHeight + 'px';
				holder.style.top = parseInt(holder.style.top) - pointerHeight + 1 + 'px';
				holder.style.left = parseInt(holder.style.left) - pointerWidth + 'px';
				pointer.style.top = tipHeight - 1 + 'px';
				pointer.style.left = 0 + 'px';
				
			}
		}
		else if(xcord == "l" && ycord == "c"){
			holder.style.width = holderWidth + pointerWidth + 'px';
			holder.style.left = parseInt(holder.style.left) - pointerWidth + 1 + 'px';
			pointer.style.left = holderWidth  - 1 + 'px';
			//if(pcord == "c"){
				pointer.style.top = (tipHeight/2)-(pointerHeight/2) + 'px';
				
			//}
			
		}
		else if(xcord == "r" && ycord == "c"){
			holder.style.width = holderWidth + pointerWidth + 'px';
			tip.style.left = pointerWidth - 1 + "px";
			//if(pcord == "c"){
				pointer.style.top = (tipHeight/2)-(pointerHeight/2) + 'px';
				
			//}
			
		}
		else if(xcord == "r" && ycord == "b"){
			if(pcord == "r"){
				holder.style.width = holderWidth + pointerWidth + 'px';
				holder.style.top = parseInt(holder.style.top) - pointerHeight + 'px';
				tip.style.left = pointerWidth - 1 + "px";
			}
			else if(pcord == "b"){
				holder.style.height = tipHeight + pointerHeight + 'px';
				holder.style.left = parseInt(holder.style.left) - pointerWidth + 'px';
				tip.style.top = pointerHeight - 1 + 'px';
			}
		}
		else if(xcord == "c" && ycord == "b"){
			holder.style.height = tipHeight + pointerHeight + 'px';
			tip.style.top = pointerHeight - 1 + 'px';
			if(pcord == "c"){
				pointer.style.left = (parseInt(holder.style.width)/2) - (pointerWidth/2) + 'px';
			}
		}
		else if(xcord == "l" && ycord == "b"){
			if(pcord == "l"){
				holder.style.width = holderWidth + pointerWidth + 'px';
				holder.style.top = parseInt(holder.style.top) - pointerHeight + 'px';
				holder.style.left = parseInt(holder.style.left) - pointerWidth + 1 + 'px';
				pointer.style.left = holderWidth  - 1 + 'px';
			}
			else if(pcord == "b"){
				holder.style.height = tipHeight + pointerHeight + 'px';
				pointer.style.left = tipWidth - pointerWidth + 'px';
				holder.style.left = parseInt(holder.style.left) + pointerWidth + 'px';
				tip.style.top = pointerHeight - 1 + 'px';
			}
		}
		
		
	}
	
	var resizeHolderWithoutPointer = function(){
		holder.style.height = tipHeight + 'px';
		holder.style.width = tipWidth + 'px';
		tip.style.top = '0px';
		tip.style.left = '0px';
		pointer.style.display = 'none';
	}
	
	var adjustToPage = function(){
		var deltaT = -1*(parseInt(holder.style.top) - offSetTop);
		var deltaB = (parseInt(holder.style.height) + parseInt(holder.style.top) - offSetTop) - maxHeight;
		var deltaL = -1*(parseInt(holder.style.left) - offsetLeft);
		var deltaR = (parseInt(holder.style.width) + parseInt(holder.style.left) - offsetLeft) - maxWidth;
		
		if(pcord){
			if(((deltaT>0 | deltaB>0) && (deltaL>0 | deltaR>0)) |
			   (deltaT>0 && (xcord == "c" | pcord == "t")) |
			   (deltaB>0 && (xcord == "c" | pcord == "b")) |
			   (deltaL>0 && (ycord == "c" | pcord == "l")) |
			   (deltaR>0 && (ycord == "c" | pcord == "r"))
			   ){
				resizeHolderWithoutPointer();
			}
			
		}
		
		if(deltaT>0){
			holder.style.top = parseInt(holder.style.top) + deltaT + 'px'
			if(pcord){
				pointer.style.top = parseInt(pointer.getStyle('top')) - deltaT  + 'px'
			}
		}
		else if(deltaB>0){
			holder.style.top = parseInt(holder.style.top) - deltaB + 'px'
			if(pcord){
				pointer.style.top = parseInt(pointer.getStyle('top')) + deltaB  + 'px'
			}
		}
		
		if(deltaL>0){
			holder.style.left = parseInt(holder.style.left) + deltaL + 'px'
			if(pcord){
				pointer.style.left = parseInt(pointer.getStyle('left')) - deltaL  + 'px'
			}
		}
		else if(deltaR>0){
			holder.style.left = parseInt(holder.style.left) - deltaR + 'px'
			if(pcord){
				pointer.style.left = parseInt(pointer.getStyle('left')) + deltaR  + 'px'
			}
		}
	}
	
	var waitToHide = function(){
		if(!status){
			displayStatus = false;
			
			if(animation){
				if(animation.getHistoryCount() > 0){
					animation.first({onComplete: function(){
							holder.style.display = "none";
						}
					});
				}
			}else{
				holder.style.display = "none";
			}
		}
	}
	
	//END private methods
}

/*-------------- Modal --------------------*/

Df.Modal=function(){var D=this.pars={contentString:false,contentNode:false,domNode:false,holder:document.body,backgroundClassName:"holder",dialogClassName:"dialogHolder",minWidth:800,minHeight:600,closeClass:"close",animateHolder:false,animateDialog:false};var G,B,K,J,L;var A=0;this.version=function(){return 1.2};this.requires=function(){return["/js/Df.js","/js/prototype1_6.js","/js/prototype1_6_extend.js","/js/Df.Animate.js"]};this.set=function(N){if(N){D=Object.extend(D,N)}if(D.minWidth.constructor==Number){D.minWidth+="px"}else{D.minWidth=parseInt($(D.minWidth).scrollWidth)+"px"}if(D.minHeight.constructor==Number){D.minHeight+="px"}else{D.minHeight=parseInt($(D.minHeight).scrollHeight)+"px"}G=$E("div",$(D.holder),{className:D.backgroundClassName});if(D.animateHolder){B=new Df.Animate(G);B.pars=Object.extend(B.pars,D.animateHolder)}};this.show=function(){G.style.display="block";if(B){if(B.getHistoryCount()==0){B.run()}else{B.last()}}if((Df.browser()).ie6){G.innerHTML="<iframe style='filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);' scrolling='no' src='javascript:false;' frameborder='0' height='"+D.minHeight+"px' width='"+D.minWidth+"px'></iframe>"}else{G.style.minWidth=D.minWidth;G.style.minHeight=D.minHeight}if(D.keyPress){Event.observe(document,"keypress",E,false)}if(J){J.style.display="block";J.down().style.display="block";if(Position.realOffset(J)[1]>0){var N=J.immediateDescendants()[0];if(N){N.style.display="block";N.style.marginTop=A+parseInt(Position.realOffset(J)[1])+"px"}}if(!(Df.browser()).ie6){J.style.minWidth=D.minWidth;J.style.minHeight=D.minHeight}if(L){if(L.getHistoryCount()==0){L.run()}else{L.last()}}}};var I=this.hide=function(){Event.stopObserving(document,"keypress",E,false);if(B){if(B.getHistoryCount()>0){B.first({onComplete:function(){G.style.display="none"}})}}else{G.style.display="none"}if(L){if(L.getHistoryCount()>0){L.first({onComplete:function(){C()}})}}else{C()}};this.setContentString=function(N){D.contentString=N;if(!J){M()}J.innerHTML=D.contentString;H();F()};this.setContentNode=function(N){D.contentNode=N;if(!J){M()}J.innerHTML="";J.appendChild(D.contentNode);D.contentNode.setStyle({display:"block",visibility:"visible"});H();F()};var C=function(){var N=J.immediateDescendants()[0];if(N){N.style.display="none"}if(D.domNode){J.down().style.display="none";document.body.appendChild(D.domNode)}J.style.display="none"};var F=function(){var N=J.immediateDescendants()[0];if(N){A=parseInt(N.getStyle("marginTop"))}};var H=function(){var O=document.getElementsByClassName(D.closeClass,J);for(var N=0;N<O.length;N++){O[N].onclick=I}};var M=function(){J=$E("div",$(D.holder),{className:D.dialogClassName});if(D.animateDialog){L=new Df.Animate(J);L.pars=Object.extend(L.pars,D.animateDialog)}};var E=function(N){if(N.keyCode==Event.KEY_RETURN){I()}};this.setDomNode=function(N){if(D.domNode){if(J.down()){J.down().style.display="none"}document.body.appendChild(D.domNode)}D.domNode=N;if(!J){M()}J.innerHTML="";J.appendChild(D.domNode);H()}};

/*-------------- ad hoc js ----------------*/

function imgOn(imgName) {
        if (document.images) {
            document[imgName].src = eval(imgName + "on.src");
	}
}
function imgOff(imgName) {
        if (document.images) {
            document[imgName].src = eval(imgName + "off.src");
	}
}

// email
function toggleVisibility(id)
{
    var displaySet = $(id).getStyle('display');
    if(displaySet.include('none')){
	    $(id).setStyle({
		display: 'block'
	    });
	} else {
		$(id).hide();
	}
}

function toggleiFrame(id, NNtype, IEtype, WC3type)
{
    if (document.getElementById) {
        eval("document.getElementById(id).style.zIndex = \"" + WC3type + "\"");
    } else {
        if (document.layers) {
            document.layers[id].visibility = NNtype;
        } else {
            if (document.all) {
                eval("document.all." + id + ".style.zIndex = \"" + IEtype + "\"");
            }
        }
    }
}

function trimString (str) {
  while (str.charAt(0) == ' ')
    str = str.substring(1);
  while (str.charAt(str.length - 1) == ' ')
    str = str.substring(0, str.length - 1);
  return str;
}


function emailCheck(type) // not sure if anybody uses this, but just in case i'm leaving it functional
{
 var email = trimString(document.emailForm.emailAddress.value);

    if (!validEmail(email))
	{
        alert('Please enter a valid e-mail address.');
        return false;
    }
	if(type == 1)
	{
        document.emailForm.submit();
	}
}

function validEmail(email)
{
    var vAtSym    = email.indexOf('@')
    var vPeriod   = email.lastIndexOf('.')
    var vSpace    = email.indexOf(' ')
    var vLength   = email.length - 1   // Array is from 0 to length-1

    if (vAtSym < 1 ||                     // '@' cannot be in first position
    	vPeriod <= vAtSym + 1 ||          // Must be atleast one valid char btwn '@' and '.'
    	vPeriod == vLength  ||            // Must be atleast one valid char after '.'
    	vSpace  != -1)                    // No empty spaces permitted
	{
        return false;
    }
	return true;
}

function showCustomPopUp(thisUrl,thisName,theseParams)
{
	remote = open(thisUrl, thisName, theseParams);
}


//	verisign POP-UP WINDOW
function popUp(url)
{
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}

function jump(url)
{
	if (url != "" && url != null)
	{
		self.location.href = url;
	}
}

// Wrapper to retrieve a DOM object.  This function (should) contain browser 
// checks and extra convienence functionality. 
function g_getObj(objId) { 
    if (document.getElementById) { 
        return document.getElementById(objId); 
    } 
  
    return null; 
}

// Will find any HTML elements that have a name attribute, including those
// that IE normally doesn't support...
function g_getObjectsByName(tag, name) {
    var tags = document.getElementsByTagName(tag);
    var obj = new Array();
    if (tags != null) {
        for (var i = 0, n = tags.length; i < n; i++) {
            if (tags[i].getAttribute("name") == name) {
                obj.push(tags[i]);
            }
        }
    }
    
    return obj;
}

function g_hideObj(objId) {
    var obj = (typeof(objId) == "string" ? g_getObj(objId) : objId);
    if (obj && obj.style) {
        obj.style.display = "none";
    }
}

function g_showObj(objId) {
    var obj = (typeof(objId) == "string" ? g_getObj(objId) : objId);
    if (obj && obj.style) {
        // Certain objects will not get displayed if their display style is set to blank.
        // For these objects, you will need to explicitly pass in an extra parameter for them
        // to display, try "inline" or "block" - Todd Hansberger
        obj.style.display = (arguments[1] != null ? arguments[1] : "");
    }
}

function g_getTrueOffsetLeft(obj) {
    var trueOffset = 0;
    if (obj != null) {
        while (obj.offsetParent) {
            trueOffset += obj.offsetLeft;
            obj = obj.offsetParent; 
        }
    }
    return trueOffset;
}

function g_getTrueOffsetTop(obj) {
    var trueOffset = 0;
    if (obj != null) {
        while (obj.offsetParent) {
            trueOffset += obj.offsetTop;
            obj = obj.offsetParent; 
        }
    }
    return trueOffset;
}

function ObjectDimension(left, top, width, height) {
    
    // private members
    var _this = this;
    this.left = left;
    this.top = top;
    this.right = left + width;
    this.bottom = top + height;
    
    // private methods
    function isCoordinateOverlap(x, y) {
      return (_this.left <= x && _this.right >= x && _this.top <= y && _this.bottom >= y);
    }

    // privileged methods
    this.isCornersOverlap = function (other) {
      return (isCoordinateOverlap(other.left, other.top)
              || isCoordinateOverlap(other.right, other.top)
              || isCoordinateOverlap(other.left, other.bottom)
              || isCoordinateOverlap(other.right, other.bottom));
    }
    
    this.isOverlap = function (other) {
      return (this.isCornersOverlap(other) || other.isCornersOverlap(this));
    }
}

function getObjectDimension(obj) {
    if (obj == null) {
      return null;
    }
    
    // Requires global_js.jsp 
    return new ObjectDimension(g_getTrueOffsetLeft(obj), g_getTrueOffsetTop(obj), obj.offsetWidth, obj.offsetHeight);
}

function applyParametricSort(f) {
    
    var sort = g_getObj("s");
    var sortValue = "";
    
    if (sort != null) {
        sortValue = sort[sort.selectedIndex].value;
        f.action += "&s=" + sortValue;
    }

    self.location.href = f.action; 
    
    return false;
}

function hideAllExpandMore() {
    var expandMoreElems = g_getObjectsByName("div", "expandMore");
    for (var i = 0, n = expandMoreElems.length; i < n; i++) {
        g_hideObj(expandMoreElems[i]);
        expandMoreElems[i].style.zIndex = -100;
        toggleDropDowns(expandMoreElems[i], false);
    }
}

function showParametricMoreValues(attrName) {
    g_hideObj("more_" + attrName);
    
    var moreContent = g_getObjectsByName("p", "moreContent_" + attrName);
    if (moreContent != null) {
        for (var i = 0; i < moreContent.length; i++) {
            g_showObj(moreContent[i], "block");            
        }
    }
}

function showParametricExpandMoreValuesWithAjax(categoryId,filterUrl,attrName){
        if(g_getObj("expandMoreContent_" + attrName)==null){
                //get the extra module data via ajax
		var url = '/include/parametricModulesAjax.jsp';
		var pars = 'categoryId=' + categoryId + '&parametricFilterBaseUrl=' + filterUrl + '&moduleName=' + attrName;
		new Ajax.Request(url,{method: 'post',postBody: pars,onSuccess:function(transport){var holder= document.createElement("div");holder.innerHTML=transport.responseText;$("leftnav_container").appendChild(holder);showParametricExpandMoreValues(attrName);}});
	}else{
		showParametricExpandMoreValues(attrName);
	}
}

function showParametricExpandMoreValues(attrName) {
    
    hideAllExpandMore();

    var module = g_getObj("module_" + attrName);
    var expandMore = g_getObj("expandMore_" + attrName);
    var expandMoreContent = g_getObj("expandMoreContent_" + attrName);
    var positioner = null;
    var heightAdjuster = null;
    
    if (module.style.cssFloat == "left") { // horizontal alignment
        positioner = g_getObj("parametricFilters");
        heightAdjuster = g_getObj("modules");
    } else { // vertical alignment
        positioner = module;
        heightAdjuster = module;
    }

    expandMore.style.zIndex = 100;
    expandMore.style.position = "absolute";
    expandMore.style.top = g_getTrueOffsetTop(positioner) + "px";
    expandMore.style.left = g_getTrueOffsetLeft(positioner) + "px";

    g_showObj(expandMore, "block");
    
    if (expandMoreContent.offsetHeight < heightAdjuster.offsetHeight) {
        expandMoreContent.style.height = "auto";
        expandMoreContent.style.height = heightAdjuster.offsetHeight + "px";
    }

    toggleDropDowns(expandMore, true);
}

function toggleDropDowns(expandMore, isHiding) {
    var allDropDowns = document.getElementsByTagName("select");
    
    if (allDropDowns != null) {

        var expandMoreDimension = getObjectDimension(expandMore);
        var dropDownDimension;
        
        for (var i = 0, n = allDropDowns.length; i < n; i++) {
            if (isHiding) {
                dropDownDimension = getObjectDimension(allDropDowns[i]);
            
                if (dropDownDimension.isOverlap(expandMoreDimension)) {
                    g_hideObj(allDropDowns[i]);
                } 
            } else {
                g_showObj(allDropDowns[i]);
            }
        }
    }
}






//deprecated
function hideExpandMoreParametricValues(attrName) {
 var expandMore = g_getObj("expandMore_" + attrName);
 g_hideObj(expandMore);
 expandMore.style.zIndex = -100;
 toggleDropDowns(expandMore, false);
}

//deprecated
function showExpandMoreParametricValues(sourceElem, attrName) {
 
 hideAllExpandMore();
 
 var expandMore = g_getObj("expandMore_" + attrName);
 var expandMoreContent = g_getObj("expandMoreContent_" + attrName);
 var filterContainer = null;
 var filterContent = null;
 
 if (sourceElem > "") {
     filterContainer = g_getObj("filterContainer_" + sourceElem);
     filterContent = filterContainer;
 } else {
     filterContainer = g_getObj("pfct");
     filterContent = g_getObj("pfContent");
 }
 
 expandMore.style.zIndex = 100;
 expandMore.style.position = "absolute";
 expandMore.style.top = g_getTrueOffsetTop(filterContainer) + "px";
 expandMore.style.left = g_getTrueOffsetLeft(filterContainer) + "px";
 
 g_showObj("expandMore_" + attrName);
 
 if (expandMoreContent.offsetHeight < filterContent.offsetHeight) {
     expandMoreContent.style.height = "auto";
     expandMoreContent.style.height = filterContent.offsetHeight + "px";
 }
 toggleDropDowns(expandMore, true);
}

//deprecated
function showMoreParametricValues(attrName) {
 g_hideObj("moreLink_" + attrName);
 g_showObj("moreData_" + attrName);
}

function removeUnwantedCharacters(searchField)
{
	var invalidchars=Array("~","#","}","{","'","!","@","$","%","^","&","*","(",")","-","_","+","=","{","}","[","]","\\","|",":",";","\"","'",",","<",".",",",">","?","/");
	var searchterm=Trim(searchField.value);
	if(searchterm.length == 1 )
	{
		for(var i=0;i<invalidchars.length;i++)
		{
			if(searchterm==invalidchars[i])
			{
				searchField.value="";
				return;
			}
		}
	}
	searchField.value = searchField.value.replace(" - "," ");
}
function verifySearchTerm(searchFieldId) {
    var searchField = g_getObj(searchFieldId);
    removeUnwantedCharacters(searchField);  	
    if (searchField == null) {
	window.alert("You must enter an item or topic in the search field.");
	return false;
    } else if (Trim(searchField.value).length == 0 ) {
	window.alert("You must enter an item or topic in the search field.");
	return false;
    }    
    return true;
}

function Trim(str) { 
	while(str.charAt(0) == (" ")){ 
		str = str.substring(1);
	}
	while(str.charAt(str.length-1) == " " ){ 
		str = str.substring(0,str.length-1);
	}
	return str;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
