function rotchange(val)
{
	if (document.getElementById('rottimer').value!=""){
		clearTimeout(document.getElementById('rottimer').value);
	}
	
	for(i=1;document.getElementById('rot'+i);i++)
	{
		if (document.getElementById('rot'+i).style.display == 'block')
		{
			cur = i;
			document.getElementById('thumb'+i).style.border = '2px solid #FFFFFF';
		}
		
		if(i==val)
		{
			document.getElementById('rot'+i).style.display = 'block';
			document.getElementById('rot'+i).style.zIndex = '1';
			document.getElementById('thumb'+i).style.border = '2px solid #4885e6';
		}
	}
	
	if (cur != val)
	{
		fade('rot'+cur, '100', 'rot'+val, '2');
	}
	
	id = setTimeout("auto();",12000);
	document.getElementById('rottimer').value = id;
}

function fade (cur, fade, val, speed)
{
	fade = fade - speed;
	if(fade == 0)
	{
		document.getElementById(cur).style.display = 'none';
		document.getElementById(cur).style.opacity = '1';
		document.getElementById(cur).style.filter = 'alpha(opacity = 100)';
		document.getElementById(cur).style.zIndex = '0';
		
		document.getElementById(val).style.zIndex = '2';
	}
	else
	{
		document.getElementById(cur).style.opacity = fade/100;
		document.getElementById(cur).style.filter = 'alpha(opacity = ' + fade + ')';
		
		setTimeout("fade('"+cur+"',"+fade+",'"+val+"',"+speed+")",20);
	}
}

function auto()
{
	for(i=1;document.getElementById('rot'+i);i++)
	{
		if(document.getElementById('rot'+i).style.display == 'block')
		{
			cur = i;
		}
	}
	
	if(cur == 5)
	{
		cur1 = 1;
	}
	else
	{
		cur1 = cur + 1;
	}
	
	document.getElementById('rot'+cur1).style.display = 'block';
	document.getElementById('rot'+cur1).style.zIndex = '1';
	document.getElementById('thumb'+cur1).style.border = '2px solid #4885e6';
	
	document.getElementById('thumb'+cur).style.border = '2px solid #FFFFFF';
	
	fade('rot'+cur, 100, 'rot'+cur1, '1');
	
	id = setTimeout("auto();",8000);
	
	document.getElementById('rottimer').value = id;
}

function changetab(val, id)
{
	for(i=1;document.getElementById(id+i+'content');i++)
	{
		if (document.getElementById(id+i+'content').style.display == 'block')
		{
			cur = i;
		}
		
		if(i==val)
		{
			if (navigator.appName == "Microsoft Internet Explorer"){
				document.getElementById(id+i+'content').style.zIndex = '2';
			}else{
				document.getElementById(id+i+'content').style.zIndex = '1';
			}
			document.getElementById(id+i+'content').style.display = 'block';
			width = document.getElementById(id+i+'label').offsetWidth;
			height = document.getElementById(id+i+'label').offsetHeight;
			document.getElementById(id+i+'label').style.backgroundImage = 'url(tabs.php?x='+width+'&y='+height+'&sel=1)';
		}
		else
		{
			if (navigator.appName == "Microsoft Internet Explorer"){
				document.getElementById(id+i+'content').style.display = 'none';
				document.getElementById(id+i+'content').style.zIndex = '0';
			}
			width = document.getElementById(id+i+'label').offsetWidth;
			height = document.getElementById(id+i+'label').offsetHeight;
			document.getElementById(id+i+'label').style.backgroundImage = 'url(tabs.php?x='+width+'&y='+height+'&sel=0)';
			
		}
	}
	
	if (cur != val)
	{
		if (navigator.appName != "Microsoft Internet Explorer"){
			fade(id+cur+'content', '100', id+val+'content', '10');
		}
	}
	
	document.getElementById(id+cur+'content').style.zIndex = '2';

}

