//THE SCRIPT BELOW TOGGLES AN IMAGE ONCLICK
// EXAMPLE.... <a href="javascript:;" onclick="trigger_effect(this,'1stCandidate','slide', 'images/toggle_plus.gif', 'images/toggle_minus.gif');">

function trigger_effect(src_element,div_id, effect, first_img, second_img){
		Effect.toggle(div_id, effect, {afterFinish:function(){
		image = src_element.getElementsByTagName('img')[0];
		image.src = image.src.match(first_img) ? second_img : first_img;
		}});
		return true;
	}
// email hider--This script is to kill any spambot in its tracks
function returnEmail(username, domain) {
					var formattedEmail = username+"@"+domain;
					window.location.href = "mailto:"+formattedEmail+"?subject=";
				}
// ~~~~~~~EXAMPLE~~~~~~~<a href="javascript:returnEmail('name', 'domain.com');" title="Click to email">
// ~~~~~~~~~~~~~~~~~clear a field onfocus
function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}
// ~~~~~~~~~~~~~~~~~rollovers
function setupRollovers() {
if (!document.getElementsByTagName)
return;
var all_links = document.getElementsByTagName('a');
for (var i = 0; i < all_links.length; i++) {
var link = all_links[i];
if (link.className &&
(' ' + link.className + ' ').indexOf(' rollover ') != -1)
{
if (link.childNodes &&
link.childNodes.length == 1 &&
link.childNodes[0].nodeName.toLowerCase() == 'img') {
link.onmouseover = mouseover;
link.onmouseout = mouseout;
}
}
}
}
function findTarget(e)
{
/* Begin the DOM events part, which you */
/* can ignore for now if it's confusing */
var target;
if (window.event && window.event.srcElement)
target = window.event.srcElement;
else if (e && e.target)
target = e.target;
if (!target)
return null;
while (target != document.body &&
target.nodeName.toLowerCase() != 'a')
target = target.parentNode;
if (target.nodeName.toLowerCase() != 'a')
return null;
return target;
}
function mouseover(e) {
var target = findTarget(e);
if (!target) return;
// the only child node of the a-tag in target will be an img-tag
var img_tag = target.childNodes[0];
// Take the "src", which names an image called "something.ext",
// Make it point to "something_over.ext"
// This is done with a regular expression
img_tag.src = img_tag.src.replace(/(\.[^.]+)$/, '-over$1');
}
function mouseout(e) {
var target = findTarget(e);
if (!target) return;
// the only child node of the a-tag in target will be an img-tag
var img_tag = target.childNodes[0];
// Take the "src", which names an image as "something_over.ext",
// Make it point to "something.ext"
// This is done with a regular expression
img_tag.src = img_tag.src.replace(/-over(\.[^.]+)$/, '$1');
}

function displayRightTab(id,link) {
	var currentValue = $(id).style.display;
	var div = document.getElementsByTagName('div');
	
	for (var i=0;i<div.length;i++) {
		if (div[i].className != 'propertyBox') {
			continue;
		}
		
		if (div[i].className == 'propertyBox' && div[i].getAttribute('id') != id) {
			div[i].style.display = 'none';
		} else {
			div[i].style.display = 'block';
			link.style.border = 'none';
			
		}
	}
}

function hideRightTab() {
	var div = document.getElementsByTagName('div');
	var total = 0;
	
	for (var i=0;i<div.length;i++) {
		if (div[i].className != 'propertyBox') {
			continue;
		} else {
			total++;
		}
		if (total == 1) {
			div[i].style.display = 'block';
		} else {
			div[i].style.display = 'none';
		}
	}
}

function setDiv(id){
	
	cookieValue = readCookie(id);	
	
	if (cookieValue == 'Appear') {
		new Effect.Appear(id);
		setCookie(id,'Appear',1) ;
	}else if (cookieValue == 'Fade') {
		new Effect.Fade(id);	
		setCookie(id,'Fade',1) ;
	}else{
		new Effect.Fade(id);
		setCookie(id,'Fade',1) ;
	}
}

function divToggle(id){
	
	cookieValue = readCookie(id);
	
	if (cookieValue == 'Fade') {
		new Effect.Appear(id);
		setCookie(id,'Appear',1) ;
	}else if (cookieValue == 'Appear') {
		new Effect.Fade(id);	
		setCookie(id,'Fade',1) ;
	}
}

function setCookie(name,value,days) {
   if (days) {
     var date = new Date();
     date.setTime(date.getTime()+(days*24*60*60*1000));
     var expires = ";expires="+date.toGMTString();
   } else {
     expires = "";
   }
   document.cookie = name+"="+value+expires+";path=/";
  }

function readCookie(name) {
  	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}
// The addLoadEvent function takes as an argument another function which should be executed once the page has loaded.
// Unlike assigning directly to window.onload, the function adds the event in such a way that any previously added onload
// functions will be executed first.
function addLoadEvent(func) {
	var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

// When the page loads, set up the rollovers

addLoadEvent(function() {
	setupRollovers();
	hideRightTab();
});
