jQuery(document).ready(function($) {
		
//
// plugin definition
//
$.fn.ps_rullande_bilder = function(options) {
	debug(this);
	
	// build main options before element iteration
	var opts = $.extend({}, $.fn.ps_rullande_bilder.defaults, options);
	
	// iterate and reformat each matched element
	return this.each(function() {

		var $this = $(this);
		// build element specific options
		var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
		
		// reset the ul/li properties
		$this.css({"list-style": "none","padding": "0px", "overflow": "hidden"})
			.find("li").css({"list-style": "none", "float": "left"});
			  
			  
        // 1. setup
        // capture a cache of all the list items
        // chomp the list down to limit li elements
		var items = [], // uninitialised
            total = 0, // initialise later on
			width = $this.outerWidth(),
			totWidth = 0,
			height = 0;
		
		
		// capture the cache
		$this.find('> li').each(function () {
			
			$(this).css({
				position: "absolute",
				top: "0px",
				left: totWidth + "px"
			});
			
			totWidth = ( totWidth + parseInt($(this).outerWidth()) );
			
			if($(this).outerHeight() > height){
				height = $(this).outerHeight();
			}
		});
		
		
		$this.css({"width": width, "height": height, "position": "relative"});
		
		$this.wrap('<div class="ps_rullande_bilder" />').parent().css({ "width" : o.width, "overflow": "hidden" });
		 
		 
		 
		 function slide(){
		 
			
			$this.find('> li').each(function () {
				
				var liWidth = parseInt($(this).outerWidth());
				
				if(parseInt($(this).css("left")) <= (-liWidth)){
					$(this).css("left", (totWidth - liWidth) + "px" );
				}else{
					$(this).css("left", (parseInt($(this).css("left")) - o.px ) + "px" );
				}
				
				//if( parseInt($(this).css("left")) <= (-liWidth) ){
				//	$(this).css("left", (width - liWidth) + "px" );
				//}
			});
			
			var spela = setTimeout(slide, o.speed);
			
			//$this.mouseover(function(){
		 	//	clearTimeout(spela);
		 	//}); 
		 }
		 
		 slide();
		 
		
		
		 //$this.mouseout(function(){
		 //	slide();
		// }); 

		 
	});
};
//
// private function for debugging
//
function debug($obj) {
	if (window.console && window.console.log)
	window.console.log($obj);
};
//
// define and expose our format function
//
$.fn.ps_rullande_bilder.format = function(txt) {
	return '<strong>' + txt + '</strong>';
};
//
// plugin defaults
//
$.fn.ps_rullande_bilder.defaults = {
	width: '100%',
	speed: 30,
	px: 1
};
//
// end of closure
//
});