time = 8000;
speed = 1000;
var newimage = 0;
var totalimages = 0;

switchmov = 0;
currentnav = 0;
max_width = 0;
current = 0;
moveamount = "";
moveamountto = ""; 

main = "";

function check_current_pos(){

if(currentnav == totalimages-1){

	jQuery('#products_nav a.right').hide();

}else{

	jQuery('#products_nav a.right').show();

}

if(currentnav == 0){

jQuery('#products_nav a.left').hide();

}else{

jQuery('#products_nav a.left').show();

}



}

function moveto(inum){
	inum--;
	currentnav = inum;
	next = moveamount*inum;
	current = next;
	jQuery('#'+main).animate({scrollLeft:current}, speed);
	jQuery('#products_central a').removeClass('active');
	jQuery('#products_central a').eq(inum).addClass('active');
check_current_pos();

}

function moveleft(){

	if(current == max_width-moveamount){
	
	
	
	}else{
	
		currentnav++; 
		next = moveamount+current;
		current = next;
		jQuery('#'+main).animate({scrollLeft:current}, speed);
		jQuery('#products_central a').removeClass('active');
		jQuery('#products_central a').eq(currentnav).addClass('active');
	
	}

check_current_pos();

}

function autoscroll(){
totalimages = jQuery('ul#mycarousel li').length;

if(switchmov == 0){

current = current-moveamount;

switchmov = 1;
currentnav = -1;
}else{




}



  if (newimage == totalimages) {
    newimage = 0;
  }

  setTimeout("autoscroll()", 1*time);
  newimage++;

	if(current == max_width-moveamount){
	
		current = 0;
		currentnav = 0;
		jQuery('#products_central a').removeClass('active');
		jQuery('#products_central a').eq(currentnav).addClass('active');
		jQuery('#'+main).scrollLeft(current);
check_current_pos();
	
	}else{

		currentnav++; 
		next = moveamount+current;
		current = next;
		jQuery('#'+main).animate({scrollLeft:current}, speed);
		jQuery('#products_central a').removeClass('active');
		jQuery('#products_central a').eq(currentnav).addClass('active');
check_current_pos();
	
	}

}


function moveright(){

if(current > 0){
currentnav--;
next = current-moveamount;
current = next;
jQuery('#'+main).animate({scrollLeft: current}, speed);
	jQuery('#products_central a').removeClass('active');
	jQuery('#products_central a').eq(currentnav).addClass('active');
}
}



jQuery(document).ready(function(){

size = jQuery('ul#mycarousel li').size();
totalimages = size; 
liwidth = jQuery('ul#mycarousel li').width();
moveamount = liwidth;
check_current_pos();

fullwidth = liwidth * size;
max_width = fullwidth;
parentid = jQuery('ul#mycarousel').parent().attr('id');
main = parentid; 
jQuery('#'+main).animate({scrollLeft: 0}, speed);

jQuery('ul#mycarousel').css('position','absolute');
jQuery('ul#mycarousel').css('width',fullwidth+'px');
jQuery('ul#mycarousel li').css('float','left').css('margin','0px').css('padding','0px').css('width',liwidth).css('list-style','none').css('z-index','100');
jQuery('#'+parentid).css('overflow','hidden');

jQuery('#products_nav a.right').click(function(){
moveleft();


});

jQuery('#products_nav a.left').click(function(){
moveright();


});


jQuery('#products_central a').click(function(){


hpl = jQuery(this).html();

moveto(hpl);


});

autoscroll();
})

