/* for subnav */
var write_off = new Image();
write_off.src = "/static/skin/default/img/nav/write_off.gif";
var write_on = new Image();
write_on.src = "/static/skin/default/img/nav/write_on.gif";
var categories_off = new Image();
categories_off.src = "/static/skin/default/img/nav/categories_off.gif";
var categories_on = new Image();
categories_on.src = "/static/skin/default/img/nav/categories_on.gif";
var about_off = new Image();
about_off.src = "/static/skin/default/img/nav/about_off.gif";
var about_on = new Image();
about_on.src = "/static/skin/default/img/nav/about_on.gif";
var troubleshooting_off = new Image();
troubleshooting_off.src = "/static/skin/default/img/nav/troubleshooting_off.gif";
var troubleshooting_on = new Image();
troubleshooting_on.src = "/static/skin/default/img/nav/troubleshooting_on.gif";

var currentMenu = null;
var write_bottom_high = new Image();
write_bottom_high.src = "/static/skin/default/img/nav/write_bottom_high.gif";
var write_bottom = new Image();
write_bottom.src = "/static/skin/default/img/nav/write_bottom.gif";


var subNavArray =  new Array("catsDrop", "aboutDrop", "troubleshootingDrop");
var showPop = false;
var timeOn = null;

function initSubNav() {
	
	for(x=0; x<subNavArray.length; x++) {
		var myMenu = document.getElementById(subNavArray[x]);
		currentTop = parseInt(myMenu.style.top);
	}
	
	showPop = true;
}

 function changeSubBG(cell) {
	if(is.ie5 || is.ie6 || is.ns6) {
		document.getElementById(cell).style.backgroundImage = 'url("/static/skin/default/img/nav/cell_high.gif")';
		document.getElementById(cell+'_bullet').style.backgroundImage = 'url("/static/skin/default/img/nav/cell_high.gif")';
		switch(cell) {
			case "write_link_2":
				document[cell+'_bottom'].src=eval("write_bottom_high.src");
			break;
			case "cats_link_11":
				document[cell+'_bottom'].src=eval("write_bottom_high.src");
			break;
			case "about_link_3":
				document[cell+'_bottom'].src=eval("write_bottom_high.src");
			break;
			case "troubleshooting_link_2":
				document[cell+'_bottom'].src=eval("write_bottom_high.src");
			break;
		default:
			break;
		}
	}
	
}
 
 function removeSubBG(cell) {
	 if(is.ie5 || is.ie6 || is.ns6) {
		 document.getElementById(cell).style.backgroundImage = 'url("")';
		 document.getElementById(cell+'_bullet').style.backgroundImage = 'url("")';
		switch(cell) {
			case "write_link_2":
				document[cell+'_bottom'].src=eval("write_bottom.src");
				break;
			case "cats_link_11":
				document[cell+'_bottom'].src=eval("write_bottom.src");
				break;
			case "about_link_3":
				document[cell+'_bottom'].src=eval("write_bottom.src");
				break;
			case "troubleshooting_link_2":
				document[cell+'_bottom'].src=eval("write_bottom.src");
				break;
			default:
				break;
		}
	}

 }
 function adjustSubLeftPos(menuItem) {
	 // off center #s
	 var writeDrop = 388;
	 var catsDrop = 293;
	 var aboutDrop = 207;
	 var troubleshootingDrop = 110;
	 var windowPos = 0;
	 
	if(is.ns6) { body = window.innerWidth; }
	if(is.ie || is.opera) { body = document.body.clientWidth; }

	var bodyCenter = body/2;				// Find the center of the browser window
	var centerLine = 402.5;
	switch(menuItem) {
		case "writeDrop":
			windowPos = bodyCenter - writeDrop;
			if(bodyCenter <= centerLine) windowPos = 14;
			break;
		case "catsDrop":
			windowPos = bodyCenter - catsDrop;
			if(bodyCenter <= centerLine) windowPos = 109;
			break;
		case "aboutDrop":
			windowPos = bodyCenter - aboutDrop;
			if(bodyCenter <= centerLine) windowPos = 195;
			break;
		case "troubleshootingDrop":
			windowPos = bodyCenter - troubleshootingDrop;
			if(bodyCenter <= centerLine) windowPos = 292;
			break;
		default:
			break;
	}

	var myMenu = document.getElementById(menuItem);
	myMenu.style.left = windowPos;

}

function showSubMenu(menuItem) {
	if(is.ns6 || is.ns7 || is.ie5 || is.ie6 || is.opera7) {
		if(menuItem != currentMenu && currentMenu != null) {
			hideMenu();
		}

		if(is.ns6) { body = window.innerWidth; }
		if(is.ie) { body = document.body.clientWidth; }
	
			var myMenu = document.getElementById(menuItem);
			adjustSubLeftPos(menuItem);
			myMenu.style.visibility = "visible";
			currentMenu = menuItem;
	}

}