//initial the tabs. Fixes the background images. Doesn't change the content though
function inittabs(val, id){
	for(i=1;document.getElementById(id+i+'label');i++)
	{
		if(i==val)
		{
			width = document.getElementById(id+i+'label').offsetWidth;
			height = document.getElementById(id+i+'label').offsetHeight;
			document.getElementById(id+i+'label').style.backgroundImage = 'url(tabs.php?x='+width+'&y='+height+'&sel=1)';
		}
		else
		{
			width = document.getElementById(id+i+'label').offsetWidth;
			height = document.getElementById(id+i+'label').offsetHeight;
			document.getElementById(id+i+'label').style.backgroundImage = 'url(tabs.php?x='+width+'&y='+height+'&sel=0)';
			
		}
	}
}

//product tab change.
function prodtab(rowid, tab, id){
	showDetails(rowid+'|'+tab);
	inittabs(id, 'prodtab');
}

function changecontent(val, id)
{
	for(i=1;document.getElementById(id+i);i++)
	{
		if (document.getElementById(id+i).style.display == 'block')
		{
			document.getElementById(id+i).style.zIndex = '0';
			document.getElementById(id+i).style.display = 'none'
		}
		
		if(i==val)
		{
			document.getElementById(id+i).style.display = 'block';
			document.getElementById(id+i).style.zIndex = '1';
		}
	}
	
}

function showDetails(productID,FieldName){
 		// the field NAME is made safe in the RPC code
		$.post("rpc_PRODUCT_DETAILS_TABS.php", {queryString: productID+"|"+FieldName}, function(data){
                if(data.length >0) {
                    $('#tabdetails').html(data);
					$('#tabs_scroll').jScrollPane({showArrows:false, dragMaxHeight:45, dragMinHeight:45, dragWidth:3});
                }
       });
}


//new rotator stuff.
function scroll(){
	$('#rotator').css('left',(parseInt($('#rotator').css('left'))-10)+'px');
	$('#slider').slider('value',(parseInt($('#rotator').css('left'))-10)/-10)
	if (parseInt($('#rotator').css('left'))%590!=0){
		setTimeout("scroll();",1);
	}else{
		if ((-1*parseInt($('#rotator').css('left'))+590) >= (parseInt($('#rotator').css('width')))){
			$('#rotator').css('left','0px');
			$('#slider').slider('value', 0);
		}
		
		clearTimeout($("#rottimer").val());
		
		id = setTimeout("scroll();",4000);
		
		$('#rottimer').val(id);
	}
}

function scrollback(){
	$('#rotator').css('left',(parseInt($('#rotator').css('left'))+10)+'px');
	$('#slider').slider('value',(parseInt($('#rotator').css('left'))-10)/-10)
	if (parseInt($('#rotator').css('left'))%590!=0){
		setTimeout("scrollback();",1);
	}else{
		if (parseInt($('#rotator').css('left')) >= 0){
			$('#rotator').css('left','0px');
			$('#slider').slider('value', 0);
		}
		clearTimeout($("#rottimer").val());
		
		id = setTimeout("scroll();",4000);
		
		$('#rottimer').val(id);
	}
}

function slidescroll(val){
	clearTimeout($('#rottimer').val());
	$('#rotator').css('left',-1*val*10+'px');
}

function slidestop(val){
	var posit = parseInt($('#rotator').css('left'));
	if (val%118==0){
		clearTimeout($("#rottimer").val());
		
		id = setTimeout("scroll();",4000);
	
		$('#rottimer').val(id);
	}else if (val%118<59){
		$('#rotator').css('left',(posit-(posit%10))+'px');
		$('#slider').slider('value',(posit-(posit%10))/-10)
		
		setTimeout("scrollback();",1);
	}else if (val%118>59){
		$('#rotator').css('left',(10+posit-(posit%10))+'px');
		$('#slider').slider('value',(10+posit-(posit%10))/-10)
		
		setTimeout("scroll();",1);
	}
}

function startrot(){
	clearTimeout($("#rottimer").val());
	
	id = setTimeout("scroll();",4000);
	
	$('#rottimer').val(id);
}

function stoprot(){
	clearTimeout($("#rottimer").val());
}