var urlPath = 'http://cadc.auburn.edu/graphicdesign/';
var sitePath = urlPath + 'templates/publicparking/';
var uploadPath = urlPath + 'u_images/m4rg0vmdg/';

Array.prototype.inArray = function (a) {
	var i;
	for (i=0; i < this.length; i++) if (this[i] == a) return true;
	return false;
}


/* DOM Functions */

function getElement(a) {	return ((document.getElementById) ? document.getElementById(a) : eval("document.all."+a));}

function getFind(a, b, c, d, e){
	if (!e || e == "") e = false;
    var f = ((b == "*" && a.all) ? a.all : a.getElementsByTagName(b));
    var r = new Array();
    var q = ((typeof d != "undefined") ? new RegExp("(^|\\s)" + d + ((e) ? ".*" : "") + "(\\s|$)") : null);
    for (var i=0; i<f.length; i++){
        var p = objGetAttr(f[i], c);
        if (p && p != "" && ((!d || d == "") || (q && q.test(p)))) r.push(f[i]);
    }
    return r;
}

function removeElement(e) {((em = getElement(e)) ? em.parentNode.removeChild(em) : e.parentNode.removeChild(e));}

function addEvent(elm, evType, fn, useCapture) {
	if (evType == "DOM") {
		return new domFunction(fn, useCapture);
	} else 	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		return elm.attachEvent("on"+evType, fn)
	}
	return false;
} 

function domFunction(f, a) {
	var n = 0;
	var t = setInterval(function() {
		var c = true;
		n++;
		if (typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)) {
			c = false;
			if (typeof a == 'object') {
				for (var i in a) {
					if ((a[i] == 'id' && getElement(i) == null) || (a[i] == 'tag' && document.getElementsByTagName(i).length < 1)) {c = true; break;}
				}
			}
			if(!c) { f(); clearInterval(t); }
		}
		if(n >= 60) clearInterval(t);
	}, 250);
}

function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

/* Replacement Functions */
String.prototype.remove = function (a) {
	var b = this.indexOf(a);
	if (b == -1) return this;
	return this.substring(0,b) + this.substring(b + a.length).remove(a);
}

Object.prototype.getAttr = function(a) {return objGetAttr(this, a);}
function objGetAttr(a, b) {
	if (typeof a != "object") return false;
	return (b == "class") ? a.className : (b == "href") ? a.href : (b == "src") ? a.src : (b == "value") ? a.value : a.getAttribute(b);
}




