////////////////////////////////////////////////////////////////////////////
// Wang.Media Javascript Calls
////////////////////////////////////////////////////////////////////////////

// include other JS...
document.write('<script src="/assets/javascript/prototype.js"><\/script>');
document.write('<script src="/assets/javascript/scriptaculous.js"><\/script>');
document.write('<!--[if lt IE 7.]><script defer type="text/javascript" src="/assets/javascript/png.js"><\/script><![endif]-->');


// include css
document.write('<link href="/assets/css/main.css" rel="stylesheet" type="text/css" />');

// call a global variable  (rather than sending it out and parsing it back in)
var theID = '';
var theID2 = '';

// this function toggles between two visible divs
function toggleLayer(whichLayerShow, whichLayerHide)
{
	document.getElementById(whichLayerHide).style.display = "none";
	document.getElementById(whichLayerShow).style.display = "";
}

// this function allows the visible toggle for just one div
function showHideLayer(whichLayer)
{
	theLayer = document.getElementById(whichLayer);
	theLayer.style.display = (theLayer.style.display != "none") ? "none" : "";
}

// this function hides one div
function hideLayer(whichLayer)
{
	//document.getElementById(whichLayer).style.display = "none";
	new Effect.Fade( document.getElementById(whichLayer));
}

// this function hides many div
function hideLayers(whichLayers)
{
	var layersArray = whichLayers.split("::");
	for (var i = 0; i < layersArray.length; i++) {
		document.getElementById(layersArray[i]).style.display = "none";		
	}
}

function minAdmin() {
	document.getElementById('chooser').style.display= "none";
	document.getElementById('bannerSpacer').style.height="20px";
	document.getElementById('bannerSpacer').style.top="-50px";
	document.getElementById('bannerBGMiddle').style.marginTop="50px";
	document.getElementById('bannerBG').style.top="-50px";
}
function maxAdmin() {
	document.getElementById('chooser').style.display= "";
	document.getElementById('bannerSpacer').style.height="256px";
	document.getElementById('bannerSpacer').style.top="-300px";
	document.getElementById('bannerBGMiddle').style.marginTop="300px";
	document.getElementById('bannerBG').style.top="-300px";
}

