var imgCache = new Array();
var imgMemCache = new Array();

function preloadImages() {
  if (!document.images) return;
  var args = preloadImages.arguments;
  for (var i = 0; i < args.length; i+=2) {
    imgCache[args[i]] = new Image();
    imgCache[args[i]].src = args[i+1];
  }
}

function swapImage(objName, key, remember) {
  if (document.images && document.images[objName] && imgCache[key] &&
      document.images[objName].src != imgCache[key].src) {
    if (remember) {
      rememberImage(objName);
    }
    document.images[objName].src = imgCache[key].src;
  }
}

function rememberImage(objName) {
  if (document.images && document.images[objName]) {
    imgMemCache[objName] = document.images[objName].src;
  }
}

function restoreImage(objName) {
  if (document.images && document.images[objName] && imgMemCache[objName] &&
      document.images[objName].src != imgMemCache[objName].src) {
    document.images[objName].src = imgMemCache[objName];
  }
}

function storedImage(objName, allURI) {
  var src = "";
  if (imgMemCache[objName]) {
    src = imgMemCache[objName];
    if (!allURI) {
      var pathOffset = src.indexOf("//");
      if (pathOffset >= 0) {
        pathOffset = src.indexOf("/", pathOffset + 2);
        if (pathOffset >= 0) {
          src = src.substring(pathOffset);
        }
      }
    }
  }
  return src;
}

preloadImages("nostars", "/images/A/common/icons/nostars.gif",
              "starHover05", "/images/A/common/icons/stars_3_05.gif",
              "starHover10", "/images/A/common/icons/stars_3_10.gif",
              "starHover15", "/images/A/common/icons/stars_3_15.gif",
              "starHover20", "/images/A/common/icons/stars_3_20.gif",
              "starHover25", "/images/A/common/icons/stars_3_25.gif",
              "starHover30", "/images/A/common/icons/stars_3_30.gif",
              "starHover35", "/images/A/common/icons/stars_3_35.gif",
              "starHover40", "/images/A/common/icons/stars_3_40.gif",
              "starHover45", "/images/A/common/icons/stars_3_45.gif",
              "starHover50", "/images/A/common/icons/stars_3_50.gif",
              "starVote05", "/images/A/common/icons/stars_2_05.gif",
              "starVote10", "/images/A/common/icons/stars_2_10.gif",
              "starVote15", "/images/A/common/icons/stars_2_15.gif",
              "starVote20", "/images/A/common/icons/stars_2_20.gif",
              "starVote25", "/images/A/common/icons/stars_2_25.gif",
              "starVote30", "/images/A/common/icons/stars_2_30.gif",
              "starVote35", "/images/A/common/icons/stars_2_35.gif",
              "starVote40", "/images/A/common/icons/stars_2_40.gif",
              "starVote45", "/images/A/common/icons/stars_2_45.gif",
              "starVote50", "/images/A/common/icons/stars_2_50.gif",
              "starAvg05", "/images/A/common/icons/stars_1_05.gif",
              "starAvg10", "/images/A/common/icons/stars_1_10.gif",
              "starAvg15", "/images/A/common/icons/stars_1_15.gif",
              "starAvg20", "/images/A/common/icons/stars_1_20.gif",
              "starAvg25", "/images/A/common/icons/stars_1_25.gif",
              "starAvg30", "/images/A/common/icons/stars_1_30.gif",
              "starAvg35", "/images/A/common/icons/stars_1_35.gif",
              "starAvg40", "/images/A/common/icons/stars_1_40.gif",
              "starAvg45", "/images/A/common/icons/stars_1_45.gif",
              "starAvg50", "/images/A/common/icons/stars_1_50.gif"
              );

var ratingTimers = new Array();
var ratingId = 0;

function clearStatusbar() {
    window.setTimeout("window.status = '';", 1);
}

function restoreRatingState(id) {
    restoreImage("stars" + id);
}

function rememberRatingState(id) {
    rememberImage("stars" + id);
    ratingId = id;
}

function leaveRating(id) {
    if (!ratingTimers[id]) {
      ratingTimers[id] = window.setTimeout("restoreRatingState(" + id + ");", 100);
    }
}

function hoverRating(id, vote) {
    clearStatusbar();

    if (ratingTimers[id] > 0) {
      window.clearTimeout(ratingTimers[id]);
      ratingTimers[id] = 0;
    }
    if (ratingId != id) {
      if (ratingId > 0) {
        restoreRatingState(ratingId);
      }
      rememberRatingState(id);
    }

    if (vote > 0) {
        if (vote <= 1) {
         swapImage("stars" + id, "starHover05");
        } else {
         swapImage("stars" + id, "starHover" + (vote*5));
        }
    }
}

function clickRating(id, vote, profileId) {
	voteUrl = "/index/index?p_ID=110&script=zicprofil/bewertung&layerID=rating&fr=" + Math.random() + "&rate_profile=1&rating=" + vote + "&profile_id=" + profileId;

    /*
 		document.images["vote" + id].src = voteUrl;
	 */
	user_status = returnUserStatus();
	if(user_status===false)
	{
		showStandardLayer.htmlRequest('914','110','', {}, {});
	}else if (vote > 0) {
	    window.location.href = voteUrl;

		var starVote = 'starVote'+vote*10;
        if (starVote <= 5) {
         swapImage("stars" + id, "starVote05");
        } else {
         swapImage("stars" + id, starVote);
        }
    	rememberRatingState(id);
    }
}


