/*_------------------------------ REFRESH WINDOW ---------------------------------*/
function refresh()
{
    window.location.reload( false );
}
/*_------------------------------ COLLAPSABLE ITEMS ---------------------------------*/
function expand(id)
{
	if (document.getElementById(id+"_content").style.display == 'none'){
		document.getElementById(id+"_content").style.display='block';
		document.getElementById(id+"_link").setAttribute((document.all ? "className" : "class"), "collapse");
	}else{
		document.getElementById(id+"_content").style.display='none';
		document.getElementById(id+"_link").setAttribute((document.all ? "className" : "class"), "expand");
	}
	document.getElementById("contentLeft").style.height = "100%";
}
/*_------------------------------ ALIGN COLUMNS ---------------------------------*/
function alignColumns()
{
	// ensures that columns are even.
	var h1 = document.getElementById("contentRight").offsetHeight;
	var h2 = document.getElementById("contentLeft").offsetHeight;
	if (h1 > h2){
		var hMax = h1;
	}else{
		var hMax = h2;
	}
	document.getElementById("contentRight").style.height = hMax+"px";
	document.getElementById("contentLeft").style.height = hMax+"px";
}
// for flash elements that need to be fullscreen
function resize_Handler()
{
	var topPadding = 41;
	if(document.location.toString().indexOf('wizard') !== -1){
		topPadding = 0;
	}
	if(document.all){
		$('flash').style.width = document.body.clientWidth;
		$('flash').style.height = document.body.clientHeight-topPadding;
	}else{
		$('flash').style.width = window.innerWidth;
		$('flash').style.height = window.innerHeight-topPadding;
	}
}
/*_------------------------------ SECONDARY NAV FOR SITES ---------------------------------*/
var navTimer = '';
var navItem = '';
var navTitle = '';

function showSecondaryNav(userID,title,nav,x,y)
{
	if (navTitle == '' || navTitle != title || (navTitle == title && $("secondaryNav").style.display == 'none'))
	{
		navTitle = title;

		clearTimeout(navTimer);
		clearSecondaryNav();
		navItem = nav;
		if(navItem !== null && navItem !== ""){
			// check for vertical nav
			//alert($('headerLinks').getStyle('min-height'));
			if($('headerLinks').getStyle('min-height') == "400px"){
				$('secondaryNav').setStyle({left: ($(navItem).viewportOffset().left-$('navigation').viewportOffset().left+$(navItem).getWidth())+"px"});
				$('secondaryNav').setStyle({top: ($(navItem).viewportOffset().top-$('navigation').viewportOffset().top)+"px"});
			}else{
				$('secondaryNav').setStyle({left: ($(navItem).viewportOffset().left-$('navigation').viewportOffset().left)+"px"});
			}
		}else if(x !== null){
			document.getElementById("secondaryNav").style.left = x+document.getElementById('header').offsetLeft+"px";
		}
		title = title.replace("&","|AND|");
		var info = "action=secondaryNav&title="+title+"&userID="+userID;
		sendReq("/resources/php/ajax.php","showSecondaryNav_Handler(req.responseText)",info);
	}
	else {
		delaySecondaryNav();
	}
}
function showSecondaryNav_Handler(re)
{
	if(re !== 'false'){
		var navArray = re.split('|');
		var secNav = '<ul>';
		for(var i=0;i<navArray.length;i++){
			if(navArray[i] !== ''){
				navArray2 = navArray[i].split(',');
				if(navArray2[1] == ''){
					navArray2[1] = navArray2[0];
				}
				secNav += '<li><a class="selected" href="/'+navArray2[1]+'.htm" onMouseOver="delaySecondaryNav()">'+navArray2[0]+'</a></li>';
			}
		}
		secNav += '</ul>';
		document.getElementById("secondaryNav").innerHTML = secNav;
		document.getElementById("secondaryNav").style.display="block";
	}
}
function delaySecondaryNav()
{
	clearTimeout(navTimer);
}
function hideSecondaryNav()
{
	navTimer = setTimeout('clearSecondaryNav()', 3000);
}
function clearSecondaryNav()
{
	document.getElementById("secondaryNav").style.display="none";
}
/*_------------------------------ ACCOUNT WINDOW ---------------------------------*/
function showAccount()
{
	document.getElementById('accountWindow').style.display = "block";
}
function hideAccount()
{
	document.getElementById('accountWindow').style.display = "none";
}
/*_------------------------------ NEW APP WINDOW ---------------------------------*/

function launchApp(app) 
{
	window.open(app,'app','fullscreen=yes, menubar=no, location=no, toolbar=no, resizable=yes, status=no');
	return false;
}
/*_------------------------------ GET URL VARIABLES ---------------------------------*/
function getURLVar(urlVarName)
{
	//divide the URL in half at the '?'
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		//load all the name/value pairs into an array
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				//load the name/value pair into an array
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
					//I found a variable that matches, load it's value into the return variable
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	return urlVarValue;   
}
/*_------------------------------ ALERT WINDOW ON EXIT ---------------------------------*/
var needToConfirm = false;
var confirmExitMessage = "";

window.onbeforeunload = confirmExit;
function confirmExit()
{
	if (needToConfirm){
		return confirmExitMessage;
	}
}
function enableConfirmExit(msg)
{
	confirmExitMessage = msg;
	needToConfirm = true;	
}
function disableConfirmExit()
{
	needToConfirm = false;
}
/*_------------------------------ LOGOUT ---------------------------------*/
function logout()
{
	var info = "action=userLogout";
	// send to php
	sendReq("/resources/php/ajax.php","LogoutStatus(req.responseText)",info);
}

function LogoutStatus(status){
	refresh();	
}
/*_------------------------------ FIX BUTTON ALIGNMENTS ---------------------------------*/
function buttonFix(btn){
	btn.getOffsetParent().setStyle({width:btn.getWidth()+10+'px'});
}
document.observe("dom:loaded", function() {
  // initially hide all containers for tab content
  $$('ul.button').each(function(s){ buttonFix(s); });
  createPhotoGrid();
});
/*_------------------------------ CREATE PHOTO GRIDS ---------------------------------*/
function createPhotoGrid()
{	
	//var gridList = document.getElementsByClassName('imageGrid');
	var gridList = $$('.imageGrid');

	for(var i=0; i<gridList.length; i++){
		var gridID = gridList[i].identify().split('imageGrid_').join('');
		// get current scale
		var currentSize = gridList[i].getElementsByClassName("scale-image")[0].getWidth();
		var currentScale = currentSize/150;
		var demoSlider = new Control.Slider('handle'+gridID,'track'+gridID, {axis:'horizontal', minimum: 0, maximum:150, alignX: 2, increment: 2, sliderValue: currentScale});
		var grid = gridList[i];
		demoSlider.options.onSlide = function(value,slider)
		{
			scaleIt(value,slider.track.up(4));
		};
		demoSlider.options.onChange = function(value,slider)
		{
			scaleIt(value,slider.track.up(4));
		};
	}
}
function scaleIt(v,grid) 
{
	var scalePhotos = grid.getElementsByClassName("scale-image");
	
	// Remap the 0-1 scale to fit the desired range
	floorSize = .26;
	ceilingSize = 1.0;
	v = floorSize + (v * (ceilingSize - floorSize));
	
	for (i=0; i < scalePhotos.length; i++) {
		scalePhotos[i].style.width = (v*150)+"px";
		scalePhotos[i].style.height = (v*150)+"px";
		//scalePhotos[i].style.paddingTop = ((v*150)-scalePhotos[i].down(0).down(0).getHeight())/2;
	}
}
//Event.observe(window, 'load', createPhotoGrid);