/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



KikLightbox = Class.create();
KikLightbox.prototype = {
    initialize : function(){
        if($('lightbox')==null){
            this.lightboxBg = new Element('div', {
                id:'lightbox-bg'
            });
            this.lightboxBg.observe('click', this.hide.bind(this));
            this.lightboxContainer = new Element('div', {
                id:'lightbox-container'
            });
            this.lightboxHeader = new Element('h2', {
                id:'lightbox-header'
            });
            this.lightboxContent = new Element('div', {
                id:'lightbox-content'
            });
            this.lightboxCloser = new Element('a', {
                id:'lightbox-closer'
            }).update('<span>x</span>');
            this.lightboxCloser.observe('click', this.hide.bind(this));
            this.lightbox = new Element('div', {
                id:'lightbox', 
                style:'visibility: hidden'
            });
            this.lightboxContainer.insert(this.lightboxCloser);
            this.lightboxContainer.insert(this.lightboxHeader);
            this.lightboxContainer.insert(this.lightboxContent);
            this.lightbox.insert(this.lightboxBg);
            this.lightbox.insert(this.lightboxContainer);
            $$('body')[0].insert(this.lightbox);
//            Event.observe(window, 'load', this.centralize.bind(this));
        }
    },
    show : function(){
        this.lightbox.appear({
            duration: 0.7
        });
    },
    hide : function(){
        this.lightbox.fade({
            duration: 0.5
        });
        this.lightboxContent.update('');
    },
    centralize: function(){
        var D = document;
        var maxHeight = Math.max(
            Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
            Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
            Math.max(D.body.clientHeight, D.documentElement.clientHeight)
            );
        this.lightboxBg.setStyle({
            height: maxHeight+'px'
            });
        var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
        var width = viewport.width; // Usable window width
        var height = viewport.height; // Usable window height
        var lightboxCont = this.lightboxContainer.getDimensions();
        var contwidth = lightboxCont.width;
        var contheight = lightboxCont.height;
        var posX = (width - contwidth)/2;
        var posY = (height - contheight)/2;
        
        this.lightboxContainer.setStyle(
        {
            top: posY+'px',
            left: posX+'px'
        });
		
        this.lightbox.setStyle({
            visibility: 'visible', 
            display: 'none'
        });
    },
    setContent: function(html){
        this.lightboxContent.update(html);
    }
}

var KikZoomoViewer = Class.create();
KikZoomoViewer.prototype = {
    initialize : function(imageStr, target){
        var images = imageStr.split(';');
        var zv = new ZoomoViewer();
        zv.serverName = "http://kikzoom.zoomoviewer.com";
        zv.clientID = 1088090;
        zv.width = 600;
        zv.height = 500;
        zv.addPlugIn("gui_default");
        zv.addPlugIn("gallery_default");
        
        for(var i=0; i<images.length; ++i){
            if(images[i] != '')
                zv.addImage(images[i].replace(/\s+/g,''));
        
        }
        zv.start('#'+target);

    }  
};

var lightbox = null;
Event.observe(window, 'load', function(){
    lightbox = new KikLightbox();
    lightbox.centralize();
});
