//jQuery functions
function createSubMenu(){
	newHeight = findPos(document.getElementById($('#MainNav').attr('id'))).y+$('#MainNav').height()-2;
	$('#MainNav li').hover(
		function(){ $('#subnav' + $(this).attr('id')).css('top',newHeight+'px'); },
		function(){ $('#subnav' + $(this).attr('id')).css('top','-999em'); }	
	);
	$('.subnav').hover(
		function(){
			$(this).css('top',newHeight+'px');
			$('#'+$(this).attr('id').substring(6)+' a').addClass('MainNav_hover');
		},
		function(){
			$(this).css("top","-999em");
			$('#'+$(this).attr('id').substring(6)+' a').removeClass('MainNav_hover');
		}
	);
	
}
function findPos(obj) { //returns the x & y coordinates of an element
	var curleft = obj.offsetLeft || 0;
	var curtop = obj.offsetTop || 0;
	while (obj = obj.offsetParent) {
		curleft += obj.offsetLeft
		curtop += obj.offsetTop
	}
	return {x:curleft,y:curtop};
}

function show_hide(id){
	if (document.getElementById){
		var obj = document.getElementById(id);
		if(obj){
			obj.style.display = (obj.style.display == 'none') ? '' : 'none';
		}
	}
}

function pd_show_hide(id){
        if (document.getElementById){
                var obj = document.getElementById(id);
                if(obj){
                        obj.style.display = (obj.style.display == 'none') ? '' : 'none';
                }
        }
}

function change_elem(text,id){
	if (document.getElementById){
		var x = document.getElementById(id);
		if(x){
			x.innerHTML = '';
			x.innerHTML = text;
		}
	}else if (document.all){
		if(x){
			var x = document.all[id];
			x.innerHTML = text;
		}
	}else if (document.layers){
		var x = document.layers[id];
		if(x){
			x.document.open();
			x.document.write(text);
			x.document.close();
		}
	}
}

//EYEPIECE PART (ONLY on the home page)
window.setTimeout("slide_eyepiece()",30000) //first call

var neyepiece = 1;
var do_slide_eyepiece = true;
function slide_eyepiece(){
	if(do_slide_eyepiece){
		nav_eyepiece();
	}
	window.setTimeout("slide_eyepiece()",20000);
}

function nav_eyepiece(what){
	if(what) do_slide_eyepiece = false;
	show_hide('eyepiece' + neyepiece);
	switch(neyepiece){
		case 1:	neyepiece = what=='-'?3:2;	break;
		case 2:	neyepiece = what=='-'?1:3;	break;
		case 3:	neyepiece = what=='-'?2:1;	break;
	}
	change_elem(neyepiece + '/3','eyepiece_count');
	show_hide('eyepiece' + neyepiece);
}
//end EYEPIECE PART

/**
* @package text_resize.js
*
* Functions that increase/decrease text font size based on values retrieved from a cookie.
* This script allows users to change the font size on story pages.
* @version 1.0
* @author Raymond Santucci
* license http://creativecommons.org/licenses/by-sa/2.5/
*
*/

// Set some global variables
origSize = 12; // original font-size if the element does not aleady have one set
minSize = 8; // minimum size we want the user to be able to set
maxSize = 24; // maximum size we want the user to be able to set

/* These are good for relative sizes
origSize = 85; // original font-size if the element does not aleady have one set
minSize = 50; // minimum size we want the user to be able to set
maxSize = 100; // maximum size we want the user to be able to set
*/
elementID = 'storyBody'; // the element to change font-size within
unit = "px"; // unit for font-size [px,ex,em,%,etc]
resize = 2; // amount resize font each time button is hit

// If the element's font-size has been set as an inline style, override the set variable
function getOrigSize() {
	if (!document.all && !document.getElementById) return;  
	var el = document.getElementById ? document.getElementById(elementID) : document.all[elementID];
	if (!el) return;
	el = el.style.fontSize;
	if (el != "") origSize = parseInt(el);
	return;
}

// Change font-size within the element depending on action
function myTextSize(chgsize) {
	if (!document.all && !document.getElementById) return;
	var el = document.getElementById ? document.getElementById(elementID) : document.all[elementID];
	if (!el) return;
	
	var newSize = 0;
	var startSize = parseInt(myGetCookie("my-textsize"));
	if (!startSize) startSize = origSize;
	switch (chgsize) {
		case "incr":	newSize = startSize + resize;		break;
		case "decr":	newSize = startSize - resize;		break;
		case "reset":	newSize = origSize;					break;
		default:		newSize = startSize;				break;
	}  
	if (!newSize) return;
	if (newSize < minSize) newSize = minSize;
	if (newSize > maxSize) newSize = maxSize;
	
	newSize += unit;
	el.style.fontSize = newSize;
	mySetCookie("my-textsize",newSize,365);  
}

// Set cookie to store user-selected font-size
function mySetCookie(name,value,days) {
	var cookie = name + "=" + value + ";";
	if (days) {
		var myDate=new Date();
		myDate.setTime(myDate.getTime()+(days*24*60*60*1000));
		cookie += " expires=" + myDate.toGMTString() + ";";
	}
	cookie += " path=/";
	document.cookie = cookie;
}

// Get cookie containing user-selected font-size
function myGetCookie(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;
}

// Call the functions that will intialize this script
function init() {
	getOrigSize();
	myTextSize();
	return;
}

window.onload=init;





// disallows profane usernames
function returnProfaneList() {
	return 'shit,sh1t,fuck,damn,d4mn,suck,bitch,b1tch,jackass,j4ckass,jack4ss,j4ck4ss';
}

function returnProfaneRegex() {
	var filter = /sh[i1]t|fuck|[a4]s{2,}h[o0]l[e3]|n[i1]g{2,}[a4e3]|j[a4]ck[a4]s|d[a4]m[mn]|suck|b[i1]tch/i;
	return filter;
}

