/*
	FUDGE + AREA17 auto paginated content slider with next/prev btns
	-----------------
	
	Usage: jQuery('div[class*=-slider-container]').f_slider({ itemsVisible: 4, doAutoScroll: false, slideAmount: 660 });
	
	Authors: Mike '1312' Byrne and Seb
	
	Copyright 2009 Fudge Studios & AREA 17

*/

jQuery.fn.f_slider = function(options) {
	
	// Set Options
	var options = jQuery.extend({
		itemsVisible: 1,
		doAutoScroll: false,
		slideAmount: ""
	}, options);
	
	if (options.slideAmount != "" && jQuery(jQuery(this).selector).length > 0) {
		
		return this.each(function (i) {
		
			// slider container
			var sliderContainer = jQuery(this);
			// slider motion
			var sliderInner = sliderContainer.find("ul[class*=-slider]");
			// get all the items in the slider list
			var listItems = sliderContainer.find("ul[class*=-slider]").children();
			// get the html of the list items into a var (picked up later)
			var listItemsHTML;
			// is the slider moving
			var sliderMoving = false;
			// which bit of the slider are we working on?
			var itemsVisible = options.itemsVisible;
			var currentSliderCount = itemsVisible;
			var currentSliderPos = 0;
			var initSliderPos = currentSliderPos;
			var slideAmount = options.slideAmount;
			// a var to attach the autoscroller set interval to
			var doAutoScroll = options.doAutoScroll;
			
			// the slider functions
			function moveSlider(direction) {
				if (!sliderMoving) {
					clearInterval(doAutoScroll);
					calculateNextPosition(direction);
					sliderMoving = true;
					sliderInner.animate({
						left: (currentSliderPos * -1)					
					}, 1000, function(){
						checkForLoop();
					});
					updatePaginator2();
				}
			}		
			// calculate the next position of the slider
			function calculateNextPosition(direction) {
				if(direction == 'right') {
					currentSliderCount = currentSliderCount + itemsVisible;
					currentSliderPos += slideAmount;
				} else if (direction == 'left') {			
					currentSliderCount = currentSliderCount - itemsVisible;
					currentSliderPos -= slideAmount;
				} else {
					currentSliderCount = (direction + 1) * itemsVisible;
					// working out the width of the original set of LIs
					var width = (slideAmount/itemsVisible) * listItems.length;
					currentSliderPos = width - initSliderPos + (direction * slideAmount);
				}
			}
			// auto scroll
			function autoScroll() {
				moveSlider('right');	
			}
			// add extra list items into the dom!
			function addListItems() {
				if (listItems.length > 0) {
					// check the amount of LIs, make to a division of 4
					// and then keep checking until it is				
					for (var i=1; i<=itemsVisible; i++) {
						var isEvenTest = listItems.length % itemsVisible;
						if ((isEvenTest*1) > 0) {
							sliderInner.append('<li class="blank"></li>');
							listItems = sliderContainer.find("ul[class*=-slider]").children();
						}
					}
					// more setting up needed, based on any new elements that have been added
					listItemsHTML = sliderContainer.find("ul[class*=-slider]").html();
					listItems = sliderContainer.find("ul[class*=-slider]").children();		
					// sort out the paginator size
					var paginatorBtns = listItems.length / itemsVisible;
					for (var i=1; i<=paginatorBtns; i++) {
						if (i==1) {
							sliderContainer.find("ul[class*=paginator]").append('<li class="current"><a href="#">'+i+'</a></li>');
						} else {
							sliderContainer.find("ul[class*=paginator]").append('<li><a href="#">'+i+'</a></li>');
						}
					}
					if (jQuery.browser.msie) {
						if (sliderContainer.parent("div.col").prev("div.col-first").children("h3").html() == "Sorties de la semaine") {
						} else {
							var pw = (paginatorBtns * 13) + 63;
							sliderContainer.find("ul[class*=paginator]").css("width",pw);
						}
						
					}
					// now duplicate the li's to be able to do the looping animation of them			
					if (listItems.length > itemsVisible) {				
						// add in a copy of the LIs - twice
						// there are now 3 copies of the LIs and we want to mainly see the middle set,
						// and then over run onto one of the 2 copies, either left or right
						// before resetting back to showing the middle set
						sliderInner.append(listItemsHTML);
						sliderInner.append(listItemsHTML);
						// sorts out positions and variables that other slider functions use
						resetSlider();
						// set up the prototype periodical executor
						//new PeriodicalExecuter(autoScroll, 5);
						// gah need to stop and start it, setInterval it is then...
						if (doAutoScroll != false) {
							doAutoScroll = setInterval(autoScroll, 5000 );
						}
					} else {
						// less than shown, dont do any auto scroll or any btn funcs
						sliderContainer.find("ul[class*=paginator]").find("li.current a").hide();
						sliderContainer.find("ul[class*=paginator]").find("li.next a").hide();
						sliderContainer.find("ul[class*=paginator]").find("li.prev a").hide();
					}
				} else {
					// nothing in the list!
					sliderContainer.find("ul[class*=paginator]").find("li.next a").hide();
					sliderContainer.find("ul[class*=paginator]").find("li.prev a").hide();
				}
			}
			// check for loop, reset if need be
			function checkForLoop() {
				// if current is bigger than the amount plus 3(?), then we're repeating the first 4 LIs, so we can just show the middle set again
				// or
				// if current is the same as negative amount minus 4(?), we've now gone backwards a full set, so we can just show the middle set again
				if( (currentSliderCount >= (listItems.length + itemsVisible)) || (currentSliderCount == 0) ) {
					resetSlider();
				}
				//update the paginator
				//updatePaginator();
				//
				sliderMoving = false;
				if (doAutoScroll != false) {
					doAutoScroll = setInterval(autoScroll, 5000);
				}
			}
			// reset slider position and variables
			function resetSlider() {
				// as default or as just gone backwards:
		
				// working out the width of the original set of LIs
				var width = (slideAmount/itemsVisible) * listItems.length;
				// 0 is gone backwards, else is gone forwards
				if(currentSliderCount == 0) {
					currentSliderCount = listItems.length;
					// then adjusting (so the left button doesnt obscure)
					currentSliderPos = width + width - slideAmount - initSliderPos;
				} else {
					currentSliderCount = itemsVisible;
					// then adjusting (so the left button doesnt obscure)
					currentSliderPos = width - initSliderPos;
				}
				// then need to sort the position out, so that the middle set of LIs is shown.
				var posAdjust = "-"+currentSliderPos+"px";
				// and adjust
				sliderInner.css({ left: posAdjust });
				//
			}
			// update paginator links (this is to be run after the animation has happened, alternatively you can use the v2)
			function updatePaginator() {
				sliderContainer.find("ul[class*=paginator]").find("li.current").removeClass("current");
				var paginatorCurrent = currentSliderCount/itemsVisible;
				paginatorCurrent = paginatorCurrent + 1;
				sliderContainer.find("ul[class*=paginator]").find("li:eq("+paginatorCurrent+")").addClass("current");
			}
			// update paginator links (this can be run at the same time the animation starts, has bits of code from checkforloop and reset in it)
			function updatePaginator2() {
				var cSc = currentSliderCount;
				if( (currentSliderCount >= (listItems.length + itemsVisible)) || (currentSliderCount == 0) ) {
					if(cSc == 0) {
						cSc = listItems.length;
					} else {
						cSc = itemsVisible;
					}
				}
				sliderContainer.find("ul[class*=paginator]").find("li.current").removeClass("current");
				var paginatorCurrent = cSc/itemsVisible;
				paginatorCurrent = paginatorCurrent + 1;
				sliderContainer.find("ul[class*=paginator]").find("li:eq("+paginatorCurrent+")").addClass("current");
			}
			// need to make sure extra list items have been added if needed
			addListItems();
			// add some events to the slider buttons
			sliderContainer.find("ul[class*=paginator]").find("li.prev a").click(function(e){
				e.preventDefault();
				moveSlider('left');
			});
			sliderContainer.find("ul[class*=paginator]").find("li.next a").click(function(e){
				e.preventDefault();
				moveSlider('right');
			});
			sliderContainer.find("ul[class*=paginator]").find("li a").each(function(i,val){
				if (i > 1 && !sliderContainer.sliderMoving) {
					jQuery(val).click(function(e) {
						e.preventDefault();
						if (!jQuery(this).parent().hasClass("current") && !sliderMoving) {
							moveSlider(i-2);
							sliderContainer.find("ul[class*=paginator]").find("li.current").removeClass("current");
							jQuery(val).parents("li").addClass("current");
						}
					});
				}
			});
		
		});
	
	}
};

