

/*--------------------------------drop down menus: */
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;
var amount = 0;
var full = 0;

function ddm_open()
{  ddm_canceltimer();
   ddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function ddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function ddm_timer()
{  closetimer = window.setTimeout(ddm_close, timeout);}

function ddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}
			
function roll_over(){
   var imgsrc = $(this).attr('src');
   var matches = imgsrc.match('_on');
	 if (!matches) {
	   imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif");
		 $(this).attr("src", imgsrcON);
	 }
}

function roll_out(){
   var imgsrc = $(this).attr('src');
	 imgsrcOFF = imgsrc.replace(/_on.gif$/ig,".gif");
	 $(this).attr("src", imgsrcOFF);
}

function writeDonateBar(id,amount,goal,full){
  meter = id2elem(id);
	if(amount >= goal){
	  amount = goal;
	}
	
  //amount/goal = width/full
	width = (full*amount)/goal;
  meter.style.width = (width)+"px";
}
	 
function id2elem(id) {
	if (typeof(id) != 'string') {
		return id;
	}
	if (document.getElementById) {
		id = document.getElementById(id);
	} else if (document.all) {
		id=document.all[id];
	} else {
		id = null;
	}
	return id;
}
function updateCopyBox(){
  runner = $('#runnerselect').val();
	anon = $('#anonymous').val();
	contactVal = $("input[@name='contact']:checked").val();
  $('#copybox').html('<span class="label">Runner:</span> '+runner+'<br /><span class="label">Anonymous?:</span> '+anon+'<br /><span class="label">Contact me?:</span> '+contactVal);
}

function anonSwitch(){
  if($('#anonymous').attr("checked")==true){
	  $('#anonymous').val("yes");
	}else{
	  $('#anonymous').val("no");
	}
	updateCopyBox();
}

function anonProfileSwitch(){
  if($('#anonymous_profile').attr("checked")==true){
	  $('#anonAnswer').html("yes");
	}else{
	  $('#anonAnswer').html("no");
	}	
}
function contactProfileSwitch(){
  if($("input[@name='contact_profile']:checked").val() == "yes"){
	  $('#contactAnswer').html("yes");
	}else{
	  $('#contactAnswer').html("no");
	}
}

document.onclick = ddm_close;
function centerdonate(){
  w = id2elem('iframewrapper');
	w.scrollLeft = 100;
}

$(document).ready(function()
{  
	 //dropdown menus
	 $('#ddm > li').bind('mouseover', ddm_open);
   $('#ddm > li').bind('mouseout',  ddm_timer);
	 
	 //rollovers
   $('#ddm > li > a > img').bind('mouseover',roll_over)   ;
   $('#ddm > li > a > img').bind('mouseout',roll_out);
	 
	 //donate form
	 $('#runnerselect').bind('change',updateCopyBox);
	 $('#anonymous').click(anonSwitch);
	 $('#anonymous_profile').click(anonProfileSwitch);
	 
	 $("input[@name='contact']").click(
	   function()
		 {
		   $(this).blur();
			 updateCopyBox();
		 }
	 );
	 $("input[@name='contact_profile']").click(
	   function()
		 {
		   $(this).blur();
			 contactProfileSwitch();
		 }
	 ); 
	 
	 $("span[@id='signin']").click(
	   function()
		 {
		   $("#loginform_wrapper").css("display","block");
			 $(this).css("display","none");
		 }
	);
});