function swapImgOn(img) {
		document[img].src = eval(img+"_on.src");
}

function swapImgOff(img) {
	document[img].src = eval(img+"_off.src");
}

function hideMenu() {
	if(is.ns6 || is.ns7 || is.ie5 || is.ie6 || is.opera7) {
		var myMenu = document.getElementById(currentMenu);
		
		myMenu.style.visibility = "hidden";
	}

}


function startTimer(time)
{
	if(time == null)
		time = 80;
	timeOn = setTimeout("hideMenu()",time);
}

function stopTimer()
{
	clearTimeout(timeOn);
}



/* FORM JS - Imported from Forums */
var pc = navigator.userAgent.toLowerCase();
var ie4_win = (pc.indexOf("win")!=-1) && (pc.indexOf("msie") != -1)
    && (parseInt(navigator.appVersion) >= 4);
var checked = false;

// only builds based upon gecko later than Jan 8th support the selectionStart, selectionEnd properly
var is_gecko = pc.indexOf("gecko/") != -1 &&
    parseFloat(pc.substring(pc.indexOf("gecko/") + 6, pc.indexOf("gecko/") + 14)) > 20030108;

function checkPost() {
    if (!checked) {
        checked = true;
        return true;
    }
    return false;
}
function styleTag(tag, ta) {
	
	if(tag == "url") {
		var userURL =  prompt("Enter A URL:", "http://");
		if(userURL == null) {
			userURL = "";
		}
		var tagOpen = '[' + tag.toLowerCase() + '=' + userURL + ']';
	} else {
		var tagOpen = '[' + tag.toLowerCase() + ']';
	}
    var tagClose = '[/' + tag.toLowerCase() + ']';
    if (ie4_win) {
        var selected;

        if (document.selection.createRange().parentElement().tagName == 'TEXTAREA') {
            selected = document.selection.createRange().text;
        }

        if (selected) {
            var addSpace = false;
            if (selected.charAt(selected.length-1) == ' ') {
                selected = selected.substring(0, selected.length-1);
                addSpace = true;
            }
            document.selection.createRange().text
                    = tagOpen + selected + tagClose + ((addSpace)?" ":"");
        } else {
            ta.value += tagOpen + tagClose;
        }
    } else if (is_gecko) {
        var selLength = ta.textLength;
        var selStart = ta.selectionStart;
        var selEnd = ta.selectionEnd;
        if (selEnd == 1 || selEnd == 2) {
            selEnd = selLength;
        }
        var s1 = (ta.value).substring(0, selStart);
        var s2 = (ta.value).substring(selStart, selEnd)
        var s3 = (ta.value).substring(selEnd, selLength);

        ta.value = s1 + tagOpen + s2 + tagClose + s3;

    } else {
        ta.value += tagOpen + tagClose;
    }
    ta.focus();
    return;
}
function caret(ta) {
    if (ie4_win && ta.createTextRange &&
            document.selection.createRange().parentElement().tagName == 'TEXTAREA')
    {
        ta.caretPos = document.selection.createRange().duplicate();
    }
}

function openEmoticons(url) {
	var width = 547;
	var height = 460;
	
	popSlideShow = window.open(url,"popExpand","width="+width+",height="+height+",left=100,top=300,toolbar=no,resizable=no,scrollbars=no,location=no,directories=no,menubar=no");
}


function getURL(formToPostTo) {
	userURL =  prompt("Enter A URL:", "http://");
	userTitle = prompt("Enter A Link Title:", "");
	formToPostTo.body.value += "[url="+userURL+"]"+userTitle+"[/url]";
}


function doMail()
{
	url = "/skin/default/emailthis/emailthis.jsp";
	url += "?title=" + escape (document.title) + "&url=" + escape (document.location);
	var screenWidth		=	(screen.width - 527) / 2;
	var screenHeight	=	(screen.height - 420) / 2;
	newwin = window.open(url,"mailer","width=527,height=420,toolbar=no,resizable=no,scrollbars=no,location=no,directories=no,menubar=no,top="+screenHeight+",left="+screenWidth+"");
}

function doContactBlogger(url)
{

	var screenWidth		=	(screen.width - 545) / 2;
	var screenHeight	=	(screen.height - 500) / 2;
	newwin = window.open(url,"contactBlogger","width=545,height=500,toolbar=no,resizable=no,scrollbars=no,location=no,directories=no,menubar=no,top="+screenHeight+",left="+screenWidth+"");
}
