function resizeExploreVectors(resizeTo) {
  flashExplore.style.height = resizeTo + 'px';
}

/*
function checkScreenAndRedirect(anchorObj) {
  if (currentScreen.id == 'screen_LaunhProjectExcerpt') {
    document.location.href = anchorObj.href;
  } else {
    //screenTo('Project Excerpt');
    //setTimeout("document.location.href = '"+anchorObj.href+"';", 500);
    document.location.href = anchorObj.href;
  }
}
*/

function findPos(obj) {

	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];

}

function tip(theObj, tipText) {

  // REQUIRES css definitions: t, b, l, r, bl, br, tl, tr

  if ($('tip')) return;
  var coords = findPos(theObj);
  var myLeft = coords[0];
  var myTop = coords[1];

  var myDiv = document.createElement("DIV");
  myDiv.id = "tip";
  myDiv.style.backgroundColor = "#ffffff";  // was faf9e9
  myDiv.style.position = "absolute";
  myDiv.style.zIndex = 9;
  //myDiv.style.padding = '3px 6px 4px 4px';
  myDiv.style.padding = '0px 0px 0px 0px';
  //myDiv.style.border = 'solid 1px #DDDDDD';
  myDiv.style.fontSize = '11px';
  myDiv.style.color = '#555555';
  myDiv.style.left = (myLeft + 21) + 'px';
  myDiv.style.top = (myTop + 0) + 'px';

  var iHtml = '';
  iHtml += '<div class="t"><div class="b"><div class="l"><div class="r"><div class="bl"><div class="br"><div class="tl"><div class="tr">';
  iHtml += tipText;
  iHtml += '</div></div></div></div></div></div></div></div>';
  myDiv.innerHTML = iHtml;

  document.body.appendChild(myDiv);

}

function remove_tip() {
  var tipObj = $('tip');
  if (tipObj) removeElement(tipObj);
}

function removeElement(theObj) {
  theObj.parentNode.removeChild(theObj);
}

function toggle(myId) {

  var myElement = $(myId);
  var myHeader = myElement.previousSibling;
  if (myHeader.childNodes.length == 0) myHeader = myHeader.previousSibling;
  var myImg = myHeader.getElementsByTagName('IMG')[0];

  if (myElement.style.display == 'none') {
    myElement.style.display = 'block';
    myImg.src = '/projects/inc/icons/down_arrow.png'; // WARNING: too much DOM
    setCookie(myId,1,5);
  } else {
    myElement.style.display = 'none';
    myImg.src = '/projects/inc/icons/right_arrow.png'; // WARNING: too much DOM
    setCookie(myId,0,5);
  }
}

function $(myId) {
	return document.getElementById(myId);
}

function go() {
  firstScreenObj = $('firstScreen');  // global
  currentScreen = $('screen_LaunchProjectExcerpt');
}

function screenTo(sourceRef, iframeSource, respHandle) {

 	// _this_ will end up on thedailywtf.com!
    var nextScreenId = sourceRef;  // TODO: bad form here
    nextScreenId = nextScreenId.split(" ");
    nextScreenId = nextScreenId.join("");
    nextScreenId = nextScreenId.split("&amp;");
    nextScreenId = nextScreenId.join("");
    nextScreenId = 'screen_'+nextScreenId;

	var firstScreenObj = $('firstScreen');
	var nextScreen     = $(nextScreenId);
    if (!nextScreen) {
    	alert("This option isn't quite ready.  Please try back soon.");
    	return;
    }

    if (typeof firstScreenOrigHeight == 'undefined') firstScreenOrigHeight = firstScreenObj.offsetHeight;

	$('iframeDBViz').style.height = '1px;'
    setIframeSource(currentScreen.id, '');
    if (nextScreenId == 'screen_LaunchScreengrabsImages') preloadScreengrabImages(); // NOTE: soft-coding
    if (nextScreen.id == 'screen_LaunchProjectExcerpt') {
      opacity('screenBackground', 0, 100, 500);
    } else if (currentScreen.id == 'screen_LaunchProjectExcerpt') {
      opacity('screenBackground', 100, 0, 500);
    }
    opacity(currentScreen.id, 100, 0, 500, "opacity('"+nextScreen.id+"', 0, 100, 500);");

    nextScreen.style.opacity          = '0';
    nextScreen.style.MozOpacity       = '0';
    nextScreen.style.KhtmlOpacity     = '0';
    nextScreen.style.filter           = "alpha(opacity=0)";
	nextScreen.style.visibility = 'visible';

    var resizeToHeight = (nextScreen.offsetHeight > firstScreenOrigHeight) ? nextScreen.offsetHeight : firstScreenOrigHeight;

	resizeScreen(resizeToHeight, "hide('"+currentScreen.id+"'); setIframeSource('"+nextScreen.id+"','"+iframeSource+"');");  // MAGIC NUMBER

	currentScreen.style.visibility='hidden';
    currentScreen = nextScreen;

}

function hide(myId) {
  $(myId).style.display='hidden';
}

function setIframeSource(myObjId, mySrc) {
  $('iframeDBViz').style.height = '500px;'
  var iframes = $(myObjId).getElementsByTagName("IFRAME");
  if (iframes.length > 0) iframes[0].src = mySrc;
}





function deselectScreenGrabImages() {
  var theDiv;
  var anchorList;
  var divs = $('View_Screengrabs').getElementsByTagName("div");
  for (var a = 0; a < divs.length; a++) {
    if (divs[a].className == 'selector') {
      theDiv = divs[a];
      break;
    }
  }
  if (theDiv) {
    anchorList = theDiv.getElementsByTagName("A");
    for (var a = 0; a < anchorList.length; a++) {
      anchorList[a].className = '';
    }
  }
}



// COOKIES (from w3cschools)

function getCookie(c_name) {
	if (document.cookie.length>0) {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1) {
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return "";
}

function deleteCookie(c_name) {
		var expdate = new Date();
		expdate.setTime(expdate.getTime() - 1);
		document.cookie = c_name += "=; expires=" + expdate.toGMTString();
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function cookiesTurnedOn() {
	document.cookie = "cookies=true";
	var has_cookies = (document.cookie) ? "true" : "false";
	return has_cookies;
}

function popUpWin() {
  var tools = '';
  if (browser_is_custom == '1') {
    var myChrome = (browser_disp_chrome == 1) ? 'yes' : 'no';
	var tools="toolbar="+myChrome+",statusbar="+myChrome+",location="+myChrome+",menubar="+myChrome+",";
    if (browser_width == '0' && browser_height == '0') {
		var strWidth = screen.availWidth - 10;    // add a very small amount of wiggle room
		var strHeight = screen.availHeight - 10;  // add a very small amount of wiggle room
		tools += "scrollbars=yes,resizable=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
    } else {
	  var x = (screen.availWidth - browser_width) /2;
	  var y = (screen.availHeight - browser_height)/3;
	  tools += "scrollbars=";
	  tools += ('1' == browser_disp_scrollbars) ? 'yes' : 'no';
	  tools += ",resizable=yes,width="+browser_width+",height="+browser_height+",left="+x+",top="+y+"";
    }
  }
  newWindow = window.open(project_url, '_blank',tools);
  newWindow.focus();
}

