/**
 * @Author: Luca Filosofi > {aSeptik} @gmail.com (c) '09
 * @Release Date: 29.09.2009
 * @Last Update: 19.12.2009
 *
 */
var $J = jQuery.noConflict();
/**
  * ajax location for e107
  *  
  */
var rating_url = new
function() {

    var currentURL = window.location;

    this.href = currentURL.href;
    // Displays 'http://www.example.com:80/example.cgi?x=3&y=4#results'
    this.protocol = currentURL.protocol;
    // Displays 'http:'
    this.host = currentURL.host;
    // Displays 'www.example.com:80'
    this.hostname = currentURL.hostname;
    // Displays 'www.example.com'
    this.port = currentURL.port;
    // Displays '80'
    this.pathname = currentURL.pathname;
    // Displays '/example.cgi'
    //this.search = currentURL.search;
    // Displays '?x=3&y=4'
    this.hash = currentURL.hash;
    // Displays '#results'

    this.loc = function() {

        var clenPath = this.pathname.substring(0, this.pathname.lastIndexOf('/') + 1);


        if (clenPath.indexOf('e107_plugins') !== -1) {

            var addreess = clenPath;

        } else {

            var addreess = 'e107_plugins/ratings/';

        }

        return addreess;

    };

    this.search = function() {
        var urlQuery = currentURL.search.split('?');
        return urlQuery[1];
    }


}



/**
 * Rate function
 *
 */
function rateThis(parameterString, id) {
          
    var query = 'action=ratings&query=' + parameterString;

    $J('#response-' + id).fadeOut(200);
    
    $J.ajax({
        type: 'POST',
        url: rating_url.loc() + 'ajax.php',
        data: query,
        cache: false,
        complete: function(data) {

            $J('#response-' + id).html(data.responseText).fadeIn(200);
        },
        error: function() {
            alert('Ajax Request ' + query + ' Error!');
            //handle if error!
        }
    });

    return false;

};