var postdimension = 101; 
var numberimage = 9; 
var postslider = {
	init: function(){
		
		img = jQuery("#post-gallery-into a img.post-images");
		total = img.length;
		
		jQuery("#post-gallery-into").css("width",(total*postdimension)+"px");

		postslider.activeback();
		postslider.deactiveback();
		postslider.activeforward();
		
		if(total <= numberimage){
			postslider.deactiveforward();
		}
	
	},
	activeback: function(){
		jQuery("#back").attr("class","");
		jQuery("#back").css("cursor","pointer");

		jQuery("#back").live("click",function(e){
			//e = new Event(e).stop();
			postslider.goback();
			return false;
				
		});
	},
	deactiveback: function(){
		jQuery("#back").attr("class","inactive");
		jQuery("#back").css("cursor","default");
	},
	activeforward: function(){
		jQuery("#forward").attr("class","");
		jQuery("#forward").css("cursor","pointer");
		
		jQuery("#forward").live("click",function(e){
				//e = new Event(e).stop();
				postslider.goforward();
				return false;
		});
	},
	deactiveforward: function(){
		jQuery("#forward").attr("class","inactive");
		jQuery("#forward").css("cursor","default");
	},
	goback: function(){

		maxspo = -((total*postdimension) - (postdimension*numberimage));
		
		actualeft = parseInt(jQuery("#post-gallery-into").css("left"));

		/*
		actualeft = $("post-gallery-into").getStyle("left").toInt();
		var leftChange = new Fx.Morph('post-gallery-into', {duration:500});
		leftChange.start({
   			'left': [actualeft, (actualeft+postdimension)]
		});*/
		
		if((actualeft+postdimension) <= 0){
			jQuery("#post-gallery-into").animate({ 
				        left: (actualeft+postdimension)+"px",
				      }, 500 );
		}
		if((actualeft+postdimension) >= 0){
			postslider.deactiveback();
		}
		
		if((actualeft+postdimension) >= maxspo){
			postslider.activeforward();
		}
		
	},
	goforward: function(){
		maxspo = -((total*postdimension) - (postdimension*numberimage));
		
		actualeft = parseInt(jQuery("#post-gallery-into").css("left"));
		
		/*
		actualeft = $("post-gallery-into").getStyle("left").toInt();
		var leftChange = new Fx.Morph('post-gallery-into', {duration:500});
		leftChange.start({
   			'left': [actualeft, (actualeft-postdimension)]
		});
		*/
		
		if((actualeft-postdimension) >= maxspo){	
			jQuery("#post-gallery-into").animate({ 
				        left: (actualeft-postdimension)+"px",
				      }, 500 );
		}
		if((actualeft-postdimension) <= maxspo){
			postslider.deactiveforward();
		}
		
		if((actualeft-postdimension) <= 0){
			postslider.activeback();
		}
	}
	
}


jQuery(window).load(function () {
	if(jQuery("#post-gallery")){
		postslider.init();
	}
});