/* - - - - - - - - - - - - - - - - - - - - - - -
 JavaScript
 29 ianuarie 2010 20:26:29
 HAPedit 3.1.11.111
 - - - - - - - - - - - - - - - - - - - - - - - */

/* - - - - - - - - - - - - - - - - - - - - - - -
  * You may use this code for free on any web page provided that
  * these comment lines and the following credit remain in the code.
  * Cross Browser Fireworks from http://www.javascript-fx.com
 - - - - - - - - - - - - - - - - - - - - - - - */

if(!window.JSFX)
{/*** Include Library Code ***/

JSFX = new Object();

// identificare obiect HTML dupa id
function getHTMLobj(id) {
    return document.getElementById ? document.getElementById(id) :
                                     document.all ? document.all[id] : document.layers[id];
}

var ns4 = document.layers;
var ie4 = document.all;
JSFX.objNo = 0;

JSFX.getObjId = function(){return "JSFX_obj" + JSFX.objNo++;};

JSFX.createLayer = function(theHtml, layerClass)
{
    var layerId = JSFX.getObjId();

    document.write(ns4 ? '<layer name="' + layerId + '" class="' + layerClass + '">' + theHtml + '</layer>' :
                         '<div id="' + layerId + '" class="' + layerClass + '" style="position:absolute; z-index:100; visibility:hidden;">'
                                     + theHtml + '</div>');
    var el = getHTMLobj(layerId);

    if(ns4) el.style = el;

    return el;
}
JSFX.fxLayer = function(theHtml, layerClass)
{
    if(theHtml == null) return;
    this.el = JSFX.createLayer(theHtml, layerClass);
}

JSFX.fxLayer.prototype.show = function()
{
    this.el.style.visibility = "";
}

JSFX.fxLayer.prototype.hide = function()
{
    this.el.style.visibility = "hidden";
}


/////////////////////////////////////////////////


/*** Class Photos ***/

JSFX.Photos = function(pathArray)
{
    if (pathArray == null) return;
    window[this.id = JSFX.getObjId()] = this;

    this.loadCount = 0;

    this.images  = new Array();
    this.numImages = pathArray.length;
    for (var i=0; i<this.numImages; i++)
    {
        this.images[i] = new Image();
        this.images[i].onload = this.imageLoaded(i);
        this.images[i].src = pathArray[i];
    }
}

JSFX.Photos.prototype.imageLoaded = function(no)
{
    this.images[no].obj = this;
    this.images[no].err = true;
    return function() {
           this.obj.images[no].err = false;
           this.obj.loadCount++;
    }
}

JSFX.Photos.prototype.isLoaded = function()
{
    return this.loadCount == this.numImages;
}

/*** Class Clasor extends FxLayer ***/

JSFX.Clasor = function(imgClass, layerClass, stopFunction)
{
    window[this.id = JSFX.getObjId()] = this;

    this.imgId = "i" + this.id;

    var html = '';
    html += '<img name="' + this.imgId + '" src="" alt="" class="' + imgClass + '" ';
    if (stopFunction) html += 'style="cursor: hand;" onClick="' + stopFunction + '" title="Click pentru terminare" ';
    html += '>';

    this.superC = JSFX.fxLayer;
    this.superC(html, layerClass);

    this.img = document.layers ? this.el.document.images[0] : document.images[this.imgId];

    this.pages = [];    // paginile clasorului
    this.page = 0;      // pagina curenta
    this.image = 0;     // imaginea curenta din pagina curenta
    this.settings = []; // parametrii pentru pagini

    this.height = "";   // inaltimea imaginii dupa incarcare (restrictionata eventual de imgClass)
    this.width  = "";   // latimea imaginii dupa incarcare (restrictionata eventual de imgClass)
}

JSFX.Clasor.prototype = new JSFX.fxLayer;

JSFX.Clasor.prototype.addPage = function(photos, frameTime) { // ataseaza obiecte Photos
                                                              // frameTime = timp de afisare frame [ms]
    if (photos instanceof Array)
       for (var i=0; i<photos.length; i++) {
           this.pages[this.pages.length] = photos[i];
           this.settings[this.pages.length-1] = {};
           this.settings[this.pages.length-1].frameTime = frameTime || 100;
       }
    else {
       this.pages[this.pages.length] = photos;
       this.settings[this.pages.length-1] = {};
       this.settings[this.pages.length-1].frameTime = frameTime || 100;
    }
    return this;
}

JSFX.Clasor.prototype.getDuration = function(page)
{
    if (page==null) page = this.page;
    return (this.pages[page].loadCount - 1) * this.settings[page].frameTime;
}

// uz intern
JSFX.Clasor.getImgDimensions = function(layer) {
    var photo = layer.pages[layer.page].images[layer.image];
    if (photo.err) return false;

    layer.img.style.height = "";
    layer.img.style.width  = "";
    layer.img.src = photo.src;

//    layer.height  = layer.img.height;
//    layer.width   = layer.img.width;

    layer.height = parseInt(CSSStyleSubject.getStyle(layer.img, "height"));
    layer.width  = parseInt(CSSStyleSubject.getStyle(layer.img, "width"));
    if (layer.height && layer.width) return true;

    if (layer.height)
       layer.width = parseInt(photo.width * layer.height / photo.height);
    else if (layer.width)
            layer.height = parseInt(photo.height * layer.width / photo.width);
         else {
            layer.height = photo.height;
            layer.width  = photo.width;
         }
    return true;
}
JSFX.Clasor.prototype.setFrame = function()
{
    this.image++;
    if (this.image>=this.pages[this.page].numImages) this.image = 0;

    return JSFX.Clasor.getImgDimensions(this);
}

JSFX.Clasor.prototype.nextFrame = function(sens)
{
    if (!sens) sens = 1;
    if (sens==1) {
       this.image++;
       if (this.image >= this.pages[this.page].numImages) this.nextPage(sens);
    } else {
       this.image--;
       if (this.image < 0) this.nextPage(sens);
    }

    return JSFX.Clasor.getImgDimensions(this);
}

JSFX.Clasor.prototype.setState = function(value) {
// Clasor devine subiect pt. Animator; value cuprins intre 0 si 1
//        la fiecare pas se afiseaza o imagine din pagina curenta
//    this.image = Math.round(value * (this.pages[this.page].numImages-1));
    this.image = Math.round(value * (this.pages[this.page].loadCount - 1));

    return JSFX.Clasor.getImgDimensions(this);
}

JSFX.Clasor.prototype.nextPage = function(sens)
{
//    if (random) {
//       this.page = parseInt(Math.random() * this.pages.length);
//    } else {
    if (!sens) sens = 1;
    if (sens==1) {
       this.page++;
       if (this.page >= this.pages.length) this.page = 0;
       this.image = 0;
    } else {
       this.page--;
       if (this.page < 0) this.page += this.pages.length;
       this.image += this.pages[this.page].numImages;
    }
///    }
//    this.image = 0;
}

JSFX.Clasor.prototype.alike = function(layer) { // cameleon pe layer
    with (this.el.style) {
         top  = layer.el.style.top;
         left = layer.el.style.left;
         height = layer.el.offsetHeight;
         width  = layer.el.offsetWidth;
    }
}

}


