var docsize = [];

    $(function(){
        setDocsize();
        $(window).resize(function(){setDocsize();});
    	$('.thumb img').click(function(){initShowroom(this)});
        $('.thumb').hover(function(){$(this).find("img").animate({opacity:1.0},150);},function(){$(this).find("img").animate({opacity:0.6},300);})
    });

    function setDocsize() {docsize[0] = $(document).width();docsize[1] = $(window).height();}
        
	function initShowroom(img)
		{
		var uid = new Date().getTime();
    	$('#site')
          .append('<div class="showroom"><a href="javascript:;" onclick="hideShowroom();"></a><div><img id="'+uid+'" src="" /></div></div>')
    	  .append('<div class="shadowscreen" style="height:'+docsize[1]+'px;"></div>')
          .append('<div id="img_tester" style="position:absolute;left:-5000px;top:0px;"></div>');
    	
        $('#'+uid).load(function()
            {
            var copyimg = new Image();
            $('#img_tester').empty().append(copyimg);
            copyimg.src = img.src.replace(/thumbs\//,'');
            var rw=$(copyimg).width();var rh=$(copyimg).height();
            $('#img_tester').empty();
            
            displayShowroom(this,rw,rh);});
        $('#'+uid).attr("src",img.src.replace(/thumbs\//,''));
		}

    function displayShowroom(img,w,h)
    	{
    	if(w>1300) {$(img).css({'height':h+'px','width':'auto'});w=1200;h+=15;}
    	else if(h>700) {h=700;$(img).css({'height':'auto','width':w+'px'});w+=15;}
	    $('.showroom').css({'top':parseInt((docsize[1]-h)/2)+'px', 'left':parseInt((docsize[0]-w)/2)+'px','opacity':'1.0'});
        $('.showroom div')
	      .css({'margin-left':parseInt(w/2)+'px','margin-top':parseInt(h/2)+'px','height':'0px','width':'0px'})
          .animate({'width':w,'height':h,'margin-top':0,'margin-left':0},250,function(){$('.showroom a').show();$('.shadowscreen').fadeIn(200);});
    	$('.shadowscreen').click(function(){hideShowroom();});
    	}

    function hideShowroom()
    	{
    	$('.shadowscreen').fadeOut(200,function(){$('.shadowscreen').remove();});
    	$('.showroom a').hide();
        $('#img_tester').remove();
    	$('.showroom div').animate({'margin-left':$('.showroom div').width()/2,'margin-top':$('.showroom div').height()/2,'width':0,'height':0},200,function(){$('.showroom').remove();});
    	}
