﻿function LB_Image(nUrl,desc,nGroup,options)
{
    this.url = nUrl;
    this.description = desc;
    this.group = nGroup;
    this.className = (options)?options.className:options;
    this.width = (options)?options.width:options;
    this.height = (options)?options.height:options;
    this.toDOM = function()
    {
        var i = document.createElement("img");
        var a = document.createElement("a");
        
        a.href= this.url;
        a.onclick = function()
        {
            return false;
        }
        
        a.className = this.className;
        
        a.setAttribute("rel","lightbox["+this.group+"]");
        a.title = this.description;
        
        i.src = this.url;
                
        a.appendChild(i);  
        
        return a;          
    }
}

function LB_ImageSet(nUrlBase,groupName)
{
    this.base = nUrlBase;
    this.group = groupName;

    this.images = [];
    this.AddImage = function(iObj)
    {
        this.images.push(iObj);
    };
    
    this.Add = function(iUrl,iDesc,options)
    {
        
        this.AddImage(new LB_Image(this.base+iUrl,iDesc,this.group,options));
    }
    
    this.AddObj = function(iObj)
    {    
        this.AddImage(new LB_Image(this.base+iObj.url,iObj.desc,this.group,iObj.options));
    }
    
    this.toDOM = function(iUrl)
    {
        var d = document.createElement("div");
        //d.innerHTML = "<h3>"+this.group+"</h3>";        
        
        for(var i =0; i < this.images.length; i++)
        {
            d.appendChild(this.images[i].toDOM());
        }
		
		var br=document.createElement("br");
		
		d.appendChild(br);
        
        return d;
    }
}

var LightBoxBuilder = Class.create({
                            initialize: function()
                            {
                            },
                            ImageSets: [],
                            AddImageSet: function(base,groupName) // Additional Parameters will be parsed as images for the Image Set...
                            {
                                var iS = new LB_ImageSet(base,groupName);
                                
                                if(arguments.length>2)
                                {
                                    for(var i=2;i<arguments.length;i++)
                                    {
                                        iS.AddObj(arguments[i]);
                                    }
                                }
                                
                                this.ImageSets.push(iS);
                            },
                            toDOM: function()
                            {
                                var d = document.createElement("div");
                                for(var i =0; i < this.ImageSets.length; i++)
                                {
                                    d.appendChild(this.ImageSets[i].toDOM());
                                }
                                
                                return d;
                            }
                            
                      });
                      

