/**
 * /public_html/javascript/functions.js
 *
 * @author    Ahmed Chafik (admin@achafik.com)
 * @copyright aChafik 2007
 * @version   Define("Id: functions.js,v 1.00 2007/10/07 16:36:56 Ahmed")
 * <script>
 */

function _gel( id ) {
  return document.getElementById(id);
}

var page = {

    agent : navigator.userAgent.toLowerCase(),

    Setup : function() {

        initPM(1, 5, 0, 0, 1);
        addReflections();

    }


}

window.onload = window.onresize = page.Setup;

/**
  Rating Class
 */
function rating() {
    this.nrating = 1;
    this.object = new Object();
    this.bg = new Array();
}

rating.prototype.highlight = function(object, rating) {
  var list = object.parentNode.childNodes;

    var ix = 0;
    for (var i = 0; i < list.length; i++) {
      var node = list[i];
      if (node.nodeName != "LI") continue;

        node.className += " " + ((++ix > rating) ? 'in' : '') + "active";

    }

  return;
};

rating.prototype.blur = function(object) {
  var list = object.parentNode.childNodes;

    for (var i = 0; i < list.length; i++) {
      var node = list[i];
      if (node.nodeName != "LI") continue;

        while (node.className.indexOf('active') >= 0) {
            node.className = node.className.replace(" active", "");
            node.className = node.className.replace("active", "");
        }

        while (node.className.indexOf('inactive') >= 0) {
            node.className = node.className.replace(" inactive", "");
            node.className = node.className.replace("inactive", "");
        }

    }

  return;
};

rating.prototype.set_rating = function() {
  var list = this.object.parentNode.childNodes;

    var ix = 0;
    for (var i = 0; i < list.length; i++) {
      var node = list[i];
      if (node.nodeName != "LI") continue;

        if (++ix <= this.nrating)
            node.className = "current_self";
        else
            node.className = "";

    }

  return;
};

rating.prototype.add = function(vid, nrating, object) {
    this.nrating = nrating;
    this.object = object;

    request_handler.send('view.php?vid=' + vid + '&rating=' + nrating, '', function() {

        // Not ready yet?... That's alright
        if (request_handler.handler.readyState != 4 || request_handler.handler.status != 200)
          return;

        // Process our data
        alert(request_handler.handler.responseText);
        if (request_handler.handler.responseText.toLowerCase().indexOf('thank you') >= 0) {
            rating.set_rating();
        }

    });

};

var rating = new rating();
