window.addEvent('domready', function(){
    /* this makes it possible for links to the currently loaded page to be styled */
    $$('a').each(function(a){
        if (a.attributes.href.nodeValue != '#' && // skip js onclick links 
            a.pathname == location.pathname) a.addClass('currentLink')
        else a.removeClass('currentLink')
    })
})
window.addEvent('domready',function() {
    /* setup jd.gallery, using body classes to toggle timed and embedLinks */
	 
	
    if (! $('gallery')) { return 0 }
    g = new gallery($('gallery'), {
        timed: $$('body')[0].hasClass('timed'), delay: 4000,
        showArrows: false, showInfopane: false, showCarousel: false,
        embedLinks: $$('body')[0].hasClass('embedLinks')
    });
	if ($$('body')[0].hasClass('ctrlLinks')) {
        /* this is a messey way of adding the prev/next and numbered links,
              ... but it works for now. */
        cl=new Element('ul').setProperties({id:'ctrl'}).injectAfter($('gallery'))
        new Element('img').setProperties({src:'img/prev.gif', alt:'prev'}).injectInside(
            new Element('a').setProperties({href:'#',onclick:'g.prevItem(); return false',
                                            title:'previous'}).injectInside(
                                                new Element('li').injectInside(cl)))
        new Element('img').setProperties({src:'img/next.gif', alt:'next'}).injectInside(
            new Element('a').setProperties({href:'#',onclick:'g.nextItem(); return false',
                                            title:'next'}).injectInside(
                                                new Element('li').injectInside(cl)))
        for (i=0; i<g.maxIter; i++) {
            new Element('a').setProperties({href:'#', onclick:'g.goTo('+i+'); return false'
                                           }).setText(i+1).injectInside(
                new Element('li').setProperties({
                    'class':'li_i'}).injectInside(cl))
        }
    }
    g.addEvent('onChanged', function(){
        $$('#ctrl .li_i a').each(function(o,i) {
            o.className = (i == g.currentIter ? 'currentLink' : '')
        })
    })
    g.fireEvent('onChanged')
})

