/* start zipped version Do Mai 12 16:08:50 CEST 2011 */
// diRating.js
jQuery.fn.diReview = function(opts) {
	var opts = opts || {};
    var className = 'input.review';

    if (opts.quickReview) {
        className = 'input.reviewQuick';
    }

    var style = 'float:right';
    if (opts.style) {
        style = opts.style;
    }

    jQuery(className).each( function(counter) {
		var jDiv = jQuery('<div class="review" style="' + style + '" id="' + jQuery.diReview.DIV_ID + this.id + '"></div>');

		for (var i=jQuery.diReview.MIN; i<=jQuery.diReview.MAX; i++) {
			var marg = (i==jQuery.diReview.MAX)? 0 : jQuery.diReview.MARG_RIGHT;
			jStar = jQuery('<div id="' + i + '"></div>')
						.css({
							width: marg + jQuery.diReview.W +'px',
							height: jQuery.diReview.H +'px',
							float: 'left'
						});
			if (!opts.readOnly) {
				jStar.bind('mouseover',jQuery.diReview.m_over)
					.bind('mouseout', jQuery.diReview.m_out)
					.bind('mousedown', jQuery.diReview.m_click);
			}
			jDiv.append(jStar);
        }
		jDiv.append(jQuery('<div></div>').css({ clear:'both' }));

		jQuery(this).after(jDiv);

		// get initial value and set it?
		var oInput = jQuery(this); //jQuery('#'+this.id);
		var points = parseInt(oInput.val(),10);
		oInput.attr('clicked','false');

		if (opts.clickfn) {
			oInput.attr('clickfn', ''+opts.clickfn)
		}

		if (opts.oneClickOnly) {
			oInput.attr('oneclickonly','true');
		} else {
			oInput.attr('oneclickonly','false');
		}

		var jDiv = jQuery('#'+jQuery.diReview.DIV_ID + this.id);

		if (points >= 0) {
			oInput.attr('clicked','true');
			jQuery.diReview.set_bg(jDiv, jQuery.diReview.get_y_clicked(points));
		}
	}).css('display','none').end();
	return this;
};

jQuery.diReview = {
	BG_IMG: 'images/punkte3.gif',	// star image
	TRANS_IMG: 'images/trans.gif',	// transparent image
    W: 19,							// width of single star
	H: 21,							// height of ~
	MARG_RIGHT: 1,					// right margin of each star
	DIV_ID: 'jDiv',
	ZERO_OFFSET: -132,
	MIN: 0,
	MAX: 5,

	m_over: function() {
		var oInput = jQuery.diReview.get_input(this);

		if (jQuery.diReview.is_clicked_once(oInput)) {
			return;
		}

		var points = parseInt(this.id,10);
		var jDiv = jQuery(this).parent().get(0);
		jQuery.diReview.set_bg(jDiv, jQuery.diReview.get_y(this, points, true));
	},
	m_out: function() {
		var oInput = jQuery.diReview.get_input(this);

		if (jQuery.diReview.is_clicked_once(oInput)) {
			return;
		}

		jQuery.diReview.show_rating(this, oInput.val());
	},
	m_click: function() {
		var oInput = jQuery.diReview.get_input(this);

		if (jQuery.diReview.is_clicked_once(oInput)) {
			return;
		}

		var points = parseInt(this.id, 10);

		oInput.val(points);
		jQuery.diReview.set_clicked(this);
		jQuery.diReview.show_rating(this, points);

		eval(oInput.attr('clickfn'));
	},
	is_clicked: function(obj) {
		var oInput = jQuery.diReview.get_input(obj);
		var clicked = oInput.attr('clicked');

		return (clicked == 'true');
	},
	set_clicked: function(obj) {
		var oInput = jQuery.diReview.get_input(obj);
		oInput.attr('clicked','true');

	},
	get_input: function (obj) {
		var sInput = jQuery(obj).parent().get(0).id;
		sInput = sInput.substring(jQuery.diReview.DIV_ID.length);
		return jQuery('#'+sInput);
	},
	show_rating: function(obj, points) {
		var jDiv = jQuery(obj).parent().get(0);
		jQuery.diReview.set_bg(jDiv, jQuery.diReview.get_y(obj, points, false));
	},
	is_clicked_once: function(oInput) {
		return (oInput.attr('oneclickonly') == 'true' && oInput.val() != '-1');
	},
	get_y: function(obj, strPoints, isOver) {
		var points = parseInt(strPoints,10);

		if (isOver) {
			return jQuery.diReview.get_y_over(points);
		} else {
			if (points < 0 || jQuery.diReview.is_clicked(obj)) {
				return jQuery.diReview.get_y_clicked(points);
			} else {
				return jQuery.diReview.get_y_standard(points);
			}
		}
	},
	get_y_clicked: function(points) {
 		return (((points + 1) * (jQuery.diReview.H + 1)) * -1) + jQuery.diReview.ZERO_OFFSET;
	},
	get_y_over: function(points) {
		return jQuery.diReview.ZERO_OFFSET + ((points + 1) * (jQuery.diReview.H + 1));
	},
	get_y_standard: function(points) {
		return jQuery.diReview.ZERO_OFFSET + (points * (jQuery.diReview.H + 1));
	},
	set_bg: function(obj, top) {
		jQuery(obj).css({backgroundPosition: '0 ' + top + 'px'});

	},
	init: function() {
	}
};

jQuery.diReview.init();
/* end zipped version Do Mai 12 16:08:50 CEST 2011 */

