
// Stuff to do on startup
jQuery(function() {

    // initialize the history plugin - this also loads the initial page
    jQuery.history.init(pageload);

    // setup all anchors to load pages into the right side.
    jQuery(".sign a").click(function() {
        var hash = this.href;
        hash = hash.replace(/^.*#/, '');
        jQuery.history.load(hash);
        return false;
    });

    jQuery('.sign a').mouseover(function() {
        jQuery('#traffic_light').addClass('traffic_light_green');
        jQuery('#route_letter').addClass('route_letter_'+jQuery(this).attr('route'));
    });

    jQuery('.sign a').mouseout(function() {
        jQuery('#traffic_light').removeClass('traffic_light_green');
        jQuery('#route_letter').removeClass('route_letter_'+jQuery(this).attr('route'));
    });


});

function pageload(hash) {
    hash = hash ? hash : 'home';

    jQuery("#content").load(hash + ".html",pageLoaded);
    jQuery('.sign a').removeClass("selected");
    jQuery('a[href=#'+hash+']').addClass('selected');

    
    if(hash == 'ceramics_2') {
        jQuery('a[href=#clay]').addClass('selected');
    }
}

function pageLoaded() {
    startGallery();

    // For IE6 pngfix
    if(jQuery.browser.msie) {
        var arVersion = navigator.appVersion.split("MSIE")
        var version = parseFloat(arVersion[1])
        if ((version >= 5.5 && version < 7)) {
            pngfix();
        }
    }

    // Handle togling languages
    jQuery('.text_francais').hide();
    
    jQuery('.btn_language').click(function() {
        jQuery(this).toggleClass('btn_english');

        if(jQuery('.btn_english').size() > 0) {
            jQuery('.text_francais').show();
            jQuery('.text_english').hide();
        } else {
            jQuery('.text_francais').hide();
            jQuery('.text_english').show();
        }
        return false;
    });

    // Set external links to open in new window
    jQuery('a[href^=http://]').attr("target", '_blank');

    // Place email (in case this is the contact page)
    jQuery('#e').html('e: <a h' + 'ref="ma' + 'ilto:l' + 'a.trimble&#64;g' + 'mail.com">' + 'la.tr' + 'imble&#64;' + 'gm' + 'ail.c' + 'om</a>');

}

var myGallery;
function startGallery() {
    if(jQuery('#myGallery').size() > 0) {
        jQuery('#myGallery img').wrap("<div class='imageElement'>");
        jQuery('#myGallery img').addClass("full");
        jQuery('.content').append("<a href='' id='rewind'></a><a href='' id='advance'></a>")
        jQuery('#rewind').click(function() {
            myGallery.prevItem();
            return false;
        });
        jQuery('#advance').click(function() {
            myGallery.nextItem();
            return false;
        });

        myGallery = new gallery(Moo.$('myGallery'), {
            timed: false,
            showCarousel: false,
            showArrows: false,
            embedLinks: false,
            showInfopane: false
        });
    } 
}

