var PRPL = {};

$(document).ready( function()
{
    // Select all links that contains lightbox in the attribute rel
    $('a[rel=shadowbox[ThisGallery]]').lightBox({fixedNavigation:true});
    
    // Rotating handshake on homepage
    var handshake = $('#handshake').tabs( // instantiate moneyshot tabs
    {
        collapsible: false,
        fx: { opacity: 'toggle' } // fade on change
    });
    
    handshake.tabs(
        'rotate',   // ROTATE call
        5000,       // every 5 seconds
        false      // stop rotation
    );

    // increase / decrease text sizes
    $('.decrease').click( function()
    {
       $('#content').css( 'font-size', '100%');
    });

    $('.increase').click( function()
    {
       $('#content').css( 'font-size', '116.5%');
    });
    
    $('#messages .close').click( function()
    {
        $(this).parent('#messages').fadeOut();
        return false;
    });

    // Navigation flyout menus for browser that don't support :hover on non-anchor elements
    $('.navigation > li').hover( function()
    {
       $(this).addClass('active');
    },
    function()
    {
        $(this).removeClass('active');
    });
    
    //  make a formEraserHelper for each input & textarea field
    $('#search, #newsletter_email_address, #contact_phone, #reminder_email').each( function()
    {
        var fieldName   =   $(this).attr('name');
        PRPL[fieldName] =   new PRPL.formEraserHelper($(this));
    });

    //  Fixes 'click to activate' flash stupidity in IE by taking the
    //  objects content and putting it into the objects content -- yeah.
    obj = document.getElementsByTagName("object");
    for(var i=0; i < obj.length; i++)
    {
        obj[i].outerHTML = obj[i].outerHTML;
    }

    $(".donatenow").click(function() {
        PRPL.gaTrackDonate();
    });
});

PRPL.gaTrackDonate = function()
{
    pageTracker._trackPageview('/donatenow');
}


PRPL.formEraserHelper   =   function(fieldObj)
{
    var obj             =   this;                   //  cached "this"
    this.fieldObj       =   fieldObj;               //  the form field jQuery object
    this.initialValue   =   this.fieldObj.val();    //  initial value of the form field
    
    //  when focused on, if the value hasn't been changed, empty it
    this.fieldObj.focus(function()
    {
        if ( $(this).val() == obj.initialValue )
        {
            $(this).val('');
        }
    });
    
    //  when blurred, if the field is empty, populate it 
    this.fieldObj.blur(function()
    {
        if ( $(this).val() === '' )
        {
            $(this).val(obj.initialValue);
        }
    });
};  //  end