var thankYouImage = "http://imageroot.marketfusion.com/image/ratesaved.gif";
var starImages = new Array("http://imageroot.marketfusion.com/image/ratestars0.gif",
                              "http://imageroot.marketfusion.com/image/ratestars1.gif",
                              "http://imageroot.marketfusion.com/image/ratestars2.gif",
                              "http://imageroot.marketfusion.com/image/ratestars3.gif",
                              "http://imageroot.marketfusion.com/image/ratestars4.gif",
                              "http://imageroot.marketfusion.com/image/ratestars5.gif");
var starMessages = new Array("http://imageroot.marketfusion.com/image/ratetext0.gif",
                              "http://imageroot.marketfusion.com/image/ratetext1.gif",
                              "http://imageroot.marketfusion.com/image/ratetext2.gif",
                              "http://imageroot.marketfusion.com/image/ratetext3.gif",
                              "http://imageroot.marketfusion.com/image/ratetext4.gif",
                              "http://imageroot.marketfusion.com/image/ratetext5.gif",
                              "http://imageroot.marketfusion.com/image/ratetextsaved.gif");
var nullStarMessage = "http://imageroot.marketfusion.com/image/rate.gif";
var starMap =
	new Array(
		'0,0,14,20',
		'15,0,30,20',
		'31,0,43,20',
		'44,0,56,20',
		'57,0,69,20',
		'70,0,82,20');

var savedRatings = new Array();
var changedRatings = new Array();
var starTwinkler = new Array();
var msgTwinkler = new Array();
var delayTime = 200;
var allImages = new Array();

function mf_js_preloadImages(){
  for (i=0; i < mf_js_preloadImages.length ;i++){
    allImages[i] = new Image();
    allImages[i].src = mf_js_preloadImages.arguments[i];
  }
}

mf_js_preloadImages(starImages);
mf_js_preloadImages(thankYouImage);
mf_js_preloadImages(starMessages);

function mf_js_sendRating (target, id, ratingType, ratingValue)
{
	window.location.href = target+'&rating=' + ratingValue ;
}

function mf_js_swapStars(id, rating)
{
  if (rating == undefined){
    rating = savedRatings[id];
  }
  document.images["stars." + id].src = starImages[rating];
}

function mf_js_swapStarMsgs(id, rating){
  if (rating == undefined){
    if ( changedRatings[id] ) {
      document.images["messages." + id].src = starMessages[6];
    } else {
      document.images["messages." + id].src = nullStarMessage;
    }
  } else {
    document.images["messages." + id].src = starMessages[rating];
  }
}

function mf_js_sendStars(target, id, rating){
  savedRatings[id] = rating;
  changedRatings[id] = 1;
  mf_js_sendRating(target, id, 'onetofive', rating);
  mf_js_swapStarMsgs(id, 6);
}

function mf_js_starMouseOver(id, rating){
        if (starTwinkler[id] != 0){
    window.clearTimeout(starTwinkler[id]);
    starTwinkler[id] = 0;
  }
  if (msgTwinkler[id] != 0){
    window.clearTimeout(msgTwinkler[id]);
    msgTwinkler[id] = 0;
  }  
  mf_js_swapStars(id, rating);
  mf_js_swapStarMsgs(id, rating);
}

function mf_js_starMouseOut(id){
  starTwinkler[id] = window.setTimeout("mf_js_swapStars('"+id+"')", delayTime);
  msgTwinkler[id] = window.setTimeout("mf_js_swapStarMsgs('"+id+"')", delayTime);
}


function mf_js_showStars(target, id, rating){
        var starID = "stars." + id;

  starTwinkler[id] = 0;
  msgTwinkler[id] = 0;

        document.write("<map name='starmap" + id +"'>");

        var i = 0;
        for (i = 0; i < 6; i++) {
          document.write("<area shape=rect " + 
        "coords='" + starMap[i] + "' " +
        "onMouseOver=\"mf_js_starMouseOver('" + id + "'," + i + ");\" " +
        "onMouseOut=\"mf_js_starMouseOut('" + id + "');\" " +
        "onClick=\"mf_js_sendStars('"+target+"','" + id + "'," + i + ");" +
        "\" >");
        }
        document.write("<\/map>");

        document.write("<img vspace=2 src='" + starImages[rating] + "'");
        document.write(" border=0 usemap='#starmap" + id);
        document.write("' id='" + starID + "'>");
}

function mf_js_showMessages(id, rating){
  var msgID = "messages." + id;
  if ( rating == undefined ) {
    document.write("<img vspace=2 height=16 src='" + nullStarMessage + "'");
    }
  else {
    document.write("<img vspace=2 height=16 src='" + starMessages[rating] + "'");    
  }
        document.write("' id='" + msgID + "'>");
}