/* Browser Detection */
var browser = {
	events: function() {
		this.compliance();
	},
	compliance : function() {
		// Style Compliance Overrides
		if (browser.os == "Mac" && browser.browser != "Safari") document.write('<link rel="stylesheet" href="'+sitePath+'css/mac.css" media="all" />');
		if (browser.browser == "Safari") document.write('<link rel="stylesheet" href="'+sitePath+'css/safari.css" media="all" />');
		if (browser.browser == "Explorer") document.write('<link rel="stylesheet" href="'+sitePath+'css/ie'+ ((browser.version < 7) ? '6' : '') +'.css" media="all" />');
	},
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "unknown browser";
		this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || false;
		this.os = this.searchString(this.dataOS) || "unknown os";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if ((dataString && dataString.indexOf(data[i].subString) != -1) || dataProp) return data[i].identity;
		}
		return false;
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb"},
		{string: navigator.vendor, subString: "Apple", identity: "Safari", versionSearch: "Version"},
		{prop: window.opera, identity: "Opera"},
		{string: navigator.vendor, subString: "iCab", identity: "iCab"},
		{string: navigator.vendor, subString: "KDE", identity: "Konqueror"},
		{string: navigator.userAgent, subString: "Firefox", identity: "Firefox"},
		{string: navigator.vendor, subString: "Camino", identity: "Camino"},
		// for newer Netscapes (6+)
		{string: navigator.userAgent, subString: "Netscape", identity: "Netscape"},
		{string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE"},
		{string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv"},
		// for older Netscapes (4-)
		{string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla"}
	],
	dataOS : [
		{string: navigator.platform, subString: "Win", identity: "Windows"},
		{string: navigator.platform, subString: "Mac", identity: "Mac"},
		{string: navigator.platform, subString: "Linux",identity: "Linux"}
	]

};

/* Run object checks */
browser.init();
browser.events();


// Attribute Selector Effects
// ------------------------------------------------------------------
// Developed by Greg Leuch, Virticle Corp (2007 January 02)
// (C) 2007 Virticle Corp <www.virticle.com> -- All Rights Reserved.
// DO NOT USE WITHOUT PERMISSION - FAILURE TO USE WIHTOUT PERMISSION
// WILL RESULT IN LEGAL AND CIVIL ACTIONS.
// ------------------------------------------------------------------
// Works in Gecko 1+ (Firefox/Mozilla/NS7+), Opera 7+, and IE7+.
// CSS use by using "class" attribute is tricky in earlier browsers.
//
// Searches through attribute values under specified element
// to find rollover instances.
//
// Use: <tag attr="-effect- src:-imgsrc-">
// Recommended: Use "class" attribute for XHTML Compliance and CSS
// styling options.
//
// Can be used with multiple attribute values.
// Ex. class="classname -effect-- src:-imgsrc-"
// (To ensure compatibility with all browsers supporting JavaScript,
// place required classname first, then rollover "classes")
//
// Can also be located for styling via CSS2 selectors
// Use: <style>*[attr~="-effect-"] {-code-}</style>
// ------------------------------------------------------------------
// Updated: 2007-05-21
//  - return only objects to defined function in locate()
// Updated: 2007-06-07
//	- added PNG replacement code for IE6 and earlier (via browser[])
//  - added "child" node identification for imgover
//  - added PNG support for imgover

var attributeEffects = {
	start : function () {
		// Use: this.set(-attr-, -effect-, -func-, [-opt-...]);
		if (browser.browser == "Explorer" && browser.version < 7) this.locate("src", "((png)$)$", "replacePNG", false, true);
		this.locate("class", "ro", "imgover");
		this.locate("class", "mo", "classover");
		this.locate("class", "rollover", "imgover", "this");
		this.locate("class", "hoverover", "imgover", "child");
		this.locate("class", "lightbox", "lightbox");
	},

	// Image Rollover Effects
	imgover : function (a, b, c, d, e) {
		if (a && e && e != null) {
			var g = new RegExp("([\\S\\s]*)("+ b +" s:)([\\S]*)([\\S\\s]*)");
			var h = e.replace(g, "$3");
			if (e != h && h != "") {
				h = h.split(":");
				var i = new RegExp("((\.png)$)$");
				var j = (i.test(h[0]) && (browser.browser == "Explorer" && browser.version < 7));
				if (j) 	var k = new RegExp("(^|[\\S\\s]*)(src=')([\\S]*)(')([\\S\\s]*|$)");

				a = ((h[1] == 'p') ? a.parentNode : ((h[1] == "g") ? a.parentNode.parentNode : a));
				a.h = ((j) ? ((h[1] == 'g') ? a.childNodes[0].childNodes[0].style.filter.replace(k, $3) : ((h[1] == 'c') ? a.childNodes[0].style.filter.replace(k, "$3") : a.style.filter.replace(k, "$3"))) : ((h[1] == 'g') ? a.childNodes[0].childNodes[0].src : ((h[1] == 'c') ? a.childNodes[0].src : a.src)));
				if (!a.h || a.h == "") return;
				a.j = ((h[2] == "u") ? uploadPath : sitePath+'images/') +h[0];
				a.l = ((h[1] == "g") ? eval(a.childNodes[0].childNodes[0]) : ((h[1] == "c") ? eval(a.childNodes[0]) : eval(a)));

				a.i = attributeEffects.imgov.length;
				attributeEffects.imgov[a.i] = new Image();
				attributeEffects.imgov[a.i].i = a.i;
				attributeEffects.imgov[a.i].l = a.l;
				attributeEffects.imgov[a.i].m = false;
				attributeEffects.imgov[a.i].n = j;
				attributeEffects.imgov[a.i].onload = function() {((this.m) ? ((this.n) ? this.l.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='crop', src='"+ this.src +"'" : this.l.src = this.src) : ''); this.m = false; return true;};
				if (browser.browser != 'Safari') attributeEffects.imgov[a.i].src = a.j;

				a.onmouseover = function() {if (browser.browser == 'Safari' && (!browser.version || browser.version < 3)) {this.l.src= this.j;} else {attributeEffects.imgov[this.i].m = true; attributeEffects.imgov[this.i].src = this.j;}};
				a.onmouseout = function() {if (browser.browser == 'Safari' && (!browser.version || browser.version < 3)) {this.l.src = this.h;} else {attributeEffects.imgov[this.i].m = true; attributeEffects.imgov[this.i].src = this.h;}};
			}
		}
	},
	imgov : [],

	// Image Rollover Effects
	classover : function (a, b, c, d, e) {
		if (a && e && e != null) {
			var g = new RegExp("([\\S\\s]*)("+ b +" c:)([\\S]*)([\\S\\s]*)");
			var h = e.replace(g, "$3");
			if (e != h && h != "") {
				a.h = h.split(":");
				
				b = ((a.h[1] == "parent") ? a.parentNode : a);
				b.a = a;
				b.b = a.style.backgroundImage;
				b.d = a.h[1];
				b.onmouseover = function() {this.a.className='over';//this.a.style.backgroundImage = 'url('+this.c+')';
				};
				b.onmouseout = function() {this.a.className='';//this.a.style.backgroundImage = 'url('+this.b+')';
				};
			}
		}
	},


	// Product Rollover Lightbox
	lightbox : function (a, b, c, d, e) {
		if (a && e && e != null) {
			var g = new RegExp("([\\S\\s]*)("+ b +" lb:)([\\S]*)([\\S\\s]*)");
			var h = e.replace(g, "$3").split(":::");
			var z = getElement("prod_lightbox");
			if (e != h[1] && h[0] != "" && h[1] != "" && z) {
				var l = a.parentNode;
				l.t = a.title;
				l.o = this.getOffset(((h[0] == "info") ? l : l.parentNode), true, true);
				l.h = h;
				z.isOpen = false;
				z.isClose = false;
				z.cur = false;
				l.z = z;

				document.onmousemove = attributeEffects.lb_move;

				if (l.href == (urlPath+h[1])) l.onclick = function() {return false;}
				a.title = "";

				l.onmouseover = attributeEffects.lb_on;
				l.onmouseout = attributeEffects.lb_off;
				//l.move = this.lb_move;

				var r;
				if (r = getElement("prod_enlarge")) {
					if (r.childNodes[0]) {
						r = r.childNodes[0];
						r.isOpen = l.isOpen;
						r.t = l.t;
						r.o = l.o;
						r.z = z;
						r.onmouseover = this.lb_on;
						r.onmouseout = this.lb_off;
						if (r.childNodes[0]) r.childNodes[0].title = "";
						if (l.href == (urlPath+h[1])) r.onclick = function() {return false;}
					}
				}
			}
		}
	},
	lbselects : function(a) {
		selects = document.getElementsByTagName("select");
        for (i=0; i!=selects.length; i++) selects[i].style.visibility = a;
	},
	lb_on : function(e) {
		if (!this.z.isOpen) {
			if (!this.z.isClose || this.z.cur != this.h[1]) this.z.style.visibility = "hidden";
			this.z.isOpen = true;
			this.z.isClose = false;
			if (this.z.cur != this.h[1]) this.z.innerHTML = "<img src=\""+ this.h[1] +"\""+ ((this.h[2] > 0) ? " width=\""+ this.h[2] +"\"" : "") + ((this.h[3] > 0) ? " height=\""+ this.h[3] +"\"" : "") +" title=\""+ this.t +"\" alt=\"\" />";
			this.z.cur = this.h[1];
			if (browser.browser == "Explorer" && browser.version < 7) attributeEffects.lbselects("hidden");
			this.z.style.display = "block";
			this.z.style.top = (this.o[1]-10)+"px";
			this.z.style.left = attributeEffects.lb_move(e);
		}
	},
	lb_off : function() {
		this.z.isOpen = false;
		this.z.isClose = true;
		this.z.cur = false;
		pause(50);
		if (!this.z.isOpen || this.z.isClose) {
			this.z.isClose = false;
			this.z.style.display = "none";
			if (browser.browser == "Explorer" && browser.version < 7) attributeEffects.lbselects("visible");
		}
	},
	lb_move : function(e) {
		if (!this.z) this.z = getElement("prod_lightbox");
		var a = -10;
		var b = 10-a;
		var c = ((document.all) ? pageBody().scrollLeft+pageBody().clientWidth : pageXOffset+window.innerWidth-15);
		a = ((typeof e != "undefined") ? (a+e.pageX) : (a+pageBody().scrollLeft+event.clientX));
		this.z.style.left = (((a-this.z.offsetWidth) > 0) ? (a-this.z.offsetWidth) : (b+a))+"px";
		this.z.style.visibility = "visible";
	},

	replacePNG: function(a, b, c, d, e) {
		a.style.width = a.offsetWidth+"px";
		a.style.height = a.offsetHeight+"px";
		a.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='image', src='"+ a.src +"')";
		a.src = sitePath+"images/spacer.gif";
	},


	// Additional required functions
	doFind : function (a, b, c, d) {
		if (!a || a == "") return false;
		var e = (a.all)? a.all : a.getElementsByTagName("*");
		var f = [];
		var g = (typeof c != "undefined") ? new RegExp(((d) ? c : "(^|\\s)" + c +"(\\s|$)")) : null;
		for(var i=0; i<e.length; i++){
			if (e[i] == null) continue;
			var h = objGetAttr(e[i], b);
			if (h && h != "" && ((!c || c == "") || (g && g.test(h)))) f.push(e[i]);
		}
		return f;
	},

	locate : function (a, b, c, d, e, f) {
		var z = this.doFind(getElement(((f && f != "") ? e : "main")), a, b, e);
		if (z.length > 0) for (var i in z) if (typeof z[i] == "object") eval("this."+c+"(z[i], b, a, d, objGetAttr(z[i], a));");
	},

	getOffset : function(e, x, y) {
		x = (x !== true);
		y = (y !== true);
		offsetX = ((e.childNodes[0]) ? e.childNodes[0].offsetLeft+((x) ? e.childNodes[0].offsetWidth : 0) : e.offsetLeft-((x) ? e.offsetWidth : 0));
		offsetY = ((e.childNodes[0]) ? e.childNodes[0].offsetTop+((y) ? e.childNodes[0].offsetHeight : 0) : e.offsetTop-((y) ? e.offsetHeight : 0));
		var p = e.offsetParent;
		r=0;
		while (p) {
			r++;
			offsetX += p.offsetLeft;
			offsetY += p.offsetTop;
			p = p.offsetParent;
		}
		return Array(offsetX, offsetY);
	}
};
function loadAttrEffects() {attributeEffects.start();}
addEvent(window, "DOM", loadAttrEffects);