﻿
/* Photo Galleries Class */
var Galleries = Class.create({
    initialize: function() {
        this.li_galleries = $$("ol#galleries > li");
        this.li_mainGallery = this.li_galleries[0];
        
        // Mimic the :first-child select for IE6
        this.li_mainGallery.addClassName("first-child");
        
        for(var g=0; g < this.li_galleries.length; g++) {
            var galTitleRaw = this.li_galleries[g].select("div.primary_image h4")[0].innerHTML.stripTags();
            var galTitle = galTitleRaw.substring(0,galTitleRaw.indexOf("(")-1);
            var ol_imgList = this.li_galleries[g].select("ol")[0];
        	var a_firstImgLink = this.li_galleries[g].select("div.primary_image > a")[0];
        	var a_imgLinks = ol_imgList.select("li a");
            
        	a_imgLinks[0].remove(); // This is a duplicate of the link around the primary image
        	
            ol_imgList.hide(); // The list of image links below the primary image should be hidden for users with JavaScript enabled
            
            this.setImgLink(a_firstImgLink, a_imgLinks[0].innerHTML, galTitle);
            
            for(var i=0; i < a_imgLinks.length; i++) {
                this.setImgLink(a_imgLinks[i], a_imgLinks[i].innerHTML, galTitle);
            }
        }
        
        // Run the lightwindow script now so it works in IE6
        lightwindowInit();
    },
    
    setImgLink: function(a, title, gallery) {
		a.writeAttribute({
            "class": "lightwindow",
            "title": title,
            "rel": "Photo Gallery["+gallery+"]"
        });
    }
});


document.observe("dom:loaded", function() {
    photoGalleries = new Galleries();
});