var oldydesc;
var oldxdesc;
function load_tally(id) {
	var http = false;

	if(navigator.appName == "Microsoft Internet Explorer") {
	  http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	  http = new XMLHttpRequest();
	}
	id = id.toString();
	http.open("GET", "/request/tally/"+id);
	http.onreadystatechange=function() {
	  if(http.readyState == 4) {
		
		percentages = http.responseText;
		bar = percentages.indexOf("|");
		x_percent = percentages.substr(0,bar);
		y_percent = percentages.substr(bar+1,percentages.length-bar-2);

		x_description_container = document.getElementById('x_description');
		y_description_container = document.getElementById('y_description');
		if(oldydesc == undefined) {
			oldxdesc = x_description_container.innerHTML;
			oldydesc = y_description_container.innerHTML;
		}

		x_description_container.innerHTML = '<div style="text-align:center;"><b>'+x_percent+'%</b><br /><embed src="/images/challenges/bars.swf?p='+x_percent+'&xory=x" width="75" height="300" wmode="transparent" /></embed></div>';
		y_description_container.innerHTML = '<div style="text-align:center;"><b>'+y_percent+'%</b><br /><embed src="/images/challenges/bars.swf?p='+y_percent+'&xory=y" width="75" height="300" wmode="transparent" /></embed><embed src="/images/challenges/slide.swf" width="0" height="0"></embed></div>';


		infobtn_obj = document.getElementById('infobtn');
		tallybtn_obj = document.getElementById('tallybtn');
		if(navigator.appName == "Microsoft Internet Explorer") {
			infobtn_obj.setAttribute("className", "");
			tallybtn_obj.setAttribute("className", "active"); 
		} else {
			infobtn_obj.setAttribute("class", "");
			tallybtn_obj.setAttribute("class", "active"); 
		}
	  }
	}
	http.send(null);

}
function load_info() {
	if(oldydesc != undefined) {
		x_description_container.innerHTML = oldxdesc;
		y_description_container.innerHTML = oldydesc;
		if(navigator.appName != "Microsoft Internet Explorer") {
			infobtn_obj.setAttribute("class", "active");
			tallybtn_obj.setAttribute("class", ""); 
		} else {
			infobtn_obj.setAttribute("className", "active");
			tallybtn_obj.setAttribute("className", ""); 
		}		
	}
}

function toggle_embed_options() {
		clearTimeout(collapse);
		eod = document.getElementById('embed_options');
		if(eod.style.display == "none" || eod.style.display == "") {
			eod.style.display = "block";
		} else {
			eod.style.display = "none";
		}
}
var collapse;
function update_embed_code(that,w,h,id,x_name,y_name,url) {
	clearTimeout(collapse);
	embed_code_input = document.getElementById('embed_code');
	w = w.toString();
	h = h.toString();
	id = id.toString();
	embed_code_input.value = '<object width="'+w+'" height="'+h+'"><param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" /><param name="movie" value="http://xversusy.com/widgets/contest_full.swf?id='+id+'" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><embed src="http://xversusy.com/widgets/contest_full.swf?id='+id+'" wmode="transparent" quality="best" bgcolor="#ffffff" width="'+w+'" height="'+h+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object><div style="text-align:center;width:'+w+'px;"><a href="http://xversusy.com/challenges/'+url+'">'+x_name+' vs. '+y_name+' @ X versus Y</a></div>';

	if(navigator.appName == "Microsoft Internet Explorer") {
		document.getElementById("widget_a").setAttribute("className","");
		document.getElementById("widget_m").setAttribute("className","");
		document.getElementById("widget_s").setAttribute("className","");
		
		that.setAttribute("className","sel");
	} else {
		document.getElementById("widget_a").setAttribute("class","");
		document.getElementById("widget_m").setAttribute("class","");
		document.getElementById("widget_s").setAttribute("class","");
		that.setAttribute("class","sel");
	}
	embed_code_input.focus();
	embed_code_input.select();
	collapse = setTimeout("toggle_embed_options()",5000);
}
function reply(id,username) {
	replyingtodiv = document.getElementById('replyingto');
	if(id == 0) {
		replyingtodiv.innerHTML = "Main Thread";
		document.commentform.parent_id.value = "";
	} else {
		replyingtodiv.innerHTML = "thread by " + username + " <a href='#bottom' onclick='reply(0,0)'>(cancel reply)</a>";
		document.commentform.parent_id.value = id;
	}
}
function youtube(vid,id) {
	yt = document.getElementById(id);
	yt.innerHTML = '<object width="213" height="172"><param name="movie" value="http://www.youtube.com/v/'+vid+'&hl=en&fs=1&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+vid+'&hl=en&fs=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="213" height="172"></embed></object>';
	
}
