/* whowasbest.com */
var c1pointtotal = 1;
var c2pointtotal = 1;

window.onload = function init() {
	/* Slogans */
	var slogan = new Array(0);
	slogan.push("You decide.");
	slogan.push("The age old question.");
	slogan.push("Because everybody's a fanboy.");
	slogan.push("All your votes are belong to us.");
	slogan.push("We're impartial. Honest.");
	slogan.push("Ya rly.");
	slogan.push("Let the flamewars begin.");
	slogan.push("Don't hate, deliberate.");
	slogan.push("We be votin'");
	slogan.push("No comment.");
	slogan.push("Beta. Only joking.");
	var i = Math.floor(slogan.length*Math.random())
	if (document.getElementById("slogan")){
		document.getElementById("slogan").innerHTML = slogan[i];
	}
	/* Results hover effect */
	var elements = document.getElementsByTagName("li");
	for (var i=0; i < elements.length; i++) {
		if (elements[i].className.match("result")) {
			elements[i].onmouseout = lowlight;
			elements[i].onmouseover = highlight;
		}
	}
	/* IE6 only min-width fix */
	if (navigator.appVersion.match("MSIE 6.0") && 
		!navigator.appVersion.match("MSIE 7.0") && 
		!navigator.appVersion.match("MSIE 5.5")){
		if(document.getElementById("maincontainer")){
			minWidth();
			window.onresize = minWidth;
		}
	}
	/* Match creation form stuff */
	if(document.getElementById("title1")){
		document.getElementById("title1").onchange = updateName1;
	}
	if(document.getElementById("title2")){
		document.getElementById("title2").onchange = updateName2;
	}
	/* Match creation */
	if(document.getElementById("c1add")){
		document.getElementById("c1add").onclick = addPoint1;
		document.getElementById("c1add").style.width = "10em";
		document.getElementById("c1add").style.marginLeft = "3em";
	}
	if(document.getElementById("c2add")){
		document.getElementById("c2add").onclick = addPoint2;
		document.getElementById("c2add").style.width = "10em";
		document.getElementById("c2add").style.marginLeft = "3em";
	}
}

function addPoint1(){
	var element = document.createElement("li");
	var list = document.getElementById("c1points");
	var name = "c1_p" + c1pointtotal;
	var char = '"';
	list.appendChild(element);
	element.id = name + "li";
	element.innerHTML = "<textarea cols='100' rows='5' style='width:90%;height:4em;font-size:1.2em;' name='"+name+"' id='"+name+"'/></textarea> <img src='/images/homepage/cross.png' style='border:0;cursor:pointer;' onclick='deletePoint("+char+name+"li"+char+");'/>";
	element.className = "c1point";
	c1pointtotal += 1;
}

function addPoint2(){
	var element = document.createElement("li");
	var list = document.getElementById("c2points");
	var name = "c2_p" + c2pointtotal;
	var char = '"';
	list.appendChild(element);
	element.innerHTML = "<textarea cols='100' rows='5' style='width:90%;height:4em;font-size:1.2em' name='"+name+"' id='"+name+"'/></textarea> <img src='/images/homepage/cross.png' style='border:0;cursor:pointer;' onclick='deletePoint("+char+name+"li"+char+");'/>";
	element.id = name + "li";
	element.className = "c2point";	
	c2pointtotal += 1;
}
function deletePoint(point){
	var element = document.getElementById(point);
	element.parentNode.removeChild(element);
}

function updateName1(){
	var element = document.getElementById("name1");
	if (element.value == ""){
		element.value = this.value;
	}
}

function updateName2(){
	var element = document.getElementById("name2");
	if (element.value == ""){
		element.value = this.value;
	}
}

function lowlight(){
	this.style.backgroundImage = "url(http://www.whowasbest.com/themes/Anonimistic/images/homepage/listbackground.gif)";
	this.style.borderBottom = "1px solid #111";
}

function highlight(){
	this.style.backgroundImage = "url(http://www.whowasbest.com/themes/Anonimistic/images/homepage/listbackground2.gif)";
	this.style.borderBottom = "1px solid #8dca23";
}

function minWidth() {
	if(document.documentElement.clientWidth < 900){
		document.getElementById("maincontainer").style.width = "780px";
	}else{
		document.getElementById("maincontainer").style.width = "85%";
	}
}
function showElement(id, type){
	var i = document.getElementById(id);
	if (i){
		i.style.display = type || '';
	}
}
function hideElement(id){
	var i = document.getElementById(id);
	if (i){
	        i.style.display = 'none';
	}
}