$(document).ready(function(){
	current = 0;
	howmany = Math.floor($(".designvotewide").size() / 3);
    $("a.moveleft").click(function(){
    	current = current - 1;
    	if(current > -1){        
        	$("#votingwrapper").animate({
	            marginLeft: "+=880px"
        	}, 1000);
        	// if we've gone left to howmany - 2, make going right possible
        	if (current == howmany - 2){
				$("a.moveright").fadeIn("slow");
				$("a.rightf").fadeIn("slow");
        	}
        	// if we've reached the start, hide the left link
        	if (current == 0){
				$("a.moveleft img").fadeOut("slow");
				$("a.leftf").fadeOut("slow");
        	}
    	} else {
			current = current + 1;
    	}
    });
    $("a.leftf").click(function(){
    	current = current - 1;
    	if(current > -1){        
        	$("#votingwrapper").animate({
	            marginLeft: "+=880px"
        	}, 1000);
        	// if we've gone left to howmany - 2, make going right possible
        	if (current == howmany - 2){
				$("a.moveright").fadeIn("slow");
				$("a.rightf").fadeIn("slow");
        	}
        	// if we've reached the start, hide the left link
        	if (current == 0){
				$("a.moveleft img").fadeOut("slow");
				$("a.leftf").fadeOut("slow");
        	}
    	} else {
			current = current + 1;
    	}
    }); 
    $("a.moveright").click(function(){
    	current = current + 1;
    	if(current != howmany){
        	$("#votingwrapper").animate({
            	marginLeft: "-=880px"
				
        	}, 1000);
        	// make going left visible
        	if (current == 1){
				$("a.moveleft img").fadeIn("slow");
				$("a.leftf").fadeIn("slow");
        	}
        	// if we've reached the end, hide the right link
        	if (current == howmany - 1){
				$("a.moveright").fadeOut("slow");
				$("a.rightf").fadeOut("slow");
        	}
    	} else {
        	current = current -1;
    	}
    });
    $("a.rightf").click(function(){
    	current = current + 1;
    	if(current != howmany){
        	$("#votingwrapper").animate({
            	marginLeft: "-=880px"
				
        	}, 1000);
        	// make going left visible
        	if (current == 1){
				$("a.moveleft img").fadeIn("slow");
				$("a.leftf").fadeIn("slow");
        	}
        	// if we've reached the end, hide the right link
        	if (current == howmany - 1){
				$("a.moveright").fadeOut("slow");
				$("a.rightf").fadeOut("slow");
        	}
    	} else {
        	current = current -1;
    	}
    });
    $("a.slidePaging").click(function(){
        pageNum = $(this).text() - 1;
		if (pageNum == current){
			return false;
		}
		if (pageNum < current){
			toMove = (current - pageNum) * 880;
			$("#votingwrapper").animate({
	            marginLeft: "+="+toMove+"px"
        	}, 1000);
		}
		if (pageNum > current){
			toMove = (pageNum - current) * 880;
			$("#votingwrapper").animate({
	            marginLeft: "-="+toMove+"px"
        	}, 1000);
		}
		current = pageNum;
		// make going left visible if we've moved away from the start
		if (current > 0 && pageNum > 0){
			$("a.moveleft img").fadeIn("slow");
			$("a.leftf").fadeIn("slow");
		}
		// make going right visible if we've moved away from the end
		if (current == howmany - 2){
			$("a.moveright").fadeIn("slow");
			$("a.rightf").fadeIn("slow");
		}
		
		// make going left invisible
    	if (current == 0){
    		$("a.moveleft img").fadeOut("slow");
    		$("a.leftf").fadeOut("slow");
    	}
    	// if we've reached the end, hide the right link
    	if (current == howmany - 1){
			$("a.moveright").fadeOut("slow");
			$("a.rightf").fadeOut("slow");
    	}	
    });
});