/* ***********************************************************************************
	Prototype JavaScript framework, version 1.5.1.2
	(c) 2005-2008 Sam Stephenson - http://www.prototypejs.org/
	'getElementsByClassName' modified from Prototype 1.5.1.2
*********************************************************************************** */
if (!document.getElementsByClassName) {
	if (document.evaluate) { // check to see if the browser features XPath
		document._getElementsByXPath = function(expression, parentElement) {
			var results = [];
			var query = document.evaluate(expression, document.getElementById(parentElement) || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			for (var i = 0,
			length = query.snapshotLength; i < length; i++) {
				results.push(query.snapshotItem(i));
			}
			return results;
		};
		document.getElementsByClassName = function(className, parentElement) {
			var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";
			return document._getElementsByXPath(q, parentElement);
		};
	} else {
		document.getElementsByClassName = function(className, parentElement) {
			var children = (document.getElementById(parentElement) || document.body).getElementsByTagName('*');
			var elements = [],
			child,
			pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
			for (var i = 0,
			length = children.length; i < length; i++) {
				child = children[i];
				var elementClassName = child.className;
				if (elementClassName.length === 0) {
					continue;
				}
				if (elementClassName === className || elementClassName.match(pattern)) {
					elements.push(child);
				}
			}
			return elements;
		};
	}
}

/* ***********************************************************************************

	CJ Panel Effect JavaScript framework, v1.1

	Copyright (c) 2008, Doug Jones. All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions
	are met:
	
	a) Redistributions of source code must retain the above copyright
	   notice, this list of conditions and the following disclaimer.
	  
	b) Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution. 
	  
	c) Neither the name of the Creative Juices, Bo. Co. nor the names of its
	   contributors may be used to endorse or promote products derived from
	   this software without specific prior written permission.
	
	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
	"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
	LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
	A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
	OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
	LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
	DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
	THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
	OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	
	For further information, visit the Creative Juices website: www.cjboco.com.
	
	Description: This framework will scan your HTML document for elements
				 with as a class name of "CJ_Hover_Effect". Once found it 
				 will attach events to fade the element in and out on any
				 mouseover and mouseout events.
				 
				 Additionally, to trigger the effect with another link, it
				 will scan for links with a class name "CJ_Panel_Trigger".
				 If the number of links MUST equals that of the panels,
				 it will then automatically trigger the effect.
	
	Change Log:
	------------------------------------------------------------------------
	10-28-2008 - 	Added a trigger action for secondary links.
					General code clean-up,
				 

*********************************************************************************** */

var CJPanelEffect = {

	version: '1.1',
	elemClassName: 'CJ_Panel_Effect',
	triggerClassName: 'CJ_Panel_Trigger',

	hoverEffect: function() {
		this.prefs = {
			speed: 10,
			amount: parseFloat(0.05),
			minimum: parseFloat(0.0),
			transparency: parseFloat(0.0),
			type: null,
			timer: null
		};
		this.setOpacity = function(o) {
			if (!o._CJPanelEffect.prefs.transparency) {
				return;
			}
			if (o._CJPanelEffect.prefs.transparency > 1.0) {
				o._CJPanelEffect.prefs.transparency = 1.0;
				return;
			}
			o.style.opacity = o._CJPanelEffect.prefs.transparency;
			o.style.MozOpacity = o._CJPanelEffect.prefs.transparency;
			o.style.filter = "alpha(opacity=" + (o._CJPanelEffect.prefs.transparency * 100) + ")";
		};
		this.fade = function(o, t) {
			var _this = o._CJPanelEffect;
			var op = _this.prefs.transparency;
			var f = function() {
				_this.fade(o, t);
			};
			if (t === "mouseover") {
				if (_this.prefs.timer && _this.prefs.type !== "mouseover") {
					clearTimeout(_this.prefs.timer);
				}
				_this.prefs.transparency = _this.prefs.transparency - _this.prefs.amount < _this.prefs.minimum ? parseFloat(_this.prefs.minimum) : parseFloat(_this.prefs.transparency - _this.prefs.amount);
				_this.setOpacity(o);
				if (_this.prefs.transparency > _this.prefs.minimum) {
					_this.prefs.type = "mouseover";
					_this.prefs.timer = setTimeout(f, parseInt(_this.prefs.speed, 10));
				}
			} else if (t === "mouseout") {
				if (_this.prefs.timer && _this.prefs.type !== "mouseout") {
					clearTimeout(_this.prefs.timer);
				}
				_this.prefs.transparency = _this.prefs.transparency + parseFloat(_this.prefs.amount * 2) > 1 ? parseFloat(1.0) : parseFloat(_this.prefs.transparency + parseFloat(_this.prefs.amount * 2));
				_this.setOpacity(o);
				if (_this.prefs.transparency < 1) {
					_this.prefs.type = "mouseout";
					_this.prefs.timer = setTimeout(f, parseInt(_this.prefs.speed / 2, 10));
				}
			}
		};
	},
	addEvent: function(e, t, fn, c) {
		if (e.addEventListener) {
			e.addEventListener(t, fn, c);
			return true;
		} else if (e.attachEvent) {
			var r = e.attachEvent('on' + t, fn);
			return r;
		} else {
			e['on' + t] = fn;
		}
	},
	init: function() {
		if (!document.getElementById || !document.createElement || !document.getElementsByTagName('body')[0].offsetWidth) {
			return;
		}
		var os = document.getElementsByClassName(CJPanelEffect.elemClassName);
		var ts = document.getElementsByClassName(CJPanelEffect.triggerClassName);
		for (var j in os) {
			if (os[j]) {
				var o = os[j];
				if (o.className === CJPanelEffect.elemClassName) {
					var f, i;
					o.style.position = "relative";
					if (o.childNodes[0] && o.childNodes[0].nodeName === "IMG") {
						o.childNodes[0].style.position = "absolute";
						o.childNodes[0].style.top = "0px";
						o.childNodes[0].style.left = "0px";
						o.childNodes[0].style.zIndex = "0";
						i = o.childNodes[0].src;
					} else {
						alert("There was a problem initializing CJ Panel Effect v" + CJPanelEffect.version);
						return;
					}
					// Create the hover element
					var ho = document.createElement('div');
					ho.style.position = "absolute";
					ho.style.top = "0px";
					ho.style.left = "0px";
					ho.style.display = "block";
					ho.style.width = o.offsetWidth + "px";
					ho.style.height = o.offsetHeight + "px";
					ho.style.zIndex = "1";
					ho.style.background = "url(" + i.replace(new RegExp(".(jpg|gif|png)", "g"), "_grey.$1") + ") no-repeat top left";
					ho._CJPanelEffect = new CJPanelEffect.hoverEffect();
					ho._CJPanelEffect.prefs.transparency = 1;
					ho.setAttribute("id", "CJ_Panel_Block_" + j);
					f = function() {
						return function(e) {
							var event = !e ? window.event: e;
							this._CJPanelEffect.fade(this, e.type);
						};
					} ();
					CJPanelEffect.addEvent(ho, 'mouseover', f, false);
					CJPanelEffect.addEvent(ho, 'mouseout', f, false);
					f = function() {
						return function(e) {
							var event = !e ? window.event: e;
							if (this._CJPanelEffect && this._CJPanelEffect.prefs.timer) {
								clearTimeout(this._CJPanelEffect.prefs.timer);
							}
							if (this._CJPanelEffect.prefs.transparency < 1) {
								this._CJPanelEffect.prefs.transparency = 1.0;
								this._CJPanelEffect.setOpacity(this);
							}
						};
					} ();
					CJPanelEffect.addEvent(ho, 'click', f, false);
					o.appendChild(ho);
					if (ts.length === os.length && ts[j]) {
						var _this = document.getElementById('CJ_Panel_Block_' + j);
						f = function() {
							var _this = document.getElementById('CJ_Panel_Block_' + j);
							return function(e) {
								var event = !e ? window.event: e;
								_this._CJPanelEffect.fade(_this, e.type);
							};
						} ();
						CJPanelEffect.addEvent(ts[j], 'mouseover', f, false);
						CJPanelEffect.addEvent(ts[j], 'mouseout', f, false);
						f = function() {
							var _this = document.getElementById('CJ_Panel_Block_' + j);
							return function(e) {
								var event = !e ? window.event: e;
								if (_this._CJPanelEffect && _this._CJPanelEffect.prefs.timer) {
									clearTimeout(_this._CJPanelEffect.prefs.timer);
								}
								if (_this._CJPanelEffect.prefs.transparency < 1) {
									_this._CJPanelEffect.prefs.transparency = 1.0;
									_this._CJPanelEffect.setOpacity(_this);
								}
							};
						} ();
						CJPanelEffect.addEvent(ts[j], 'click', f, false);
					}
				}
			}
		}
	}
};

CJPanelEffect.addEvent(window, 'load', CJPanelEffect.init, false);