// Deadcreative

// this function controls the 'you are here' effect

window.onload = function() {
	if (document.getElementsByTagName) {
		var body_id = document.getElementsByTagName("body").item(0);
		var page_id = body_id.getAttribute("id");
		//alert(page_id);
		if (page_id == "terms" || page_id == "enter") {
			setCookie("nav_state", "");	
		}
		else {
			var image_name = "b-" + page_id;
			var link_id = document.getElementById(image_name);
			link_id.setAttribute("src","img/" + image_name + "-over.gif");
			// set a cookie so the browser remembers
			setCookie("nav_state", image_name);
		}
		if (page_id == "Contact") {
			checkAddressState();
		}
		else {
			setCookie("form_state","none");
		}
	}
	stoopidIE6();
}

// this function tells IE6 to do the image rollover

stoopidIE6 = function() {
	var items = getElementsByClassName(document, "img", "thumb");
	for (var i=0; i<items.length; i++) {
		items[i].onmouseover = function() {
			this.style.border = "1px dashed #999";
		}
		items[i].onmouseout = function() {
			this.style.border = "1px solid #ccc";
		}
	}
}

// a function that lets me get all the items with a certain class name

getElementsByClassName = function(oElm, strTagName, strClassName){
    //alert(oElm + " + " + strTagName  + " + " +  strClassName);
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];  
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements); // returning 15
	
}

// navigation rollover control

rollover = function(name,over) {
	if (document.getElementById) {
		var link_element = document.getElementById(name);
		
		var current_page = readCookie("nav_state");
		//alert(current_page);
		
		if (current_page != name) {
			if (over) {
				link_element.setAttribute("src","img/" + name + "-over.gif");
			}
			else {
				link_element.setAttribute("src","img/" + name + ".gif");
			}
		}
	}
}

setCookie = function (name, value) {
	document.cookie = name + "=" + value;
}

readCookie = function(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// showcase image swap

showcase = function(image_id,link_id) {
	var target = document.getElementById("showcase-thumbs");
	var thumbs = target.getElementsByTagName("a");
	
	var thumbs_length = thumbs.length;
	
	for (i=0; i < thumbs_length; i++) {
		thumbs[i].style.borderWidth = '2px';
		thumbs[i].style.borderStyle = 'solid';
		thumbs[i].style.borderColor = '#fff';
	}

	img_holder = document.getElementById("showcase-full-image")
	img_holder.setAttribute("src","img/" + image_id);
	
	link_hover = document.getElementById(link_id)
	link_hover.style.borderWidth = '2px';
	link_hover.style.borderStyle = 'solid';
	link_hover.style.borderColor = '#CCFF33';
}

// this function controls the thumb over state

thumb_control = function(thumbs,thumbs_length) {
	for (i=0; i<thumbs_length; i++) {
		thumbs[i].style.borderWidth = '2px';
		thumbs[i].style.borderStyle = 'solid';
		thumbs[i].style.borderColor = '#fff';
	}
}