// browser check
if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4) {
	var ie = 1;
}
else {
	var ie = null;
}
if (navigator.userAgent.indexOf("Safari")!=-1) {
	var safari = 1;
}
else {
	var safari = null;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Scrolling Functions
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// these variables control the movement
xTarget = 0;
x = 0;
yTarget = 0;
y = 0;
s=0;
var div = '';
var kill = 0;
ope = '';
total = 1;
// these functions move the contents of a div

var limit = 1;
var slideshowCounter = 0;
function initiateSlideshowGallery(lim) {
	kill = 0;
	limit = lim;
	document.getElementById('stage').style.left = 0+'px';
	x = 0;
	xTarget = 0;
	slideshowCounter = 1;
	document.getElementById('gallerySlideshowLink').innerHTML = 'stop slideshow';
	document.getElementById('gallerySlideshowLink').onclick = function() { killSlideshow(limit); }
	slideshowGallery();
}
function killSlideshow(lim) {
	kill = 1;
	document.getElementById('gallerySlideshowLink').innerHTML = 'restart slideshow';
	document.getElementById('gallerySlideshowLink').onclick = function() { initiateSlideshowGallery(limit); }
}
function slideshowGallery() {
	if (kill != 1) {
		if (slideshowCounter == limit) {
			document.getElementById('stage').style.left = 738+'px';
			x = 738;
			xTarget = 738;
			slideshowCounter = 0;
		}
		slideshowCounter++;
		moveH(-738,"stage");
		setTimeout("slideshowGallery()",3000);
	}
}

// these functions move the contents of a div
function scrollHWrapper(thisDiv,theDiv) {
	if (theDiv == "") {
		window.clearTimeout(move_timeout);
		move_timeout = null;
		s = 0;
	}
	else {
		//alert(document.getElementById(theDiv).offsetLeft);
		if ((document.getElementById(theDiv).offsetLeft +  thisDiv.offsetLeft)  < 300)
			s = 1;
		else
			s = -1;
		div = theDiv;
		scrollH();
	}
}
function scrollH() {
	//	alert(document.getElementById('stage').offsetLeft);
	if ((document.getElementById(div).offsetLeft == -(document.getElementById('lastImage'+ope).offsetLeft) || (document.getElementById(div).offsetLeft == -(document.getElementById('lastImage'+ope).offsetLeft) -79)) && s < 0) {
		document.getElementById(div).style.left = 0 + "px";
		move_timeout = window.setTimeout("scrollH();",25);
	}
	else if ((document.getElementById(div).offsetLeft == 0) && s > 0) {
		document.getElementById(div).style.left = -(document.getElementById('lastImage'+ope).offsetLeft)+ -79+"px";
		move_timeout = window.setTimeout("scrollH();",25);
	}
	else if (s != 0) {
		document.getElementById(div).style.left = document.getElementById(div).offsetLeft + s + "px";
		move_timeout = window.setTimeout("scrollH();",25);
	}
	else {
		window.clearTimeout(move_timeout);
		move_timeout = null;
	}
}

function moveH (distance,theDiv) {
	if ( (xTarget > ((total-1) * -738) || distance > 0) && (xTarget < 0 || distance < 0)) {
	div = theDiv;
	xTarget = xTarget + distance;
	moveHorizontal();
	}
}

function moveHMini (distance,theDiv) {
	if (xTarget < 0 || distance < 0) {
	div = theDiv;
	xTarget = xTarget + distance;
	moveHorizontal();
	}
}

function goToH(target,theDiv) {
	div = theDiv;
	xTarget = target;
	moveHorizontal();
}
function moveHorizontal() {
	var xDiff = xTarget - x;
	x += xDiff/4;
	document.getElementById(div).style.left = x + "px";
	if (Math.round(xDiff) == 0) {
		window.clearTimeout(move_timeout);
		move_timeout = null;
	} else {
		move_timeout = window.setTimeout("moveHorizontal();",25);
	}
}
function focusY(focusElement,theDiv) {
	target = document.getElementById(focusElement).offsetTop * -1;
//	if (ie) {
//		y = Math.round(y);
//		target = y + target;
//	}
	moveY(target,theDiv);
}
function moveY(target,theDiv) {
	div = theDiv;
	yTarget = target;
	moveVertical();
}
function yScroll(velocity, theDiv) {
	if (y < 0 || velocity < 0) {
		div = theDiv;
		yTarget = (y + velocity);
		moveVertical();
	}
}
function initiateMouseScrollY(theDiv,divToScroll) {
	div = divToScroll;
	if (theDiv.addEventListener && !safari)
     theDiv.addEventListener('DOMMouseScroll', scrollWheelMoveV, false);
	else
		theDiv.onmousewheel = document.onmousewheel = scrollWheelMoveV;
}
function removeMouseScrollY(theDiv,divToScroll) {
	if (theDiv.addEventListener && !safari)
     theDiv.removeEventListener('DOMMouseScroll', scrollWheelMoveV, false);
	else
		theDiv.onmousewheel = document.onmousewheel = null;
}
function scrollWheelMoveV(e) {
	if (window.event || window.Event) {
		if (!e) e = window.event;
		if (e.wheelDelta <= 0 || e.detail > 0 ) 
			velocity = -100;
		else 
			velocity = 100;
		if (y < 0 || velocity < 0) {
			yTarget = (y + velocity);
			moveVertical();
		}
	}
}
function moveVertical() {
	var yDiff = yTarget - y;
	y += yDiff/4;
	if (y > 0) {
		y = 0;
		yTarget = 0;
	}
	document.getElementById(div).style.top = y + "px";
	if (Math.round(yDiff) == 0) {
		window.clearTimeout(move_timeout);
		move_timeout = null;
	} else {
		move_timeout = window.setTimeout("moveVertical();",25);
	}
}

// this function shows a div
function showLayer(whichLayer)
{
	//document.getElementById(whichLayer).style.display = "block";
  new Effect.Appear( document.getElementById(whichLayer));
}

// these are generic AJAX functions
var req;

function ajaxer(data,file,div) 
{
	// hope to deprecate this soon... here, we assign a universal
	// variable  for the div id
	theID = div;
	if (div !='') {
		document.getElementById(theID).innerHTML = '<br /><br /><img src="/images/spinner.gif" alt="loading..." /><br /><br />loading';
	}
	// branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.open("POST", "/assets/ajax/" + file + ".php", true);
				req.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
        req.send(data);
        req.onreadystatechange = processReqChange;
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("POST", "/assets/ajax/" + file + ".php", true);
						req.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
            req.send(data);
        }
    }
}
function processReqChange() 
{
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200 && theID !='') {
			// set the id's HTML to the result
			document.getElementById(theID).innerHTML = req.responseText;
			new Effect.Appear( document.getElementById(theID));
		} 
		if (req.status != 200) {
			// explain the problem (we need error checking here)
			alert("Ajax Javascript Request Error\n" + req.statusText);
		}
	}
}