$(document).ready(function(){

$("a[href$=jpg]").click(function(){return hs.expand(this);});
$("a[href$=gif]").click(function(){return hs.expand(this);});
$("a[href$=png]").click(function(){return hs.expand(this);});
$("a[href$=jpeg]").click(function(){return hs.expand(this);});

function getImageSize(id) {
    var oHlpr = document.createElement( 'IMG');
    var oPic = id;
    oHlpr.style.visibility = 'hidden';
    oHlpr.style.position = 'absolute';
    oHlpr.top = 0; oHlpr.left = 0;
    oHlpr.src = oPic.src;
    document.body.appendChild( oHlpr);
var imSize = { 'width':oHlpr.offsetWidth,'height':oHlpr.offsetHeight };
    document.body.removeChild( oHlpr);
    return imSize;
}

function changesize(){
	var divs = $('div#scroll');
	divs.width(400); 
	divs.width(divs.parent().width());
}

$(window).bind("resize", function(){
   // changesize();
});


	/*$('div#scroll').mousemove(function(e){
		var lastLi = $(this).find('a:last-child');
		var divWidth = $(this).width();
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth();	
		var left = (e.pageX - $(this).offset().left) * (ulWidth-divWidth) / divWidth;
		$(this).scrollLeft(left);
	});*/

$('#scroll_left').hover(
function(){
direction=-9;
stopfull=true;
scrollactive=true;
},
function(){
stopfull=false;
direction=-3;
}
);

$('#scroll_right').hover(
function(){
direction=9;
stopfull=true;
scrollactive=true;
},
function(){
stopfull=false;
direction=3;
}
);
	$('div#scroll a').hover(
  		function () {
    			$(this).addClass("hover");
  		},
  		function () {
    			$(this).removeClass("hover");
  		}
	);

	$('div#scroll').hover(
  		function () {
    			scrollactive=false;
  		},
  		function () {
    			scrollactive=true;
  		}
	);

var scrollactive=true;
var direction=3;
var stopfull=false;
if($('div#scroll').is(':visible'))
setInterval(function(){
if (scrollactive){
	var div=$('div#scroll');
	var lastLi = div.find('> a:last');
	var divWidth = div.width();
	//var max = lastLi[0].offsetLeft + lastLi.width() - divWidth;
	var max = lastLi[0].offsetLeft + lastLi[0].offsetWidth - divWidth;
 	var left = div.scrollLeft();
	if ((left >= max) && (direction > 0)) if(stopfull) return; else direction=0-direction;
        if ((left <= 0) && (direction < 0))if(stopfull) return; else direction=0-direction;
	div.scrollLeft(left+direction);
 }
},40);

changesize();

$('td.image img').hover(
function(){
cheight=this.height;
cwidth=this.width;
oheight=getImageSize(this).height;
owidth=getImageSize(this).width;
margintop=(oheight-cheight)/2;
marginleft=(owidth-cwidth)/2;
if(cwidth < owidth && !$(this).is(':animated')){
$(this).parent().height($(this).parent().height());
$(this).parent().css('z-index','100');
$(this).css('position','absolute');
$(this).animate({top:-margintop,left:-marginleft,width:owidth},300);
}
},
function(){
$(this).parent().css('z-index','2');
$(this).animate({top:0,left:0,width:'100px'},200);
$(this).parent().css('z-index','1');
}
);


});

