$(document).ready( function() {
	
	$('.image').click(function(){slideRight();});
	$('.right a').click(function(e){slideRight();e.preventDefault();});
	$('.left a').click(function(e){slideLeft();e.preventDefault();});
	
	$('.navigation .left')
		.mouseenter( function() { $('img', this).attr( 'src', '/images/model_back.png')} )
		.mouseleave(function() { $('img', this).attr( 'src', '/images/back_off.png')});
	
	var sliding = false;
	var pos = 0;
	var step = 735;
	var speed = 500;
	var news = $('.news');
	var max = news.innerWidth();
	
	checkNav(pos);
	
	function slideRight() {
		if ( pos + step < max ) {
			if (!sliding) {
				sliding = true;
				checkNav(pos+step);
				news.animate({ 'margin-left' : '-'+(pos+step)+'px'}, speed, 'swing', function(){
					pos += step;
					sliding = false;
				});
			}
		}
	}
	function slideLeft() {
		if ( pos - step >= 0 ) {
			if (!sliding) {
				sliding = true;
				checkNav(pos-step);
				news.animate({ 'margin-left' : '-'+(pos-step)+'px'}, speed, 'swing', function(){
					pos -= step;
					sliding = false;
				});
			}
		}
	}
	
	function checkNav( p ) {
		var right = $('.navigation .right');
		var image = $('.image');
		var left = $('.navigation .left');
		
		if ( p+step < max ) { right.show(); image.addClass( 'nav' ); } 
		else { right.hide(); image.removeClass( 'nav' ); }
		
		if ( p > 0 ) { left.show(); } 
		else { left.hide(); }
	}
	
});


 

