function roll_over(pic_name,pic_src) {
	if(document.images){
		document[pic_name].src=pic_src.src;
	}

}

function roll_over_star(pic_name,star_index) {
	if(document.images){
		for (i=1;i<star_index+1;i++) {
			document[pic_name+i].src=i_star_vote.src;
		}
	}

}

function roll_out_star(pic_name,star_index,current_index) {
	if(document.images){
		for (i=1;i<star_index+1;i++) {
			if (i<current_index+1) {
				document[pic_name+i].src=i_star.src;
			} else {
				document[pic_name+i].src=i_star_n.src;
			}
		}
	}

}

function getXMLHttp() {
  var xmlHttp

  try {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e) {
    //Internet Explorer
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e) {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}

function setCookie(name, value, expires, path, domain, secure) {
var theCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
if ((name + "=" + escape(value)).length <= 4000)
document.cookie = theCookie
}

function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function vote(num_stars,story_id) {
  
  if (getCookie('rating_cookie') == story_id) {
    document.getElementById('current-rating-result').innerHTML = 'You already voted on this story!';
	return;
  }
  
  var now = new Date()
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)
  setCookie('rating_cookie',story_id,now,'/');
	
  var xmlHttp = getXMLHttp();
 
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
      HandleResponse(xmlHttp.responseText);
    }
  }

  xmlHttp.open("GET", "index.php?p=interactive/rate/"+story_id+"/"+num_stars, true);
  xmlHttp.send(null);
  
}


function HandleResponse(response) {
  document.getElementById('current-rating-result').innerHTML = response;
}




function f_expand_contract(p_id) {
	
	the_id = eval(p_id);
	the_img = eval("expander_"+p_id);
	
	if (the_id.style.display=='none') {
		the_id.style.display = 'block';
		the_img.src = "http://www.eastoftheweb.com/interactive/images/in_i_contract.gif";
	} else {
		the_id.style.display = 'none';
		the_img.src = "http://www.eastoftheweb.com/interactive/images/in_i_expand.gif";
	}

}



if(document.images)	 {
	var i_children_h = new Image();
	i_children_h.src = "http://www.eastoftheweb.com/interactive/images/in_t_children_h.gif";
	var i_children = new Image();
	i_children.src = "http://www.eastoftheweb.com/interactive/images/in_t_children.gif";
	
	var i_crime_h = new Image();
	i_crime_h.src = "http://www.eastoftheweb.com/interactive/images/in_t_crime_h.gif";
	var i_crime = new Image();
	i_crime.src = "http://www.eastoftheweb.com/interactive/images/in_t_crime.gif";
	
	var i_fiction_h = new Image();
	i_fiction_h.src = "http://www.eastoftheweb.com/interactive/images/in_t_fiction_h.gif";
	var i_fiction = new Image();
	i_fiction.src = "http://www.eastoftheweb.com/interactive/images/in_t_fiction.gif";
	
	var i_horror_h = new Image();
	i_horror_h.src = "http://www.eastoftheweb.com/interactive/images/in_t_horror_h.gif";
	var i_horror = new Image();
	i_horror.src = "http://www.eastoftheweb.com/interactive/images/in_t_horror.gif";
	
	var i_humour_h = new Image();
	i_humour_h.src = "http://www.eastoftheweb.com/interactive/images/in_t_humour_h.gif";
	var i_humour = new Image();
	i_humour.src = "http://www.eastoftheweb.com/interactive/images/in_t_humour.gif";
	
	var i_nonfiction_h = new Image();
	i_nonfiction_h.src = "http://www.eastoftheweb.com/interactive/images/in_t_nonfiction_h.gif";
	var i_nonfiction = new Image();
	i_nonfiction.src = "http://www.eastoftheweb.com/interactive/images/in_t_nonfiction.gif";
	
	var i_romance_h = new Image();
	i_romance_h.src = "http://www.eastoftheweb.com/interactive/images/in_t_romance_h.gif";
	var i_romance = new Image();
	i_romance.src = "http://www.eastoftheweb.com/interactive/images/in_t_romance.gif";
	
	var i_scifi_h = new Image();
	i_scifi_h.src = "http://www.eastoftheweb.com/interactive/images/in_t_scifi_h.gif";
	var i_scifi = new Image();
	i_scifi.src = "http://www.eastoftheweb.com/interactive/images/in_t_scifi.gif";
	
	var i_home_h = new Image();
	i_home_h.src = "http://www.eastoftheweb.com/interactive/images/in_t_home_h.gif";
	var i_home = new Image();
	i_home.src = "http://www.eastoftheweb.com/interactive/images/in_t_home.gif";
	
	var i_star = new Image();
	i_star.src = "http://www.eastoftheweb.com/interactive/images/in_i_star.gif";
	var i_star_n = new Image();
	i_star_n.src = "http://www.eastoftheweb.com/interactive/images/in_i_star_n.gif";
	var i_star_vote = new Image();
	i_star_vote.src = "http://www.eastoftheweb.com/interactive/images/in_i_star_vote.gif";
}
