var dropCurrent = "";
function swapDrop(dropNew) {
	if (dropCurrent != "") {
		new Effect.SlideUp("drop_" + dropCurrent, {duration: 0.35, queue: {position: "end", scope: "dropScope"}});
		$("nav_"+dropCurrent).src = "images/nav_"+dropCurrent+"_off.jpg";
		setTimeout("autoloadNav();",100);
	}
	if (dropNew != dropCurrent) {
		$("nav_"+dropNew).src = "images/nav_"+dropNew+"_on.jpg";
		new Effect.SlideDown("drop_" + dropNew, {duration: 0.35, queue: {position: "end", scope: "dropScope"}});
		dropCurrent = dropNew;
	} else {
		dropCurrent = "";
	}
}
function mouseDrop(dropOver, dropMode) {
	if (dropCurrent != dropOver) {
		if (dropMode == 1) {
			$("nav_"+dropOver).src = "images/nav_"+dropOver+"_on.jpg";
		} else {
			$("nav_"+dropOver).src = "images/nav_"+dropOver+"_off.jpg";
		}
	}
}

var navCurrent = 0;
function mouseNav(navOver, navMode) {
	if (navCurrent != navOver) {
		if (navMode == 1) {
			$("navLi"+navOver).className = "navOver";
			$("navDiv"+navOver).className = "navOver";
			$("navHref"+navOver).className = "navOver";
		} else {
			$("navLi"+navOver).className = "";
			$("navDiv"+navOver).className = "";
			$("navHref"+navOver).className = "";
		}
	}
}
function swapNav(navNew) {
	if (navCurrent != navNew) {
		if (navCurrent != 999) {
			$("navLi"+navCurrent).className = "";
			$("navDiv"+navCurrent).className = "";
			$("navHref"+navCurrent).className = "";
		}
		if (navNew != 999) {
			$("navLi"+navNew).className = "navOn";
			$("navDiv"+navNew).className = "navOn";
			$("navHref"+navNew).className = "navOn";
		}
		$("main"+navCurrent).style.display = "none";
		$("main"+navNew).style.display = "block";
		navCurrent = navNew;
	}
}

function swapBoxlink(boxId,boxClass) {
	$(boxId).className = "boxlink"+boxClass;
}

function autoloadNav() {
	var tempLocation = location.hash;
	if (tempLocation != "") {
		tempLocation = tempLocation.replace("#","");
		if (tempLocation.indexOf("_") > -1) {
			tempLocation = tempLocation.replace("_","");
			if (tempLocation.indexOf("-") > -1) {
				tempLocation = tempLocation.split("-");
				swapNav(tempLocation[0]);
				loadArticle(tempLocation[1]);
			} else {
				swapNav(tempLocation);
			}
		}
	}
}


var drawerBookPreviewCurrent = 0;
var drawerBookPreviewTotal = 1;

function drawBookPreviewControls (totalPanes) {
	tempOutput = "";
	
	drawerBookPreviewTotal = totalPanes;
	
	var i = 0;
	for (i=0; i<totalPanes; i++) {
		tempOutput = tempOutput + "<a href=\"javascript:drawerBookPreviews(" + i + ");\"><img id=\"drawerBookPreviewPaneIndi" + i + "\" src=\"images/direct_stat_sm_";
		if (i == 0) {
			tempOutput = tempOutput + "on";
		} else {
			tempOutput = tempOutput + "off";
		}
		tempOutput = tempOutput + ".gif\" style=\"margin-right:10px;margin-bottom:3px;\" /></a>";
	}
						
	tempOutput = "<a href=\"javascript:drawerBookPreviews(-1);\"><img src=\"images/direct_back_sm_off.gif\" onmouseover=\"this.src='images/direct_back_sm_on.gif';\" onmouseout=\"this.src='images/direct_back_sm_off.gif';\" style=\"margin-right:10px;\" /></a>" + tempOutput + "<a href=\"javascript:drawerBookPreviews(99);\"><img src=\"images/direct_go_sm_off.gif\" onmouseover=\"this.src='images/direct_go_sm_on.gif';\" onmouseout=\"this.src='images/direct_go_sm_off.gif';\" /></a>";
	
	return tempOutput;
}

