$.fn.slider = function(settings) {
	this.defaults = {
		 width:"200",
		 height:"200",
		 element:null
	}
	this.store = { alreadySet:false }
	var opts = $.extend({}, this.defaults, settings);
	var storeAttrs = $.extend({}, this.store);
	this.init = function() {
		$(this).css({
						'width':opts.width+'px',
						'height':opts.height+'px'
					});
		storeAttrs.container = document.createElement('DIV');
		$(storeAttrs.container).css({ 
							 'position':'relative',
							 'width':opts.width+'px',
							 'height':opts.height+'px'
						 });
		
		//make left arrow
		var arrowContainerLeft = document.createElement('DIV');
		$(arrowContainerLeft).css({ 
								  'position':'relative',
								  'float':'left',
								  'width':'auto',
								  'height':'auto'
								});
		var arrowLeft = document.createElement('DIV');
		$(arrowLeft).css({ 
							  'cursor':'pointer',
							  'width':'auto',
							  'height':'auto'
						 });
		var arrowLeftImg = document.createElement('IMG');
		$(arrowLeftImg).attr("src","images/left-arrow.png");
		$(arrowLeft).append(arrowLeftImg);
		$(arrowContainerLeft).append(arrowLeft);
		$(arrowLeft).click(this.moveLeft);
	
		//make right arrow
		var arrowContainerRight = document.createElement('DIV');
		$(arrowContainerRight).css({ 
									  'position':'relative',
									  'float':'left',
									  'width':'auto',
									  'height':'auto'
								 });
		var arrowRight = document.createElement('DIV');
		$(arrowRight).addClass('arrowRight');
		$(arrowRight).css({ 
							  'cursor':'pointer',
							  'width':'auto',
							  'height':'auto'
						  });
		var arrowRightImg = document.createElement('IMG');
		$(arrowRightImg).attr("src","images/right-arrow.png");
		$(arrowRight).append(arrowRightImg);
		$(arrowContainerRight).append(arrowRight);
		$(arrowRight).click(this.moveRight);
		
		//make center
		var slideScreen = document.createElement('DIV');
		$(slideScreen).css({ 
							  'height':opts.height+'px',
							  'overflow':'hidden',
							  'float':'left',
							  'position':'relative',
							  'width':'500px'
						  });
		
		storeAttrs.slider = document.createElement('DIV');
		$(storeAttrs.slider).css({
						  'width':'2000px',
						  'height':opts.height+'px',
						  'marginLeft':'0px'
					 });
		$(slideScreen).append(storeAttrs.slider);
		$(storeAttrs.container).append(arrowContainerLeft);
		$(storeAttrs.container).append(slideScreen);
		$(storeAttrs.container).append(arrowContainerRight);
		$(this).append(storeAttrs.container);
		
	/*	storeAttrs.slideScreenWidth = (opts.width-$(arrowContainerLeft).outerWidth(true)-$(arrowContainerRight).outerWidth(true));
		$(slideScreen).css({ 
							  'width':storeAttrs.slideScreenWidth+'px'
						  });*/
		
		
		//if web kit
		var obj = this;
		setTimeout(function(obj,t) {
		
					$(opts.element).show();
					/***READJUST SLIDER SCREEN TO MAXIMUM ELEMENT WIDTH INSIDE SLIDER ELEMENTS*****/
					var totalSliderContainerWidth = $(arrowRight).outerWidth(true) + $(arrowLeft).outerWidth(true);
					if(opts.element) {
						var biggestWidth = 0;
						$(opts.element).children().each(function(i,x) {
							var elWidth = $(x).outerWidth(true);
							if(elWidth > biggestWidth)
								biggestWidth = elWidth;
						});
					}
					totalSliderContainerWidth = totalSliderContainerWidth + biggestWidth;
					if(totalSliderContainerWidth > opts.width) {
						$(storeAttrs.container).css({ 'width':totalSliderContainerWidth+'px' });
						opts.width = totalSliderContainerWidth;
					}
					/***************************************************************************/
					storeAttrs.slideScreenWidth = (opts.width-$(arrowContainerLeft).outerWidth(true)-$(arrowContainerRight).outerWidth(true));
					$(slideScreen).css({ 
										  'width':storeAttrs.slideScreenWidth+'px'
									  });
					if(opts.element) {
						$(opts.element).children().each(function(i,x) {
							var marginTopMiddle = (opts.height - $(x).height()) / 2;
							$(x).css({
								'width':storeAttrs.slideScreenWidth+'px',
								'textAlign':'center',
								'marginTop':marginTopMiddle
							});
						});
						$(storeAttrs.slider).append(opts.element);
					}
					var marginTopRightArrow = (opts.height - $(arrowRight).outerHeight(true)) / 2;
					$(arrowRight).css({ 
										'marginTop':marginTopRightArrow
									  });
					
					var marginTopLeftArrow = (opts.height - $(arrowLeft).outerHeight(true)) / 2;
					$(arrowLeft).css({ 
										'marginTop':marginTopLeftArrow
									  });
		},100,obj);
	}
	this.moveRight = function() {
		if($.inArray("inprogress",$(storeAttrs.slider).queue())) {
			$(storeAttrs.slider).animate({
									   'marginLeft':(parseInt($(storeAttrs.slider).css('marginLeft').replace('px',''),10)-storeAttrs.slideScreenWidth)+'px'
									   },600);
		}
	}
	this.moveLeft = function() {
		if($.inArray("inprogress",$(storeAttrs.slider).queue())) {
			$(storeAttrs.slider).animate({
									   'marginLeft':(parseInt($(storeAttrs.slider).css('marginLeft').replace('px',''),10)+storeAttrs.slideScreenWidth)+'px'
									   },600);
		}
	}
	this.init();
}

