//initializations
$(document).ready(function(){
    //image rollovers
    $(".ro").each(function(){
        var currentImg = $(this).children("img");
        $(this).hover(
            function(){
                imgOver(currentImg);
            },
            function(){
                imgOut(currentImg);
            }
        );
    });
 
 //click on Action Link to open tray
 $(".opentray a").click(function(){ 
    var openHeight = $(".tray .trayinfo").attr("offsetHeight") + 140;
    var scrollTarget = $(".tray").offset().top - 15;
    $(".tray").animate({height:openHeight},1000,function(){
        $(".tray").css("overflow","visible");
        if($(".tray .trayphoto")) {
            $(".tray .trayphoto").fadeIn("normal");
        }
        $("html, body").animate({scrollTop: scrollTarget}, "slow");
    });
    return false;   
 });
 
 //click on closebox
 $(".tray .closebox").click(function(){
    $(".tray .trayphoto").fadeOut("normal");  
    $(".tray").css("overflow","hidden");
    $(".tray").animate({height:0},1500);
  return false;
 });
 
});  //end of initializations

function imgOver(currentImg) {
 if($(currentImg).attr("src").indexOf("_over") == -1) {
  var newSrc = $(currentImg).attr("src").replace(".","_over.");
  $(currentImg).attr("src",newSrc);
 }
}
 
function imgOut(currentImg) {
 if($(currentImg).attr("src").indexOf("_over") != -1) {
  var oldSrc = $(currentImg).attr("src").replace("_over.",".");
  $(currentImg).attr("src",oldSrc);
 }
}
