ratingComponent = function(id, script_url, append_querystring) {
	this.debug = false;
	if (this.debug && !document.getElementById(id)) alert('invalid id');
	this.container = document.getElementById(id);
	
	this.script_url = script_url;
	this.append_querystring = (typeof append_querystring == 'string')? append_querystring: '';
		
	this.imgcounter = 0;
	
	this.images = [];
	this.src = [];
	
	var img = this.container.getElementsByTagName('img');
	for (i=0; i<img.length; i++) {
		if (img[i].name = 'rating') {
			img[i].imgnumber = this.imgcounter;
			img[i].style.cursor = 'pointer';
			
			YAHOO.util.Event.addListener(img[i], 'mouseover', this.showRating, this);
			YAHOO.util.Event.addListener(img[i], 'mouseout', this.clearRating, this); 
			YAHOO.util.Event.addListener(img[i], 'click', this.setRating, this); 
			
			this.images[this.images.length] = img[i];
			this.src[this.src.length] = img[i].src;
			
			this.imgcounter++;
		}
	}
}

ratingComponent.prototype.setImageSources = function(img1, img2) {
	this.img1 = new Image();
	this.img1.src = img1;
	
	this.img2 = new Image();
	this.img2.src = img2;
}

ratingComponent.prototype.setActivityImage = function(img_id) {
	this.loading_img = document.getElementById(img_id);
}
	
	
ratingComponent.prototype.setRating = function(e, ratingComp) {
	if (typeof ratingComp.loading_img != 'undefined') {
		ratingComp.loading_img.style.visibility = 'visible';
	}
		
	for (i=0; i<ratingComp.images.length; i++) {
		YAHOO.util.Event.purgeElement(ratingComp.images[i]); 
		
		ratingComp.images[i].style.cursor = 'auto';
	}
	
	var callback = { 
		success: function(o) {
			if (typeof o.argument.loading_img != 'undefined') {
				o.argument.loading_img.style.visibility = 'hidden';
			}
			
			//alert(o.responseText);
		},
		
		argument: ratingComp
	} 
	
	var postdata = 'rating='+this.imgnumber+'&'+ratingComp.append_querystring;
	
	var request = YAHOO.util.Connect.asyncRequest('POST', ratingComp.script_url, callback, postdata); 
	
}
	
ratingComponent.prototype.showRating = function(e, ratingComp) {
	for (i=0; i<ratingComp.images.length; i++) {
		if (i <= this.imgnumber) {
			ratingComp.images[i].src = ratingComp.img1.src;
		} else {
			ratingComp.images[i].src = ratingComp.img2.src;
		}
	}
}
	
ratingComponent.prototype.clearRating = function(e, ratingComp) {
	for (i=0; i<ratingComp.images.length; i++) {
		ratingComp.images[i].src = ratingComp.src[i];
	}
}

