jQuery.fn.extend({
	galleryShop: function(options) {
		return this.each(function() {
			new jQuery.fnGalleryShop(this, options);
		});
	}
});


jQuery.fnGalleryShop = function(object, options) {

	var opt = options || {};
	opt.maxItem = 10;
	opt.slideSpeed = opt.slideSpeed || 0; // "slow", "normal", "fast" or the number of milliseconds -> 0 = no animation

	var thisObj = $(object); // $(object) = $(this)
	var currPosition = 0;
	var slideWidth = 69; // width+border+margin
	var slidesItem = thisObj.find("a");
	var slidesNumber = slidesItem.length;

	if ( slidesItem.length > opt.maxItem ) {
		thisObj.find(".slide").width( slidesNumber * slideWidth );

		//thisObj.find(".slide a").each(function(a) {
			//$(this).html("<span style='display: inline-block; padding-top: 7px; font-size: 12px;'>" + (a+1) + "</span>"); //test
		//});

		function mControl(_pos) {
			if (_pos == 0) {
				thisObj.find(".navBack").attr('id', 'Disabled');
				thisObj.find(".navBack").css({ backgroundPosition: '0% 0%', cursor: 'auto' });
			} else {
				thisObj.find(".navBack").attr('id', '');
				thisObj.find(".navBack").css({ backgroundPosition: '0% 100%', cursor: 'pointer' });
			}

			if (_pos == (slidesNumber-opt.maxItem)) {
				thisObj.find(".navNext").attr('id', 'Disabled');
				thisObj.find(".navNext").css({ backgroundPosition: '0% 0%', cursor: 'auto' });
			} else {
				thisObj.find(".navNext").attr('id', '');
				thisObj.find(".navNext").css({ backgroundPosition: '0% 100%', cursor: 'pointer' });
			}
		}

		mControl(currPosition);

		thisObj.find(".navBack, .navNext").bind("click", function() {
			if ( $(this).attr('id') != 'Disabled' ) {
				currPosition = ( $(this).attr("class") == "navNext" ) ? currPosition+1 : currPosition-1;
				mControl(currPosition);
				thisObj.find(".slide").animate( {"marginLeft": slideWidth*(-currPosition)}, {queue: true, duration: opt.slideSpeed} );
			}
		});

	}

}
