$(document).ready(function() {
						   
    $("#hintToggle").toggleVal();
    PEPS.rollover.init();
    $(".lightbox").lightbox();
   
}); 


// Toggle text and images (on/off)

jQuery.fn.toggleVal = function(focusClass) {
    this.each(function() {
        $(this).focus(function() {
            // clear value if current value is the default
            if($(this).val() == this.defaultValue) {
                $(this).val("");
            }
			
            // if focusClass is set, add the class
            if(focusClass) {
                $(this).addClass(focusClass);
            }
        }).blur(function() {
            // restore to the default value if current value is empty
            if($(this).val() == "") {
                $(this).val(this.defaultValue);
            }
			
            // if focusClass is set, remove class
            if(focusClass) {
                $(this).removeClass(focusClass);
            }
        });
    });
}


// Image rollovers 

PEPS = {};

PEPS.rollover =
{
    init: function()
    {
        this.preload();
	
        $("#sub_nav ul li a img").hover(
            function () {
                if ($(this).attr('class') == 'no-roll'){

                }
                else{
                    $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
                }
            },
            function () {
                if ($(this).attr('class') == 'no-roll'){

                }
                else{
                    $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
                }
            }
            );
    },
 
    preload: function()
    {
        $(window).bind('load', function() {
            $('#sub_nav ul li a img').each( function( key, elm ) {
                if ($(this).attr('class') == 'no-roll'){

                }else{
                    $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) );
                }
                
            });
        });
    },
 
    newimage: function( src ) {
        return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_h' + src.match(/(\.[a-z]+)/)[0];
    },
    oldimage: function( src ){
        return src.replace(/_h/, '');
    }
};