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";
}
function swapimg(url){
var a=document.getElementById("mainimagewrap");
a.style.opacity=0;
a.style.filter="alpha(style=0,opacity=0)";
var img = new Image(); // this new image will use the onload properly
img.onload = function() {
var b=document.getElementById("mainimage");
b.src = "uploads/"+url;
setTimeout("fadein("+10+", 'mainimagewrap')",25); 
}
img.src = "uploads/"+url;
}

function fadein(s, id){
if(typeof(z)!="undefined"){clearTimeout(z);}
var c=document.getElementById(id);
c.style.opacity=s/100;
c.style.filter="alpha(style=0,opacity="+s+")";
s=s+5;
if(s<=100){z=setTimeout("fadein("+s+", '"+id+"')",25);}
}

function showhide(id){
if(document.getElementById("i"+id).style.display!='none'){
	$("#i"+id).toggle();
} else {
	$("#i"+id).fadeIn('fast');
}
}
