var currentPage = 1;
var $allnum;
var $wrapper;
var okclick = true;
$(document).ready(function(){
	$wrapper = $(".wrapper").css('overflow', 'hidden');
	$wrapper.attr("scrollLeft","0");
	$slider = $wrapper.find('> ul');
	$items = $slider.find('> li');
	$single = $items.filter(':first');
	$allnum = $items.length;
	left = $single.outerWidth();
	$wrapper.after('<a class="arrow back"></a><a class="arrow forward"></a>');
	$('a.back', this).click(function () {		
		gotoPage(currentPage - 1);		
	});
	
	$('a.forward', this).click(function () {
		gotoPage(currentPage + 1);		
	});
	if(currentPage==1){$('a.back', this).css("display","none");}else{$('a.back', this).css("display","block");};
	if(currentPage==$allnum){$('a.forward', this).css("display","none");}else{$('a.forward', this).css("display","block");};	
})
function gotoPage(goPage) {
	if (okclick) {
		okclick = false;
		if (goPage>currentPage) {var nowleft = left;} else {var nowleft = - left;};
		currentPage = goPage;	
		if(currentPage<=1){$('a.back').css("display","none");}else{$('a.back').css("display","block");};
		if(currentPage>=$allnum-3){$('a.forward').css("display","none");}else{$('a.forward').css("display","block");};	
		//window.document.title = currentPage;
		$wrapper.filter(':not(:animated)').animate({scrollLeft : '+=' + nowleft}, 400, function(){okclick = true;});	
		//alert(nowleft);
	}
}

function gotoCategory(getCurrentPage) {
	okclick = false;
	$wrapper.filter(':not(:animated)').animate({scrollLeft : '+=' + 233 * (getCurrentPage - 1)}, 400, function(){okclick = true;});
	currentPage = getCurrentPage;
	if(currentPage<=1){$('a.back').css("display","none");}else{$('a.back').css("display","block");};
	if(currentPage>=$allnum-3){$('a.forward').css("display","none");}else{$('a.forward').css("display","block");};	
}
