(function($)
{
	$.fn.cinemarkHslide = function (settings) {

		var container = this.children('.links');
		var slideContainer = container.children('ul');
		var items = slideContainer.children('li');
		
		var config = {
			x: 0,
			speedSlide: 1000,
			itemWidth: parseInt(items.css('width')) + parseInt(items.css('margin-right')), // ancho de cada item
			itemLengh: items.size(), // cantidad de items
			showItems: 8, // items que se mostraran
			prevButton: this.children('.prevBtn:first'),
			nextButton: this.children('.nextBtn:first')
		};

		if (settings) {
			$.extend(config, settings);
		}
		
		var slideContainerWidth = config.itemWidth * config.itemLengh;
			
		var x = config.x;
		
		slideContainer.css({width: slideContainerWidth + 'px'});
		
		config.prevButton.click(function () {
			if (x != 0)
			{
				x = x + config.itemWidth;
				startSlide();
			}
			return false;
		});
		
		config.nextButton.click(function () {
			if ((slideContainerWidth + x) > (config.showItems * config.itemWidth))
			{
				x = x - config.itemWidth;
				startSlide();
			}
			return false;
		});

		var startSlide = function () {
			slideContainer.animate({
				left: x
			}, config.speedSlide, function() {});
			if ((slideContainerWidth + x) > (config.showItems * config.itemWidth))
			{
				config.nextButton.children('a').show();
			}else{
				config.nextButton.children('a').hide();
			}
			if (x != 0)
			{
				config.prevButton.children('a').show();
			}else{
				config.prevButton.children('a').hide();
			}
		}
		
		startSlide();

		return this;
	};
})(jQuery);