jQuery.fn.f_controler = function(options) {

	myFeature = function(name) {
		this.init(name);
	}
	
	jQuery.extend(myFeature.prototype, {
		widget_name: '',
		widget_scrollInterval: 0,
		widget_delay: 0,
		widget_faderTimer: 0,
		widget_hoverTimer: 0,
		
		widget_sliderContainer: '',
		widget_sliderInner: '',
		widget_listItems: '',
		widget_currentSliderPos: '',
		widget_initSliderPos: '',
		widget_slideAmount: '',
		widget_isFading: false,
		widget_scrollInterval: false,
		
		widget_setIntervalId: 0,
		widget_setTimeOutId: 0,
		widget_setTimeOutId2: 0,
		widget_setTimeOutId3: 0,

		// getter widget name
		myNameIs: function() {
			return this.widget_name;
		},
		
		// getter/setter for scroll interval
		saveScrollInterval: function(widget_scrollInterval) {
			this.widget_scrollInterval = widget_scrollInterval;
		},
		getScrollInterval: function() {
			return this.widget_scrollInterval;
		},
		
		// getter/setter for fader timer
		saveFaderTimer: function(widget_faderTimer) {
			this.widget_faderTimer = widget_faderTimer;
		},
		getFaderTimer: function() {
			return this.widget_faderTimer;
		},
		// getter/setter for delay
		saveDelay: function(widget_delay) {
			this.widget_delay = widget_delay;
		},
		getDelay: function() {
			return this.widget_delay;
		},
		// getter/setter for hover timer
		saveHoverTimer: function(widget_hoverTimer) {
			this.widget_hoverTimer = widget_hoverTimer;
		},
		getHoverTimer: function() {
			return this.widget_hoverTimer;
		},
		
		// getter/setter for the setInterval id
		saveSetIntervalId: function(widget_setIntervalId) {
			this.widget_setIntervalId = widget_setIntervalId;
		},
		getSetIntervalId: function() {
			return this.widget_setIntervalId;
		},
		
		// getter/setter for the setTimeOut id
		saveSetTimeOutId: function(widget_setTimeOutId) {
			this.widget_setTimeOutId = widget_setTimeOutId;
		},
		getSetTimeOutId: function() {
			return this.widget_setTimeOutId;
		},
		
		// getter/setter for the setTimeOut id 2
		saveSetTimeOutId2: function(widget_setTimeOutId2) {
			this.widget_setTimeOutId2 = widget_setTimeOutId2;
		},
		getSetTimeOutId2: function() {
			return this.widget_setTimeOutId2;
		},
		
		// getter/setter for the setTimeOut id 3
		saveSetTimeOutId3: function(widget_setTimeOutId3) {
			this.widget_setTimeOutId3 = widget_setTimeOutId3;
		},
		getSetTimeOutId3: function() {
			return this.widget_setTimeOutId3;
		},
		
		moveSlider: function(widget_direction, widget_trigger) {
			if (!this.widget_isFading) {
				this.widget_listItems.eq(this.widget_currentSliderPos).fadeOut(800);
				this.widget_isFading = true;
				this.calculateNextPosition(widget_direction); 
				this.widget_listItems.eq(this.widget_currentSliderPos).fadeIn(1000);
				this.widget_isFading = false;
				// updates the paginator (not if we use the pagination bullets)
				if (widget_trigger != "bullet") {
					this.updatePaginator();
				}
			}			
		},
		
		calculateNextPosition: function(widget_direction) {
			if (widget_direction == "right") {
				if (this.widget_currentSliderPos == this.widget_listItems.length - 1) {
					this.resetSlider();
				} else {
					this.widget_currentSliderPos++;
				}
			} else {
				this.widget_currentSliderPos = widget_direction;
			}
		},
		
		resetSlider: function() {
			this.widget_currentSliderPos = this.widget_initSliderPos;
		},
		
		updatePaginator: function() {
			this.paginatorCurrent = this.widget_sliderContainer.find("ul[class*=paginator]").find("li.current").prevAll().size();
			this.widget_sliderContainer.find("ul[class*=paginator]").find("li.current").removeClass("current");
			// if we reach the last paginator, we rollback to the 1st
			if (this.paginatorCurrent == this.widget_listItems.length + 1) {
				this.paginatorCurrent = 1;
			}
			this.paginatorCurrent = this.paginatorCurrent + 1;
			this.widget_sliderContainer.find("ul[class*=paginator]").find("li:eq("+this.paginatorCurrent+")").addClass("current");
		},
		
		hideNonVisiblePosters: function() {
			if (this.widget_listItems.length > 0) {
				for (var i = this.widget_listItems.length; i > 1; i--) {
					this.widget_listItems.eq(i-1).hide();
				}
			}
		},
		
		addListItems: function() {
			if (this.widget_listItems.length > 0) {
				// sort out the paginator size
				this.paginatorBtns = this.widget_listItems.length;
				for (var i=1; i<=this.paginatorBtns; i++) {
					if (i==1) {
						this.widget_sliderContainer.find("ul[class*=paginator]").append('<li class="current"><a href="#">'+i+'</a></li>');
					} else {
						this.widget_sliderContainer.find("ul[class*=paginator]").append('<li><a href="#">'+i+'</a></li>');
					}
				}
				if (jQuery.browser.msie) {
					var pw = (this.paginatorBtns * 13) + 63;
					this.widget_sliderContainer.find("ul[class*=paginator]").css("width",pw);
				}
				
			} else {
				// nothing in the list!
				this.widget_sliderContainer.find("ul[class*=paginator]").find("li.next a").hide();
				this.widget_sliderContainer.find("ul[class*=paginator]").find("li.prev a").hide();
			}
		},
		
		// start slider auto fade
		autoFade: function() {
			this.moveSlider("right", "");
		},
		
		info: function() {
			//console.log('my name is ' + this.widget_name + " and have a delay of " + this.widget_delay);
			//console.log('my name is ' + this.widget_name + " and have a fader timer of " + this.widget_faderTimer);
		},
		init: function(options) {
			
			var options = jQuery.extend({
				widget_name: "",
				widget_scrollInterval: 0,
				widget_delay: 0
			}, options);
			
			this.widget_name = options.widget_name;
			this.widget_scrollInterval = options.widget_scrollInterval;
			this.widget_delay = options.widget_delay;
			
			this.widget_sliderContainer = jQuery("#" + this.widget_name);
			this.widget_sliderInner = this.widget_sliderContainer.find("ul[class*=-slider]");
			this.widget_listItems = this.widget_sliderInner.children();
			
			this.widget_currentSliderPos = 0;
			this.widget_initSliderPos = this.widget_currentSliderPos;
			
			this.hideNonVisiblePosters();
			this.addListItems();
			
		}
		
	});
	
	// private rescoping method
	var rescope = function(scope, method){
	        if(!method){ method = scope; scope = null; }
	        if(typeof method == "string"){
	                scope = scope || window;
	                if(!scope[method]){ throw(['method not found']); }
	                return function(){ return scope[method].apply(scope, arguments || []); };
	        }
	        return !scope ? method : function(){ return method.apply(scope,	arguments || []); };
	}
	
	// PUBLIC function to move the slider
	// _name : name of the feature
	// _direction : direction of the move
	// _delay : runs the auto fade after X seconds of delay
	// _scrollInterval : runs the auto fade every X seconds of autofade
	// _iterator : since each feature calls twice moveSlider, we have 2 setTimeOut ids so we have to keep track of them
	jQuery.fn.f_moveSlider = function(_name, _direction, _delay, _scrollInterval, _iterator, _trigger) {
		if (_name == g1.myNameIs()) {
			if (_delay >= 0) {
				var _d = setTimeout(function() {
					if (_scrollInterval > 0) {
						var _t = setInterval(_g1_scrollInterval, _scrollInterval);
						g1.saveSetIntervalId(_t);
						//console.log("g1.saveSetIntervalId= " + _t + " (iterator #" + _iterator + ")");
					} else {
						//console.log("g1.direction= " + _direction + " (iterator #" + _iterator + ")");
						g1.moveSlider(_direction, _trigger);
					}
				}, _delay);	
				//console.log(g1.myNameIs() + " timeOutId= " + _d);
				if (_iterator == 1) {
					g1.saveSetTimeOutId(_d);
					//console.log("g1.saveSetTimeOutId= " + _iterator);
				} else if (_iterator == 2) {
					g1.saveSetTimeOutId2(_d);
					//console.log("g1.saveSetTimeOutId2= " + _iterator);
				} else if (_iterator == 3) {
					g1.saveSetTimeOutId3(_d);
					//console.log("g1.saveSetTimeOutId3= " + _iterator);
				}			
			}
		} else if (_name == g2.myNameIs()) {
			if (_delay >= 0) {
				var _d = setTimeout(function() {
					if (_scrollInterval > 0) {
						var _t = setInterval(_g2_scrollInterval, _scrollInterval);
						g2.saveSetIntervalId(_t);
					} else {
						g2.moveSlider(_direction, _trigger);
					}
				}, _delay);	
				//console.log(g2.myNameIs() + " timeOutId= " + _d);
				if (_iterator == 1) {
					g2.saveSetTimeOutId(_d);
					//console.log("g2.saveSetTimeOutId= " + _iterator);
				} else if (_iterator == 2) {
					g2.saveSetTimeOutId2(_d);
					//console.log("g2.saveSetTimeOutId2= " + _iterator);
				}			
			}
		} else if (_name == g3.myNameIs()) {
			if (_delay >= 0) {
				var _d = setTimeout(function() {
					if (_scrollInterval > 0) {
						var _t = setInterval(_g3_scrollInterval, _scrollInterval);
						g3.saveSetIntervalId(_t);
						//console.log(g3.myNameIs() + " setIntervalid= " + _t);
					} else {
						g3.moveSlider(_direction, _trigger);
					}
				}, _delay);
				//console.log(g3.myNameIs() + " timeOutId= " + _d);
				if (_iterator == 1) {
					g3.saveSetTimeOutId(_d);
					//console.log("g3.saveSetTimeOutId= " + _iterator);
				} else if (_iterator == 2) {
					g3.saveSetTimeOutId2(_d);
					//console.log("g3.saveSetTimeOutId2= " + _iterator);
				}				
			}
		} else {
			return -1;
		}		
	}
	
	// the following 3 functions had to be created in order to use "setInterval" properly in f_startAutoFader
	function _g1_scrollInterval() {
		g1.autoFade();
	}
	function _g2_scrollInterval() {
		g2.autoFade();
	}
	function _g3_scrollInterval() {
		g3.autoFade();
	}
	
	// Anonymous functions to clear the intervals
	function _g1_clearIntervals() {
		clearInterval(g1.getSetTimeOutId());
		clearInterval(g1.getSetTimeOutId2());
		clearInterval(g1.getSetIntervalId());
	}
	
	function _g2_clearIntervals() {
		clearInterval(g2.getSetTimeOutId());
		clearInterval(g2.getSetTimeOutId2());
		clearInterval(g2.getSetIntervalId());
	}
	
	function _g3_clearIntervals() {
		clearInterval(g3.getSetTimeOutId());
		clearInterval(g3.getSetTimeOutId2());
		clearInterval(g3.getSetIntervalId());
	}
	
	// PUBLIC function to stop the autofader (individually or all)
	jQuery.fn.f_stopAutoFader = function(_name) {
		if (_name == g1.myNameIs()) {
			_g1_clearIntervals();
		} else if (_name == g2.myNameIs()) {
			_g2_clearIntervals();
		} else if (_name == g3.myNameIs()) {
			_g3_clearIntervals();
		} else if (_name == "all") {
			_g1_clearIntervals();
			_g2_clearIntervals();
			_g3_clearIntervals();
		} else {
			return -1;
		}		
	}
	
	// Resynchronizing all 3 features. 
	// First we stop all auto fading
	// Then based on the name of the feature that has been rolled out, we relaunch all 3 with the right sequence order changes while keeping the proper delays
	// So on mouse out event : 
	// if (this) is genre-1
	// we stop all timers, genre-1 fades after 2 seconds we relaunch with config#1 (1=0s, 2=2s, 3=4s);
	// if (this) is genre-2
	// we stop all timers and relaunch with config #2 (2=0s, 3=2s, 1=4s)
	// if (this) is genre-3
	// we stop all timers and relaunch with config #3 (3=0s, 1=2s, 2=4s)
	jQuery.fn.f_launchSynchroFaders = function(_name, _trigger) {
		
		this.delay_1 = g1.getDelay();
		this.delay_2 = g2.getDelay();
		this.delay_3 = g3.getDelay();
		
		if (_trigger == "mouseout") {
			jQuery().f_stopAutoFader("all");
		} else if (_trigger == "bullet") {
			this.delay_1 += 1000;
			this.delay_2 += 1000;
			this.delay_3 += 1000;
		}
	
		if (_name == g1.myNameIs()) {
			jQuery().f_moveSlider(g1.myNameIs(), "right", this.delay_1, 0, 1, "");
			jQuery().f_moveSlider(g2.myNameIs(), "right", this.delay_2, 0, 1, "");
			jQuery().f_moveSlider(g3.myNameIs(), "right", this.delay_3, 0, 1, "");
			// this runs the sequence every 6 eights seconds. the trick here is that it waits for 8 seconds on launch before running and 
			// repeating every next 6 seconds
			jQuery().f_moveSlider(g1.myNameIs(), "right", this.delay_1, g1.getScrollInterval(), 2, "");
			jQuery().f_moveSlider(g2.myNameIs(), "right", this.delay_2, g2.getScrollInterval(), 2, "");
			jQuery().f_moveSlider(g3.myNameIs(), "right", this.delay_3, g3.getScrollInterval(), 2, "");
			
		} else if (_name == g2.myNameIs()) {
			
			jQuery().f_moveSlider(g2.myNameIs(), "right", this.delay_1, 0, 1, "");
			jQuery().f_moveSlider(g3.myNameIs(), "right", this.delay_2, 0, 1, "");
			jQuery().f_moveSlider(g1.myNameIs(), "right", this.delay_3, 0, 1, "");
			
			jQuery().f_moveSlider(g2.myNameIs(), "right", this.delay_1, g2.getScrollInterval(), 2, "") ;
			jQuery().f_moveSlider(g3.myNameIs(), "right", this.delay_2, g3.getScrollInterval(), 2, "");
			jQuery().f_moveSlider(g1.myNameIs(), "right", this.delay_3, g1.getScrollInterval(), 2, "");
			
		} else if (_name == g3.myNameIs()) {
			
			jQuery().f_moveSlider(g3.myNameIs(), "right", this.delay_1, 0, 1, "");
			jQuery().f_moveSlider(g1.myNameIs(), "right", this.delay_2, 0, 1, "");
			jQuery().f_moveSlider(g2.myNameIs(), "right", this.delay_3, 0, 1, "");
			
			jQuery().f_moveSlider(g3.myNameIs(), "right", this.delay_1, g3.getScrollInterval(), 2, "");
			jQuery().f_moveSlider(g1.myNameIs(), "right", this.delay_2, g1.getScrollInterval(), 2, "");
			jQuery().f_moveSlider(g2.myNameIs(), "right", this.delay_3, g2.getScrollInterval(), 2, "");
		} 
		
		delete this.delay_1;
		delete this.delay_2;
		delete this.delay_3;
	}
	
	// We use this function to synchronize two features when the third is being hovered
	jQuery.fn.f_ajustSynchroFaders = function(_name) {
		
		this.delay_1 = g1.getDelay();
		this.delay_2 = g2.getDelay();
		this.widget_scrollInterval = g1.getScrollInterval() - 2000;
		
		if (_name == g1.myNameIs()) {
			jQuery().f_moveSlider(g2.myNameIs(), "right", this.delay_1, 0, 1, "");
			jQuery().f_moveSlider(g3.myNameIs(), "right", this.delay_2, 0, 1, "");
			// this runs the sequence every 6 eights seconds. the trick here is that it waits for 8 seconds on launch before running and 
			// repeating every next 6 seconds
			jQuery().f_moveSlider(g2.myNameIs(), "right", this.delay_1, this.widget_scrollInterval, 2, "");
			jQuery().f_moveSlider(g3.myNameIs(), "right", this.delay_2, this.widget_scrollInterval, 2, "");
			
		} else if (_name == g2.myNameIs()) {
			jQuery().f_moveSlider(g3.myNameIs(), "right", this.delay_1, 0, 1, "");
			jQuery().f_moveSlider(g1.myNameIs(), "right", this.delay_2, 0, 1, "");
			jQuery().f_moveSlider(g3.myNameIs(), "right", this.delay_1, this.widget_scrollInterval, 2, "");
			jQuery().f_moveSlider(g1.myNameIs(), "right", this.delay_2, this.widget_scrollInterval, 2, "");
			
		} else if (_name == g3.myNameIs()) {
			jQuery().f_moveSlider(g1.myNameIs(), "right", this.delay_1, 0, 1, "");
			jQuery().f_moveSlider(g2.myNameIs(), "right", this.delay_2, 0, 1, "");
			jQuery().f_moveSlider(g1.myNameIs(), "right", this.delay_1, this.widget_scrollInterval, 2, "");
			jQuery().f_moveSlider(g2.myNameIs(), "right", this.delay_2, this.widget_scrollInterval, 2, "");
		}	
		
		delete this.delay_1;
		delete this.delay_2;
		delete this.widget_scrollInterval;
	}
	
	// Creating the objects
	var g1 = new myFeature({ widget_name: "genre-1", widget_scrollInterval: 6000, widget_delay: 2000});
	var g2 = new myFeature({ widget_name: "genre-2", widget_scrollInterval: 6000, widget_delay: 4000});
	var g3 = new myFeature({ widget_name: "genre-3", widget_scrollInterval: 6000, widget_delay: 6000});
	
	// Starting the auto fade 
	jQuery().f_launchSynchroFaders("genre-1");
	
	// Attaching mouse events (pagination click, feature hover);
	jQuery('div.genre').f_faderMouseEvents();
	

};

