// Javascript by Sean Jones
// image rollver script
$(document).ready(function(){ 
						   
// image rollver script
$(".featuredWork img").hover(
 function()
 {
  this.src = this.src.replace("_off","_on");
 },
 function()
 {
  this.src = this.src.replace("_on","_off");
 }
);

// find css class featuredWork and rename it...
$(".featuredWork").addClass("featuredWork_js");

$(".sampleWork:odd").css("float","right"); 

// Modal Pop-up
    // Gallery popup and overlay
    $(".sampleWork a").click(function(){
		
		var featuredWorkText = $(this).parent().find(".selectedWorkTxt").html();							 
    	
	
        var largeImageSrc = $(this).attr("href");
        var largeImageAlt = $(this).attr("title");

        var image = new Image();
        
        image.onload = function() {

        var popup = $('<div class="overlayBkg"></div><div class="popupContainer"><div class="popup"><img class="closePopup" src="media/close.gif" title="close window" alt="close window" width="66" height="22" /><img src="' + image.src + '" title="' + largeImageAlt + '" alt="' + largeImageAlt + '"/><div class="selectedWorkTxt">' + featuredWorkText + '</div></div></div>');
		
                popup.find(".closePopup").add(popup.eq(0)).click(function()
                    {
                popup.fadeOut(function() {$(this).remove()}); // fadeout and remove popup from page
                $(window).unbind("resize");
                    });
            
                    popup.hide();
            		$("body").prepend(popup);
                    setcoverSize( popup.eq(0).css("opacity","0.5") );
                    popup.eq(1).find(".popup").width(image.width+390);
					popup.eq(0).show();
					popup.eq(1).fadeIn();
                    
                  $(window).bind("resize",function() {setcoverSize( popup.eq(0));});

        }
        image.onerror = function() {
            alert("error");
        }

        image.src = largeImageSrc;
		
        return false;
    });
function setcoverSize( el )
{
    var wh = $(window).height();
    var ww = $(window).width();
    var bh = document.body.scrollHeight;
    var bw = document.body.scrollWidth;
    el.width( ww > bw ? ww : bw ).height( wh > bh ? wh : bh );
}
});
