d = document;
ie = (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) ? true : false;

var JS = {

	/* COMMON FUNCTIONS 
	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */

	/* ---------------------------------------------------------
	   Name:   Event Listener
	   Args:   obj (object) - object to attach event to (e.g. document),
	           evType (string) - event type (e.g. "load"),
			   fn (function) - function, which will handle the event
	   Author: Scott Andrew
	   URL:    http://scottandrew.com
	   Notes:  edited by Mark Wubben, <useCapture> is now set to false
	 ---------------------------------------------------------*/
	
	addEvent: function (/* object */ obj, /* string */ evType, /* function */ fn) {
		if(obj.addEventListener){
			obj.addEventListener(evType, fn, true); 
			return true;
		} else if (obj.attachEvent){
			var r = obj.attachEvent('on'+evType, fn);
			return r;
		} else {
			return false;
		}
	},

	/* IMAGES
	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
	
	Images: {
		
		/* ---------------------------------------------------------
		   Name:   Proper IE PNG handler
		   Args:   -
		   Author: Few talented webdesigners ;)
		   URL:    http://dsandler.org, http://www.youngpup.net/?request=/snippets/sleight.xml, http://www.allinthehead.com/retro/69
		   Notes:  -
		 ---------------------------------------------------------*/
		
		enableAlphaImages: function () {
			if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
				var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
				var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
				if (itsAllGood) {
					for (var i=0; i<document.all.length; i++){
						var obj = document.all[i];
						var bg = obj.currentStyle.backgroundImage;
						var img = document.images[i];
						if (bg && bg.match(/\.png/i) != null) {
							var img = bg.substring(5,bg.length-2);
							var offset = obj.style["background-position"];
							obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='crop')";
							obj.style.backgroundImage = "url('blank.gif')";
							obj.style["background-position"] = offset; // reapply
						} else if (img && img.src.match(/\.png$/i) != null) {
							var src = img.src;
							img.style.width = img.width + "px";
							img.style.height = img.height + "px";
							img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='crop')"
							img.src = "blank.gif";
						}
					}
				}
			}
		}
	},

	/* TABLES
	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */

	Tables: {
		
		/* ---------------------------------------------------------
		   Name:   Alternate rows classes for IE + hover class
		   Args:   parentObj (object) - parent object for the tables to attach alt rows to,
		           altClass (string) - alternative row class name,
				   hoverClass (string) - hover row class name
		   Author: Kamil Pełka
		   URL:    http://kamilpelka.com/
		   Notes:  -
		 ---------------------------------------------------------*/
		
		enableAltRows: function ( /* object */ parentObj , /* string */ altClass , /* string */ hoverClass ) {
			data_tables = parentObj.getElementsByTagName("table");
			// Loopin through all tables
			for (var i=0;i<data_tables.length;i++) {
				
				table_rows = data_tables[i].getElementsByTagName("tr");
				
				//Loopin through all rows in a table
				for (var j=0;j<table_rows.length;j++) {
					tds = table_rows[j].getElementsByTagName("td");
					if (tds.length > 0) {
						if ((altClass != "") && (j % 2 != 0)) {
							if (table_rows[j].className != '') {
								table_rows[j].className = table_rows[j].className + " alt";
							} else {
								table_rows[j].className = "alt";
							};
						}
						if (hoverClass != "") {
							table_rows[j].onmouseover = function() {
								eval("this.oldClassName = this.className;");
								eval("this.className = '"+hoverClass+"';");
							}
							table_rows[j].onmouseout = function() {
								eval("this.className = this.oldClassName;");
							}
						}
					}
				}
			}
		}
	},

	/* DHTML
	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */

	DHTML: {

		interval: 40,
		running: false,
		tween: 5,
		
		/* ---------------------------------------------------------
		   Name:   Resize (originally - Animate)
		   Args:   elId (string) - ID of the object to resize,
		           newWidth (integer) - target width of the object (in px),
				   newHeight (integer) - target height of the object (in px)
		   Author: John Serris (a.k.a JB)  
		   URL:    http://phonophunk.phreakin.com/
		   Notes:  Edited and modified by Kamil Pełka (http://kamilpelka.com)
		 ---------------------------------------------------------*/
		
		resize: function(elId, newWidth, newHeight) {
			var h = d.getElementById(elId);
			if (this.running) {
				var c = parseInt(h.offsetHeight,10);
				var e = parseInt(h.offsetWidth,10);

				if (e < newWidth) {
					var fWidth = Math.ceil(e+((newWidth-e)/this.tween));

					if (fWidth >= (newWidth-1)) {
						h.style.width = newWidth + "px";
					} else {
						h.style.width = fWidth + "px";
					}
				} else if (e > newWidth) {
					var fWidth = Math.floor(e-((e-newWidth)/this.tween));
					if (fWidth <= (newWidth+1)) {
						h.style.width = newWidth + "px";
					} else {
						h.style.width = fWidth + "px";
					}
				}

				if (c < newHeight) {
					var fHeight = Math.ceil(c+((newHeight-c)/this.tween));

					if (fHeight >= (newHeight-1)) {
						h.style.height = newHeight + "px";
					} else {
						h.style.height = fHeight + "px";
					}
				} else if (c > newHeight) {
					var fHeight = Math.floor(c-((c-newHeight)/this.tween));
					if (fHeight <= (newHeight+1)) {
						h.style.height = newHeight + "px";
					} else {
						h.style.height = fHeight + "px";
					}
				}

				if ( (c == newHeight) && (e == newWidth) ) {
					clearInterval(this.timer);
					this.running = false;
					this.timer = null;
				}

			} else {
				this.running = true;
				this.timer = setInterval("JS.DHTML.resize('" + elId + "'," + newWidth + ", " + newHeight + ")",this.interval);
			}
		}
	},

	/* COOKIES
	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */

	Cookies: { 
	
		/* ---------------------------------------------------------
		   Name:   Cookie setter
		   Args:   name (string) - cookie name,
		           val (mixed) - cookie value,
				   days (integer) - how many days the cookie will remain valid
		   Author: John Serris (a.k.a JB)
		   URL:    http://phonophunk.phreakin.com/
		   Notes:  -
		 ---------------------------------------------------------*/
		
		set: function(name,val,days) {
			var expires = "";
			if (days) {
				var date = new Date();
				date.setTime(date.getTime() + (days*24*60*60*1000));
				expires = "; expires=" + date.toGMTString();
			}
			d.cookie = name + "=" + val + expires + "; path=/";
		},

		/* ---------------------------------------------------------
		   Name:   Cookie getter
		   Args:   name (string) - cookie name
		   Author: John Serris (a.k.a JB)
		   URL:    http://phonophunk.phreakin.com/
		   Notes:  -
		 ---------------------------------------------------------*/

		get: function(name) {
			name = name + "=";
			var cs = d.cookie.split("; ");
			for (var i = 0, cv; cv = cs[i]; i++) {
				if (cv.indexOf(name) == 0) {
					return cv.substring(name.length,cv.length);
				}
			}
			return null;
		}
	},

	/* AJAX
	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */

	Ajax: new XHConn()
}

/* PRIVATE */

/* ---------------------------------------------------------
   Name:   XHConn
   Args:   -
   Author: Brad Fults
   URL:    http://xkr.us/code/javascript/XHConn/
   Notes:  -
 ---------------------------------------------------------*/

function XHConn() {
	var xmlhttp, bComplete = false;
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) { try { xmlhttp = new XMLHttpRequest(); }
	catch (e) { xmlhttp = false; }}}
	if (!xmlhttp) return null;
	this.connect = function(sURL, sMethod, sVars, fnDone) {
		if (!xmlhttp) return false;
		bComplete = false;
		sMethod = sMethod.toUpperCase();
		try {
			if (sMethod == "GET") {
				xmlhttp.open(sMethod, sURL+"?"+sVars, true);
				sVars = "";
			} else {
				xmlhttp.open(sMethod, sURL, true);
				xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
				xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			}
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && !bComplete) {
					bComplete = true;
					fnDone(xmlhttp);
				}
			};
			xmlhttp.send(sVars);
		}
		catch(z) { return false; }
		return true;
	};
	return this;
}