$(document).ready(function(){
	$("div.itemCopy").hide();
	
	$("div.itemLink").each(function(x){
		this.id = "link"+x;
		this.onclick = function(){
			checkItem(x);
		};
	});
	$("div.itemCopy").each(function(x){
		this.id = "copy"+x;
	});
	
	$("div.itemLink").mouseover(function(){
		$(this).addClass("over");
	});
	$("div.itemLink").mouseout(function(){
		$(this).removeClass("over");
	});
});





function checkItem(wItem) {
	var current=null;
	var links = $("div.itemLink");
	for(var x=0; x<links.length; x++){
		if(links[x].className.indexOf("current") != -1) {
			current = x;
		}
	}
	
	if((current == null) || (current == wItem)) {
		toggleItem(wItem);
	} else {
		hideItem(current, wItem);
	}
}



function showItem(wItem) {
	$("#copy"+wItem).slideDown("slow");
	$("#link"+wItem).addClass("current");
}
function hideItem(wItem, wNextItem) {
	$("#copy"+wItem).slideUp("slow", function() {showItem(wNextItem);});
	$("#link"+wItem).removeClass("current");
}
function toggleItem(wItem) {
	$("#copy"+wItem).slideToggle("slow");
	$("#link"+wItem).toggleClass("current");
}




function searchFocus() {
	var el = document.getElementById("q");
	var defaultValue = el.value;
	if(el) {
		el.onfocus= function() {
			if(this.value == defaultValue) {
				this.value = "";
			}
		}
		el.onblur= function() {
			if(this.value == "") {
				this.value = defaultValue;
			}
		}
	}
}

function setFormBehaviour() {
	var el = document.getElementById("q");
	var defaultValue = el.value;
	if(el) {
		document.forms[0].onsubmit = function() {
			if(el.value == defaultValue) {
				document.location = "http://www.ask.com/";
				return false;
			}
		};
	}
}


addLoadEvent(pngForIe);
addLoadEvent(searchFocus);
addLoadEvent(setFormBehaviour);
