function scrollit(id,x) {
	if(typeof(y)!="undefined"){clearTimeout(y);} // cancel
	var c=document.getElementById(id); // get item 
	var d=Math.round(parseFloat(c.scrollTop)); // calc new position
	var e=document.getElementById("newscontent").scrollHeight-document.getElementById("newscontent").offsetHeight;
	if(d+x+x>e||d+x+x<0){x=Math.round(x/2);} // slow down ?
	else if(Math.abs(x)<25){x=x*1.25;} // or speed up ?
	d=d+x;
	if(d>e){d=e;} else if(d<0){d=0;} // stop
	c.scrollTop=d; // set
	if(d>0&&d<e){ // rerun?
		y=setTimeout("scrollit('"+id+"',"+x+")",25);
	} else {
		if(typeof(y)!="undefined"){clearTimeout(y);}
	}
}
function scrollstop(){if(typeof(y)!="undefined"){clearTimeout(y);}}

function less(pid){
	e=Number(document.getElementById('quantity'+pid).value);
	if(e>1){
		e=e-1;
		document.getElementById('quantity'+pid).value=e;
		document.getElementById('submit'+pid).value="Add "+e+" to basket";
	}
}
function more(pid){
	e=Number(document.getElementById('quantity'+pid).value);
	e=e+1;
	document.getElementById('quantity'+pid).value=e;
	document.getElementById('submit'+pid).value="Add "+e+" to basket";
}

$(document).ready(function(){
	$('.withsub').hover(function(){ 
		$('.subnav', this).show();
	},function(){ 
		$('.subnav', this).hide();
	});
	$('.gallery_wrap .gallery_thumb a').click(function(){
		var e=$(this).closest('.gallery_wrap');
		var url=$(this).attr('href');
		var img = new Image(); // this new image will use the onload properly
		img.onload = function() {
			e.find('img.gallery_mainimage').css('opacity',0).attr('src',url).animate({'opacity':1});
			e.find('div.title').html($(this).attr('title'));
		}
		e.find('img.gallery_mainimage').css('opacity',0.5);
		img.src = url;
		return false;
	});
});
