/* copyright 2010-2011 rasor sculptures. All rights reserved. */

function setScrollBox(scrollY) {
	var sby = 425;
	h = $('#scrollbox2').innerHeight();
	if(h>sby) ypos = -(h-535)*(scrollY/sby);
	else ypos = 0;
	$('#scrollbox2').css('top',ypos+'px');
}

function moveScroll(delta) {
	var sby = 425;
	var h = $('#scrollbox2').innerHeight();
	var hpos = $('#scrollhandle').position().top;
	var newhpos = hpos-115+delta; // 115 is zero ypos for handle
	if(newhpos > sby) newhpos = sby;
	if(newhpos < 0) newhpos = 0;
	newSpos = ((newhpos)/sby) * (h-535);
	setScrollBox(newhpos);
	$('#scrollhandle').css('top',newhpos+'px');
}

function changePiece(imgid,imgfile,scalex,scaley){
	exdiv = '#ex'+imgid;
	thumbdiv = '#thumbs'+imgid;
	descdiv = '#dd'+imgid;
	arrowdiv = '#arw'+imgid;
	$("#artpic").fadeOut('slow',function() {		
		$("#infobox").html($(exdiv).html());
		$("#artpic").attr('src',imgfile);
		if(scalex>0) {
			$("#artpic").attr('width',scalex);
			$("#artpic").removeAttr('height');
		}
		else {
			$("#artpic").attr('height',scaley);
			$("#artpic").removeAttr('width');
		}
		descrip = $(descdiv).html();
		$("#desc2").html(descrip);
		$(".thumb").each( function(index){
			$(this).attr('class','thumb');
		});
		$(".arrow").each( function(index){
			$(this).html('');
		});
		$(arrowdiv).html("<img src='images/arrow.gif' width=10 />");
		$("#imghref").attr('href',"?id="+imgid);
		
		$(thumbdiv).attr('class','thumb bordery');
		$("#artpic").fadeIn('slow');
	});
}

function showMore(){
	$("#desc").slideToggle();
}

$(document).ready(function(){
	$("#closex").click(function() { $("#desc").hide();} );  
	$("#desc").draggable({ containment:'parent'});
	$("#scrollhandle").draggable({ containment:'parent'});
	$('#scrollhandle').bind('drag', function(event,ui) {setScrollBox(ui.position.top);} );
	$("#scrollbar").click(function(eventObj){ $('#posbox').html('<p>x: '+eventObj.pageX+' y: '+eventObj.pageY);} );
	$("#arrowup").click(function(){ moveScroll(-50);});
	$("#arrowdwn").click(function(){ moveScroll(50);});
});
