$(document).ready(function(){
   $("#accordion").accordion({ active: false, autoHeight: false });

	$("#tab_image a.thickbox").each(function(e) {
			
			var sp = $(this).parent().children('span');
			
			var img = new Image();
			img.src = this;
			img.onload = function() {
				if (this.width > 250) {
					sp.html('Zoom In');
				}
			};	
		}
	);
		
	$("a.thickbox").click(function () {
		$("#image").attr('src', $(this).attr('href'));
		$("#image").css('left', 0);
		$("#image").css('top', 0);
		return false;
	});
	
	$("#product_image").hover(function () {
		if ($("#image").width() > 300) {
			
			$().mousemove( function(e) {
				
				var xPos = $("#product_image").offset().left;
				var yPos = $("#product_image").offset().top;
				
				var xRatio = $("#image").width() /250;
				var yRatio = $("#image").height() /400;
				
				var x1 = 0;
				var x2 = -($("#image").width()-250);
				var y1 = 0;
				var y2 = -($("#image").height()-400);
				
				if (e.pageX >= xPos && e.pageX <= xPos+250 && e.pageY >= yPos && e.pageY <= yPos+400) {
					
					if ((xPos-e.pageX)*xRatio < x1 && (xPos-e.pageX)*xRatio > x2) {$("#image").css('left', (xPos-e.pageX)*xRatio);}
					else if ((xPos-e.pageX)*xRatio > x1) {$("#image").css('left', x1);}
					else if ((xPos-e.pageX)*xRatio < x2) {$("#image").css('left', x2);}

					if ((yPos-e.pageY)*yRatio < y1 && (yPos-e.pageY)*yRatio > y2) {$("#image").css('top', (yPos-e.pageY)*yRatio);}
					else if ((yPos-e.pageY)*yRatio > x1) {$("#image").css('top', y1);}
					else if ((yPos-e.pageY)*yRatio < x2) {$("#image").css('top', y2);}
					
				}
				
			});
		}
	})
});