$(document).ready( function() {
    $(".nextButton").hover( function() {
       $(this).attr("src","images/next-button-over.png");
    },
    function() {
        $(this).attr("src","images/next-button.png");
    });

    $(".backButton").hover( function() {
       $(this).attr("src","images/back-button-over.png");
    },
    function() {
        $(this).attr("src","images/back-button.png");
    });

    $(".zoomIn").click(function(){
        zoomIn();
    });
    $(".zoomOut").click(function(){
        zoomOut();
    });

    getZoomStatus( location.hash.substring(1) );

});

function getZoomStatus( hashTag)
{
    if( hashTag == "zoom" )
    {
        zoomIn();
    }
}

function zoomIn()
{
    var selector = $("#imageCopy img:last");
    var source = $(selector).attr("src");

    if ( source.search(/-zoom/i) == -1 )
    {
        newSource = source.substring( 0, source.search(/.png/i) );
        newSource = newSource + "-zoom.png";
        //$(selector).attr("src","");
        setTimeout('$("#imageCopy img:last").attr("src", newSource);',5);
    }
    var backButton = $(".backButton").parent().attr("href");
    if( backButton != undefined )
    {
        if ( backButton.search(/#zoom/i) == -1 )
        {
            backButton = backButton + "#zoom";
            if( backButton.search(/index/i) == -1 )
            {
                $(".backButton").parent().attr("href",backButton);
            }
        }
    }
    var nextButton = "";
    nextButton = $(".nextButton").parent().attr("href");
    if( nextButton != undefined )
    {
        if ( nextButton.search(/#zoom/i) == -1 )
        {
            nextButton = nextButton + "#zoom";
            $(".nextButton").parent().attr("href",nextButton);
        }
    }
}

function zoomOut()
{
    var selector = $("#imageCopy img:last");
    var source = $(selector).attr("src");

    if ( source.search(/-zoom/i) )
    {
        //$(selector).attr("src","");
        setTimeout('$("#imageCopy img:last").attr("src", $("#imageCopy img:last").attr("src").replace("-zoom","") );',5);
    }
}

// Image Preloading
	jQuery.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
		jQuery("<img>").attr("src", arguments[i]);
	  }
	}
	$.preloadImages("images/next-button-over.png");
        $.preloadImages("images/back-button-over.png");