jQuery.noConflict();
(function($) { 
  $(function() {
	var SLIDE_SPEED = 5000;
	var thumb_div = $("#r11-feature-thumbs");
    var thumbs = $("#r11-feature-thumbs a");
	var slides = $("#r11-feature-slides div.r11-feature-slide");
	var pager_prev = $("#r11-feature-pager-prev");
	var pager_next = $("#r11-feature-pager-next");
	var current_thumb, slide_timer;
		
	thumb_div.css("background-position", "0 0");
	
	thumbs.each(function(i) {
		var thumb = $(this);
		var slide = $(slides[i]);
		
		thumb.click(function(ev) {	
			ev.preventDefault();
			current_thumb = $(this);
			
			clear_slide_timer();
			
			if(ev.button === undefined) {
				start_slide_timer();
			}
			
			slides.stop(1,1).fadeOut("slow");
			slide.stop(1,1).fadeIn("slow");
			
			var bg_pos = "(+" + (thumb.position().left-6) + "px 0)";
			
			thumb_div.stop().animate({backgroundPosition: bg_pos}, 400, "swing");
			
			// set pagers
			if(thumb.next().length) {
				pager_next.stop().removeClass("r11-pager-off").fadeTo("fast",1);				
			} else {
				pager_next.stop().addClass("r11-pager-off").fadeTo("fast",.4);				
			}
			
			if(thumb.prev().length) {
				pager_prev.stop().removeClass("r11-pager-off").fadeTo("fast",1);
			} else {
				pager_prev.stop().addClass("r11-pager-off").fadeTo("fast",.4);
			}			
		});
	});
	
	$(thumbs[0]).click();
	
	function start_slide_timer() {
		slide_timer = setTimeout(animate_slides, SLIDE_SPEED);
	}
	
	function clear_slide_timer() {
		clearTimeout(slide_timer);
	}	
		
	function animate_slides() {
		var next_thumb = current_thumb.next();		
		if(next_thumb.length) {
			current_thumb = next_thumb.click();
		} else {
			current_thumb = $(thumbs[0]).click();			
		}		
	}
	
	pager_next.click(function(ev) {
		ev.preventDefault();	
		if(!$(this).hasClass("r11-pager-off")) {
			clearInterval(slide_timer);		
			animate_slides();
		}
	});
	
	pager_prev.click(function(ev) {
		ev.preventDefault();	
		if(!$(this).hasClass("r11-pager-off")) {
			clearInterval(slide_timer);		
			var next_thumb = current_thumb.prev();		
			if(next_thumb.length) {
				current_thumb = next_thumb.click();
			} else {
				current_thumb = $(thumbs[0]).click();		
			}
		}
	});	
  });
})(jQuery);

/**
 * @author Alexander Farkas
 * v. 1.22
 */
(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = $.curCSS;
		$.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			fx.start = [start[0],start[2]];
			var end = toArray(fx.end);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);
