function addEvent(obj, evType, fn) { if (obj.addEventListener){ obj.addEventListener(evType, fn, false); return true; } else if (obj.attachEvent) { var r = obj.attachEvent('on'+evType, fn); return r; } else { return false; } }
function setCookie(name,value,days) { if (days) { var newDate = new Date(); newDate.setTime(newDate.getTime()+(days*24*60*60*1000)); var expires = "; expires="+newDate.toGMTString(); } else { var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } document.cookie = name+"="+value+expires+"; path=/"; }
function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; }
function deleteCookie(name) { setCookie(name,"",-1); }
// Returns array with page width, height and window width, height (core code from - quirksmode.org, edited for Firefox by pHaez).
function getPageSize(){ var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight) { xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } 	else { xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; }	var windowWidth, windowHeight; if (self.innerHeight) { windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { windowWidth = document.body.clientWidth; 	windowHeight = document.body.clientHeight; } if (yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } if (xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight); return arrayPageSize; }
function windowSize() { var win = { w: 0, h: 0 }; if( typeof( window.innerWidth ) == 'number' ) { win.w = window.innerWidth; win.h = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { win.w = document.documentElement.clientWidth; win.h = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { win.w = document.body.clientWidth; win.h = document.body.clientHeight; } return win; }
function findPosXY(obj) { var objPos = {x:0, y:0}; if (obj.offsetParent) { while (obj.offsetParent) { objPos.x = obj.offsetLeft; objPos.y = obj.offsetTop; obj = obj.offsetParent; } } else if(obj.y) { objPos.x = obj.x; objPos.y = obj.y; } return objPos; }
// Gets the height of a box:
function getHeight(boxID) { var thisBox = $(boxID); if (thisBox) { if (thisBox.offsetHeight) { return thisBox.offsetHeight; } else if (thisBox.style.pixelHeight) { return thisBox.style.pixelHeight; } else { return false; } } return false; }
function insertAfter(newElement,targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) { parent.appendChild(newElement); }
	else { parent.insertBefore(newElement,targetElement.nextSibling); }
}
// Open a custom window :
function open_window(url,name,wth,hgt,inst) {
	if (wth == 'full') { pwindow = window.open(url); }
	else {
		var mywidth = 800; if (wth) { mywidth = wth; }
		var myheight = 600; if (hgt) { myheight = hgt; }
		var myname=''; if (name) { myname = name; }
		var wintype = ',scrollbars=yes,menubar=yes,status=yes'; if (inst && inst == 'plain') { wintype = ',scrollbars=no,menubar=no,status=no'; }
		pwindow = window.open(url,name, 'top=100,left=100,resizable=yes,width='+mywidth+',height='+myheight+wintype)
	}
	pwindow.focus();
}
function popNewWindows() {
	var linkies = document.getElementsByTagName('a');
	var pageDimensions = getPageSize();
	var popWidth = 820;
	var popHeight = (pageDimensions[1]*.75);
	if (pageDimensions[0] < 780) { popWidth = (pageDimensions[0]*.75) }
	for (var l=0; l<linkies.length; l++){
		var linky = linkies[l];
		var linkClass = String(linky.className);
		if (linkClass.indexOf("blank75") > -1) {
			linky.onclick = function () { open_window(String(this.getAttribute('href')),'pop75',popWidth,popHeight,'real'); return false; }
		}
		if (linkClass.indexOf("screenshot") > -1) {
			var gameID = null;
			if (linky.getAttribute('rel')) { gameID = '&gid='+linky.getAttribute('rel'); }
			linky.onclick = function () { open_window(hurl+'/winpop.php?screenshot='+escape(this.getAttribute('href'))+gameID,'screenshot','400','300','plain'); return false; }
		}
		if (linkClass.indexOf("thumb_pop") > -1) {
			linky.onclick = function () { open_window('image_pop.php?image='+this.getAttribute('href'),'thumbpop',100,100,'plain'); return false; }
		}
	}
}
addEvent(window, 'load', popNewWindows);

// Slide (and fade-in) something open (only works if you have moo.fx running as well):
function slideBox(elID,startHeight,endHeight,speed,startOpacity,endOpacity) {
	var slide_box = new fx.Styles(elID, {duration: speed, wait: false});
    if (!startHeight) { startHeight = 1; }
	slide_box.custom({
		'opacity': [startOpacity,endOpacity],
		'height': [startHeight, endHeight]
	});
}

function slider_link(sliderID,startHeight,endHeight,speed,startOpacity,endOpacity,linkID,downText,upText) {
	slideBox(sliderID,startHeight,endHeight,speed,startOpacity,endOpacity);
	$('map_slider_link').setAttribute('href','javascript:slider_link("'+sliderID+'",'+endHeight+','+startHeight+','+speed+',1,1,\''+linkID+'\',\''+downText+'\',\''+upText+'\');');
	if (startHeight < endHeight) {
		$(linkID).className = 'slider_link_up';
		$(linkID).innerHTML = upText;
	}
	else {
		$(linkID).className = 'slider_link_down';
		$(linkID).innerHTML = downText;
	}
}

getStyle = function(elID, cssAtt) {
	var a = document.getElementById(elID);
	var b;
	if (a.currentStyle) { b = a.currentStyle[cssAtt]; }
	else {
		try {
			b = document.defaultView.getComputedStyle(a,null).getPropertyValue(cssAtt);
		} catch(e) { }
	}
	return b;
}

var toggle = function(things,css_display) {
	current_style = getStyle; // Cache function pointer so it won't be looked up every time in loops below.
	if (typeof(things) == 'string') {
		things = (things.indexOf(',') > -1 ? things.split(',') : new Array(things));	
	}
	var thing_count = things.length;
	for (var e = 0; e < thing_count; e++) {
		if (!$(things[e])) { continue; }
		if (current_style(things[e],'display') == 'none') { // If it's OFF, turn it ON:
			$(things[e]).style.display = css_display;
		}
		else { // If it's ON, turn it OFF:
			$(things[e]).style.display = 'none';
		}
	}
}

var holiday_flyer = function() {
	var page = $('three_col');
	var flyer = $('holiday_flyer');
	if (page && flyer) {
		page.appendChild(flyer);
		flyer.style.visibility = 'visible';
		return false;
	}
	return true;
}