if (typeof fv_views_vote == "undefined") {
	var fv_views_vote = {};
}

fv_views_vote.addScript = function(url) {
    var script = document.createElement('script');
	script.type = 'text/javascript';
    script.src = url;

	fv_views_vote.script = script;
//    document.body.appendChild(script);
	document.getElementsByTagName("head")[0].appendChild(script);
};

fv_views_vote.removeScript = function() {
	if (fv_views_vote.script) {
		document.getElementsByTagName("head")[0].removeChild(fv_views_vote.script);
	}
}

fv_views_vote.vote = function(photoId, index){
	var sUrl = 'http://' + top.location.host + '/views/photo_vote_js.jsp?id=' + photoId;
	fv_views_vote.index = index;
	fv_views_vote.addScript(sUrl);

//	alert(sUrl);
//	alert(fv_views_vote.status);
//	alert(fv_views_vote.message);


}; 

fv_views_vote.callback = function(response) {
	fv_views_vote.removeScript();
//	var response = eval(data);

	if (response.status == 'success') {
	    var numVotesElem = document.getElementById('vote_count');
		if (numVotesElem) {
			numVotesElem.innerHTML = response.num_votes;
			// We need to update the array also. How to get image index?
			imageArray[fv_views_vote.index][10] = response.num_votes;
		}
	}
	opacity('vote_panel', 0, 100, 300);
};

