// JavaScript Document

function callBackSlideshow(box) {
	addClass(box, "hidden");
}

var lastHomeBox = null;
function showHomeBox(id) {
	var nextBox = $(id);
	var prevBox = (lastHomeBox) ? lastHomeBox : $("ourMission");
	if(nextBox == prevBox) return false;
	
	prevBox.style.zIndex = 2;
	nextBox.style.zIndex = 1;
	removeClass(nextBox,"hidden");
	
	if ((navigator.userAgent.indexOf("iPhone") > -1)||(navigator.userAgent.indexOf("iPod") > -1)||(navigator.userAgent.indexOf("Android") > -1)){
		addClass(prevBox,"hidden");
		
	}
	else {
		changeOpac(100, nextBox);
	
		var currBoxAnim = getAnimationManager().add(prevBox);
	
		currBoxAnim.setAction({method: "fadeOut", alpha: 0, duration: 1000});
		currBoxAnim.setCallBack(callBackSlideshow);
		currBoxAnim.play();
	}
	
	lastHomeBox = nextBox;
		
	return false;
}

function homeGoldBarOver(elem) {
	if(elem.className.indexOf("active")>-1) return false;
	
	var goldBar = elem.parentNode;

	var currentWidth = goldBar.getAttribute("sourceWidth");
	if(currentWidth == null) currentWidth = goldBar.offsetWidth; 
	
	goldBar.setAttribute("sourceWidth", currentWidth);

	var extendedWidth = Number(currentWidth) + 90;
	var currBoxAnim = getAnimationManager().add(goldBar);
	currBoxAnim.setAction({method: "resizeTo", width: extendedWidth, duration: 250});
	currBoxAnim.play();
	
	elem.onmouseout = function() {
		var currBoxAnim = getAnimationManager().add(goldBar);
		currBoxAnim.setAction({method: "revertSize", duration: 250});
		currBoxAnim.play();
	}
}

function goldBarOver(elem) {
	var goldBar = elem.parentNode;
	
	var currentWidth = goldBar.getAttribute("sourceWidth");
	if(currentWidth == null) currentWidth = goldBar.offsetWidth; 
	
	goldBar.setAttribute("sourceWidth", currentWidth);
	var extendedWidth = Number(currentWidth) + 62;
	var currBoxAnim = getAnimationManager().add(goldBar);
	currBoxAnim.setAction({method: "resizeTo", width: extendedWidth, duration: 250});
	currBoxAnim.play();
	elem.onmouseout = function() {
		var currBoxAnim = getAnimationManager().add(goldBar);
		currBoxAnim.setAction({method: "revertSize", duration: 250});
		currBoxAnim.play();
	}
}

function goldBarOverFlash(elem) {
	var goldBar = getChildByClassName(elem.parentNode.parentNode, "menuItemBox");
	if(goldBar.className.indexOf("active") > -1) return;
	
	var currentWidth = goldBar.getAttribute("sourceWidth");
	if(currentWidth == null) currentWidth = goldBar.offsetWidth; 
	
	goldBar.setAttribute("sourceWidth", currentWidth);
	var extendedWidth = Number(currentWidth) + 58;
	var currBoxAnim = getAnimationManager().add(goldBar);
	currBoxAnim.setAction({method: "resizeTo", width: extendedWidth, duration: 250});
	currBoxAnim.play();
}

function goldBarOutFlash(elem) {
	var goldBar = getChildByClassName(elem.parentNode.parentNode, "menuItemBox");
	if(goldBar.className.indexOf("active") > -1) return;
	
	var currentWidth = goldBar.getAttribute("sourceWidth");
	if(!currentWidth) return;

	var currBoxAnim = getAnimationManager().add(goldBar);
	currBoxAnim.setAction({method: "revertSize", duration: 250});
	currBoxAnim.play();
}


function changeHidden(hidObject,showObject) {
	addClass(hidObject, "hidden");
	removeClass(showObject, "hidden");
	return false;
}

function openExternalLink(linkObj) {
	window.open(linkObj.href);
	return false;
}

function selectThumb(selImg) {
	if (selImg) {
		var thumbsBox = selImg.parentNode.parentNode;
		var img = selImg.getElementsByTagName("IMG");
                var attribution = img[0].getAttribute("xattribution") || "";
		var thumbImg = getChildByClassName(thumbsBox,"active");
		if (thumbImg) removeClass(thumbImg,"active");
		addClass(selImg,"active");	
		document.getElementById("LargeImage").src = img[0].src;
		document.getElementById("ImageAttribution").innerHTML = attribution;
	}
	return false;
}

function openContacts() {
	var modalDialog = getModalDialogManager();
	modalDialog.open("contactsModalDialogBox");
}



function openMovie(url) {
	var modalDialog = getModalDialogManager();
	modalDialog.open("videoModalDialogBox");
	var videoBox = document.createElement("div");
	videoBox.id = "videoBox";
	$("videoModalDialog").appendChild(videoBox);
	addSWFObject(url, "videoBox");
	return false;
}

function closeMovie() {
	getModalDialogManager().close();
	$("videoModalDialog").innerHTML = "";
}

function addSWFObject(url, id) {
	var flashvars = {};
	var params = {};
	params.allowFullScreen = "true";
	params.allowScriptAccess = "always";
	var attributes = {};
	swfobject.embedSWF(url, id, "430", "288", "9.0.0", "/m/scripts/expressInstall.swf", flashvars, params, attributes);
}

var windowPopupId = 0;
function popup(url) { //v2.0 All Steps
	var width = 300;
	var height = 500;
	var flash=window.open(url,'popup'+(windowPopupId++),'width=' + width + ',height=' + height + ',top='+(screen.height-500)/2+',left='+(screen.width-300)/2+',alwaysRaised=1,location=0,scrollbars=1,resizable=1');
	flash.focus();
}

function clearNewsletterBox(e) {
    if (e.value == 'email address') {
        e.value = '';
    }
}

function unclearNewsletterBox(e) {
    if (e.value == '') {
        e.value = 'email address';
    }
}

$j(document).ready(function() {
    $j('.toggle').click(function () {
        $j(this).parent().siblings('.toggleable').toggle();
        return false;
    })
});