jQuery.fn.f_faderMouseEvents = function() {
	
	if ((jQuery(this).selector).length > 0) {
		
		return this.each(function (i) {
			// slider id
			var sliderId = jQuery(this).attr("id");
			// slider container
			var sliderContainer = jQuery(this);
			// slider motion
			var sliderInner = sliderContainer.find("ul[class*=-slider]");
			// get all the items in the slider list
			var listItems = sliderContainer.find("ul[class*=-slider]").children();
			
			// rescoping methods
			var rescope = function(scope, method){
			        if(!method){ method = scope; scope = null; }
			        if(typeof method == "string"){
			                scope = scope || window;
			                if(!scope[method]){ throw(['method not found']); }
			                return function(){ return scope[method].apply(scope, arguments || []); };
			        }
			        return !scope ? method : function(){ return method.apply(scope,	arguments || []); };
			}
			
			// Click event on slider pagination bullets
			sliderContainer.find("ul[class*=paginator]").find("li a").each(function(i,val){
				if (i > 1) {
					jQuery(val).click(function(e) {
						e.preventDefault();
						if (!jQuery(this).parent().hasClass("current")) {
							jQuery().f_stopAutoFader("all"); // making s
							jQuery().f_moveSlider(sliderId, i-2, 0, 0, 3, "bullet"); //function(_name, _direction, _delay, _scrollInterval, _iterator)
							sliderContainer.find("ul[class*=paginator]").find("li.current").removeClass("current");
							jQuery(val).parents("li").addClass("current");
							
							// if we are still hovering the bullets, don't run auto fade for the current slide but adjust the two other features
							if (sliderInner.hasClass("features-hover")) {
								jQuery().f_ajustSynchroFaders(sliderId);
							}
							// if not, run general auto fade for all three features 
							else {
								jQuery().f_launchSynchroFaders(sliderId, "bullet");
							}
						}
					});
				}
			});
			
			// Hover event on the slider paginator bullets
			sliderContainer.find("ul.paginator").hover(function(){
				sliderContainer.find("ul.features-slider").addClass("features-hover");
				jQuery().f_stopAutoFader("all");
				jQuery().f_ajustSynchroFaders(sliderId);
			}, function() {
				sliderContainer.find("ul.features-slider").removeClass("features-hover");
				jQuery().f_launchSynchroFaders(sliderId, "mouseout");
			});

			// Hover on the slider
			sliderInner.hover(function(){
				sliderInner.addClass("features-hover");
				jQuery().f_stopAutoFader("all");
				jQuery().f_ajustSynchroFaders(sliderId);
			}, function() {
				sliderInner.removeClass("features-hover");
				if (jQuery("div#lb-mask").css("display") == "none" ) jQuery().f_launchSynchroFaders(sliderId, "mouseout");
				
			});
		});
	}
};


function videoSlider() {

	jQuery("ul.videos-slider li._videos").hover(function(){
		jQuery(this).addClass("pointer");
	}, function() {
		jQuery(this).removeClass("pointer");
	});
	
	jQuery("ul.videos-slider li h4 a.a_info, ul.videos-slider li h4 a.a_img, ul.videos-slider li h4 a.video").hover(function(){
		jQuery(this).parents("li").removeClass("pointer");
	}, function() {
		jQuery(this).parents("li").addClass("pointer");
	});
	jQuery("ul.videos-slider li p a.a_info").hover(function(){
		jQuery(this).parents("li").addClass("hover");
	}, function() {
		jQuery(this).parents("li").removeClass("hover");
	});
	
	jQuery("ul.videos-slider li._videos").click(function(e) {
		if (jQuery(this).hasClass("pointer")) {
			e.preventDefault();
			var href = jQuery(this).find("a").attr("href");
			if (href != "#" && href != "" && href != undefined) {
				window.location = href;
			}
		}
	});

}