/*
blog: http://web-breaker.blogspot.com
author: FX from web-breaker blog
*/

function wbSlide2 (targetBox, showAtOnce, animateSpeed){
	$(document).ready(function(){
		var _this = $(targetBox);
		var itemNum = $('.wbItem2>div').length;
		var itemWidth = $(".wbItem2>div").outerWidth(true);
		var slideWidth = itemNum * itemWidth;
		var maxId = showAtOnce - itemNum;
		$('.wbItem2', _this).css({width : slideWidth + "px"});
		var cId = 0;
		$('.wbLeft2>img', _this).click(function () {
			cId ++;
			sliding (cId);
		});
		$('.wbRight2>img', _this).click(function () {
			cId --;
			sliding (cId);
		});
		function sliding (cId){
			if(cId == maxId) {$('.wbRight2>img', _this).hide();};
			if(cId == 0) {$('.wbLeft2>img', _this).hide();};
			var marginNum = itemWidth * cId;
			var newMargin = marginNum + 'px';
			$(".wbItem2", _this).animate( { marginLeft: marginNum + "px" }, {  duration:animateSpeed } );
			if(cId > maxId) {$('.wbRight2>img', _this).show();};
			if(cId < 0) {$('.wbLeft2>img', _this).show();}
		};
		if (itemNum <= showAtOnce){
			$('.wbLeft2>img', _this).hide();
			$('.wbRight2>img', _this).hide();
		} else {
			$('.wbLeft2>img', _this).hide();
		};
		
		$.extend($.fn.disableTextSelect = function() {
			return this.each(function(){
				if($.browser.mozilla){//Firefox
					$(this).css('MozUserSelect','none');
				}else if($.browser.msie){//IE
					$(this).bind('selectstart',function(){return false;});
				}else{//Opera, etc.
					$(this).mousedown(function(){return false;});
				}
			});
		});
		$('.wbLeft2>img', _this).disableTextSelect();
		$('.wbRight2>img', _this).disableTextSelect();
	});
}(jQuery);

