////////////////////////////////////////////////////////////////////////////
// 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>');

// 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 shows a div
function showLayer(whichLayer)
{
	document.getElementById(whichLayer).style.display = "block";
  //new Effect.Appear( 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";		
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Image Rotator
/////////////////////////////////////////////////////////////////////////////////////////////////////////
var total = 0;
var currentRI = 0;
function rotator(t) {
	total = t;
	rotateTimeout = window.setTimeout("rotate();",3000);
}
function rotate() {
	new Effect.Fade(document.getElementById('ri'+currentRI),{ duration: 3.0 });
	if (currentRI == (total - 1))
		currentRI = 0;
	else
		currentRI = (currentRI + 1);
	new Effect.Appear(document.getElementById('ri'+currentRI),{ duration: 3.0 });
	rotateTimeout = window.setTimeout("rotate();",7000);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Scrolling Functions
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// these variables control the movement
xTarget = 0;
x = 0;
yTarget = 0;
y = 0;
count  = 0;
currentThumb = 0;
var div = '';
// these functions move the contents of a div
function moveH (distance,theDiv) {
	div = theDiv;
	new Effect.Fade(document.getElementById('caption'+currentThumb),{ duration: 1 });
	xTarget = xTarget + distance;
	if (xTarget > 0) {
		x = (count*-800);
		xTarget = (count*-800)+800;
	}
	if (xTarget < (count*-800)) {
		x = 0;
		xTarget = -800;
	}
	moveHorizontal();
}
function goToH(target,theDiv) {
	new Effect.Fade(document.getElementById('caption'+currentThumb),{ duration: 2 });
	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);
		x = xTarget;
		document.getElementById('thumb'+currentThumb).className='thumb';
		currentThumb = (xTarget/-800);
		if (xTarget == (count*-800))
			currentThumb = 0;
		new Effect.Appear(document.getElementById('caption'+currentThumb),{ duration: 1 });
		document.getElementById('thumb'+currentThumb).className='thumbSelected';
		move_timeout = null;
	} else {
		move_timeout = window.setTimeout("moveHorizontal();",25);
	}
}


// these are generic AJAX functions
var req;
var req2;
var cornersSet = 0;
function aj(data,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..." />';
	}
	// branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.open("POST", "/assets/ajax/ajax.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/ajax.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 (theID == 'adminPopup') {
				settings = {
          tl: { radius: 10 },
          tr: { radius: 10 },
          bl: { radius: 10 },
          br: { radius: 10 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      	}
			}
						showLayer(theID);
	
		} 
		if (req.status != 200) {
			// explain the problem (we need error checking here)
			alert("Ajax Javascript Request Error\n" + req.statusText);
		}
	}
}

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