function drawerBookPreviews (previewMoveTo) {
	if (previewMoveTo == -1) {
		// previous pane
		if (drawerBookPreviewCurrent == 0) {
			previewMoveTo = drawerBookPreviewTotal - 1;
		} else {
			previewMoveTo = drawerBookPreviewCurrent - 1;
		}
	} else if (previewMoveTo == 99) {
		// next pane
		if (drawerBookPreviewCurrent == (drawerBookPreviewTotal-1)) {
			previewMoveTo = 0;
		} else {
			previewMoveTo = drawerBookPreviewCurrent + 1;
		}
	}
	if (previewMoveTo != drawerBookPreviewCurrent) {
		$("drawerBookPreviewPaneIndi" + drawerBookPreviewCurrent).src = "images/direct_stat_sm_off.gif";
		$("drawerBookPreviewPaneIndi" + previewMoveTo).src = "images/direct_stat_sm_on.gif";
		tempMoveAmount = -200 * previewMoveTo;
		new Effect.Move('bookFrameContainer', {x: tempMoveAmount, mode: 'absolute', duration:0.75, queue: {position:'end', scope: 'bookScope'}});
		drawerBookPreviewCurrent = previewMoveTo;
	}
}
function drawerBookPreviewsSlideshow() {
	drawerBookPreviews(99);
	setTimeout("drawerBookPreviewsSlideshow();",10000);
}

function loadReview (itemID) {
	new Ajax.Request("fetch.php?ax=item&id="+itemID, {onSuccess:loadReviewProcess});
}
function loadReviewProcess (t) {
	$("popRevScroll").innerHTML = "<div id=\"popRevInner\">" + t.responseText + "</div>";
	$("popRev").style.display = "block";
	Scroller.reset("popRevScroll");
	scroll(0,0);
}
function addReview (itemID) {
	new Ajax.Updater("popRevScroll", "fetch.php?ax=item&id=" + itemID + "&px=" + escape(document.review.px.value), {asynchronous: true});
}

var articleLive = "";
function loadArticle (articleID) {
	articleLive = articleID;
	new Ajax.Request("fetch.php?ax=article&id="+articleID, {onSuccess:loadArticleProcess});
}
function loadArticleProcess (t) {
	$("popArtScroll").innerHTML = "<div id=\"popArtInner\">" + t.responseText + "</div>";
	$("popArt").style.display = "block";
	Scroller.reset("popArtScroll");
	scroll(0,0);
}

var ipePageChanged = 0;
function ipePageEdit(pageID,divID) {
	new Ajax.Updater(divID,"ipe_page.php?ax=doedit&page_id=" + pageID + "&active_div=" + divID);
}
function ipePageSave(pageID,divID) {
	if (ipePageChanged == 1) {
		ipePageChanged = 0;
		new Ajax.Updater(divID, "ipe_page.php?ax=doupdate&page_id=" + pageID + "&active_div=" + divID, {asynchronous: true, parameters: Form.serialize("ipePage" + pageID)});
	} else {
		new Ajax.Updater(divID,"ipe_page.php?ax=dofetch&page_id=" + pageID + "&active_div=" + divID);
	}
}
function ipePageCancel(pageID,divID) {
	if (ipePageChanged == 1) {
		if (window.confirm("By canceling, you will lose your changes to this page.  Are you sure you want to do this?\n\nClick \"OK\" to continue or \"Cancel\" to continue editing.")) {
			ipePageChanged = 0;
			new Ajax.Updater(divID,"ipe_page.php?ax=dofetch&page_id=" + pageID + "&active_div=" + divID);
		}
	} else {
		new Ajax.Updater(divID,"ipe_page.php?ax=dofetch&page_id=" + pageID + "&active_div=" + divID);
	}
}

var streamLoading = 0
function loadStream (itemID) {
	streamLoading = itemID;
	new Ajax.Request("fetch.php?ax=audiostream&id="+itemID, {onSuccess:loadStreamProcess});
}
function loadStreamProcess (t) {
	path = t.responseText;
	var so = new SWFObject("playerSingle.swf", "mymovie" + streamLoading, "192", "67", "7", "#FFFFFF");
	so.addVariable("autoPlay", "yes");
	so.addVariable("soundPath", path);
	so.addVariable("playerSkin", "1");
	so.addVariable("overColor", "#156F1B");
	so.write("flashPlayer" + streamLoading);
}

function addReview (itemID) {
	new Ajax.Updater("popRevScroll", "fetch.php?ax=item&id=" + itemID + "&px=" + escape(document.review.px.value), {asynchronous: true});
}