(function(B){B.tinysort={id:"TinySort",version:"1.0.0",defaults:{order:"asc",attr:"",place:"start",returns:false}};B.fn.extend({tinysort:function(G,H){if(G&&typeof (G)!="string"){H=G;G=null}var D=B.extend({},B.tinysort.defaults,H);var N={};this.each(function(R){var T=(!G||G=="")?B(this):B(this).find(G);var S=D.order=="rand"?""+Math.random():(D.attr==""?T.text():T.attr(D.attr));var Q=B(this).parent();if(!N[Q]){N[Q]={s:[],n:[]}}if(T.length>0){N[Q].s.push({s:S,e:B(this),n:R})}else{N[Q].n.push({e:B(this),n:R})}});for(var F in N){oParent=N[F];oParent.s.sort(function I(S,R){var Q=S.s.toLowerCase();var T=R.s.toLowerCase();if(C(S.s)&&C(R.s)){Q=parseFloat(S.s);T=parseFloat(R.s)}return(D.order=="asc"?1:-1)*(Q<T?-1:(Q>T?1:0))})}var K=[];for(var F in N){oParent=N[F];var L=[];var E=B(this).length;switch(D.place){case"first":B.each(oParent.s,function(Q,R){E=Math.min(E,R.n)});break;case"org":B.each(oParent.s,function(Q,R){L.push(R.n)});break;case"end":E=oParent.n.length;break;default:E=0}var O=[0,0];for(var J=0;J<B(this).length;J++){var M=J>=E&&J<E+oParent.s.length;if(A(L,J)){M=true}var P=(M?oParent.s:oParent.n)[O[M?0:1]].e;P.parent().append(P);if(M||!D.returns){K.push(P.get(0))}O[M?0:1]++}}return this.setArray(K)}});function C(D){return(parseFloat(D)+"")==D}function A(E,F){var D=false;B.each(E,function(H,G){if(!D){D=G==F}});return D}B.fn.TinySort=B.fn.Tinysort=B.fn.tsort=B.fn.tinysort})(jQuery);
//Set the id names of your tablinks (without a number at the end)
var tablink_idname = new Array("tablink")
//Set the id names of your tabcontentareas (without a number at the end)
var tabcontent_idname = new Array("tabcontent") 
//Set the number of your tabs in each menu
var tabcount = new Array("9")
//Set the Tabs wich should load at start (In this Example:Menu 1 -> Tab 2 visible on load, Menu 2 -> Tab 5 visible on load , Menu 3 -> Tab 1 visible on load)
var loadtabs = new Array("1")  
//Set the Number of the Menu which should autochange (if you dont't want to have a change menu set it to 0)
var autochangemenu = 1;
//the speed in seconds when the tabs should change
var changespeed = 15;
//should the autochange stop if the user hover over a tab from the autochangemenu? 0=no 1=yes
var stoponhover = 0;
//END MENU SETTINGS

function easytabs(menunr, active) {if (menunr == autochangemenu){currenttab=active;}if ((menunr == autochangemenu)&&(stoponhover==1)) {stop_autochange()} else if ((menunr == autochangemenu)&&(stoponhover==0))  {counter=0;} menunr = menunr-1;for (i=1; i <= tabcount[menunr]; i++){document.getElementById(tablink_idname[menunr]+i).className='tab'+i;document.getElementById(tabcontent_idname[menunr]+i).style.display = 'none';}document.getElementById(tablink_idname[menunr]+active).className='tab'+active+' tabactive';document.getElementById(tabcontent_idname[menunr]+active).style.display = 'block';}var timer; counter=0; var totaltabs=tabcount[autochangemenu-1];var currenttab=loadtabs[autochangemenu-1];function start_autochange(){counter=counter+1;timer=setTimeout("start_autochange()",1000);if (counter == changespeed+1) {currenttab++;if (currenttab>totaltabs) {currenttab=1}easytabs(autochangemenu,currenttab);restart_autochange();}}function restart_autochange(){clearTimeout(timer);counter=0;start_autochange();}function stop_autochange(){clearTimeout(timer);counter=0;}

(function($) {
		
	function fireEvent(opts, name, self, arg) {
		var fn = opts[name];
		
		if ($.isFunction(fn)) { 
			try {  
				return fn.call(self, arg);
				
			} catch (error) {
				if (opts.alert) {
					alert("Error calling scrollable." + name + ": " + error);
				} else {
					throw error;	
				}
				return false;
			} 					
		}
		return true;			
	}
				
	var current = null;	
	
	
	// constructor
	function Scrollable(root, conf) {   
				
		// current instance
		var self = this;  
		if (!current) { current = self; }		
		
		// horizontal flag
		var horizontal = !conf.vertical;		
		
		
		// wrap (root elements for items)
		var wrap = $(conf.items, root);				
		
		// current index
		var index = 0;
		
		
		// get handle to navigational elements
		var navi = root.siblings(conf.navi).eq(0);
		var prev = root.siblings(conf.prev).eq(0);
		var next = root.siblings(conf.next).eq(0);
		var prevPage = root.siblings(conf.prevPage).eq(0);
		var nextPage = root.siblings(conf.nextPage).eq(0);
		
		
		// methods
		$.extend(self, {
				
			getVersion: function() {
				return [1, 0, 1];	
			},
			
			getIndex: function() {
				return index;	
			},
	
			getConf: function() {
				return conf;	
			},
			
			getSize: function() {
				return self.getItems().size();	
			},
	
			getPageAmount: function() {
				return Math.ceil(this.getSize() / conf.size); 	
			},
			
			getPageIndex: function() {
				return Math.ceil(index / conf.size);	
			},

			getRoot: function() {
				return root;	
			},
			
			getItemWrap: function() {
				return wrap;	
			},
			
			getItems: function() {
				return wrap.children();	
			},
			
			/* all seeking functions depend on this */		
			seekTo: function(i, time, fn) {
				
				// default speed
				time = time || conf.speed;
				
				// function given as second argument
				if ($.isFunction(time)) {
					fn = time;
					time = conf.speed;
				}
								
				if (i < 0) { i = 0; }				
				if (i > self.getSize() - conf.size) { return self; } 				

				var item = self.getItems().eq(i);					
				if (!item.length) { return self; }				
				
				// onBeforeSeek
				if (fireEvent(conf, "onBeforeSeek", self, i) === false) {
					return self;	
				}									
				
				if (horizontal) {					
					var left = -(item.outerWidth(true) * i);					
					wrap.animate({left: left}, time, conf.easing, fn ? function() { fn.call(self); } : null);
					
				} else {
					var top = -(item.outerHeight(true) * i); // wrap.offset().top - item.offset().top;					
					wrap.animate({top: top}, time, conf.easing, fn ? function() { fn.call(self); } : null);							
				}	
				
				
				// navi status update
				if (navi.length) {
					var klass = conf.activeClass;
					var page = Math.ceil(i / conf.size);
					page = Math.min(page, navi.children().length - 1);
					navi.children().removeClass(klass).eq(page).addClass(klass);
				} 
				
				// prev buttons disabled flag
				if (i === 0) {
					prev.add(prevPage).addClass(conf.disabledClass);					
				} else {
					prev.add(prevPage).removeClass(conf.disabledClass);
				}
								
				// next buttons disabled flag
				if (i >= self.getSize() - conf.size) {
					next.add(nextPage).addClass(conf.disabledClass);
				} else {
					next.add(nextPage).removeClass(conf.disabledClass);
				}				
				
				current = self;
				index = i;				
				
				// onSeek after index being updated
				fireEvent(conf, "onSeek", self, i);	
				
				return self;
				
			},			
				
			move: function(offset, time, fn) {
				var to = index + offset;
				if (conf.loop && to > (self.getSize() - conf.size)) {
					to = 0;	
				}
				return this.seekTo(to, time, fn);
			},
			
			next: function(time, fn) {
				return this.move(1, time, fn);	
			},
			
			prev: function(time, fn) {
				return this.move(-1, time, fn);	
			},
			
			movePage: function(offset, time, fn) {
				return this.move(conf.size * offset, time, fn);		
			},
			
			setPage: function(page, time, fn) {
				var size = conf.size;
				var index = size * page;
				var lastPage = index + size >= this.getSize(); 
				if (lastPage) {
					index = this.getSize() - conf.size;
				}
				return this.seekTo(index, time, fn);
			},
			
			prevPage: function(time, fn) {
				return this.setPage(this.getPageIndex() - 1, time, fn);
			},  
	
			nextPage: function(time, fn) {
				return this.setPage(this.getPageIndex() + 1, time, fn);
			}, 
			
			begin: function(time, fn) {
				return this.seekTo(0, time, fn);	
			},
			
			end: function(time, fn) {
				return this.seekTo(this.getSize() - conf.size, time, fn);	
			},
			
			reload: function() {
				return load();	
			},
			
			click: function(index, time, fn) {
				
				var item = self.getItems().eq(index);
				var klass = conf.activeClass;			
				
				if (!item.hasClass(klass) && (index >= 0 || index < this.getSize())) {				
					self.getItems().removeClass(klass);
					item.addClass(klass);
					var delta = Math.floor(conf.size / 2);
					var to = index - delta;

					// next to last item must work
					if (to > self.getSize() - conf.size) { to--;	}
					
					if (to !== index) {
						return this.seekTo(to, time, fn);		
					}				 
				}
				
				return self;
			}			
			
		});
	
		
		// mousewheel
		if ($.isFunction($.fn.mousewheel)) { 
			root.bind("mousewheel.scrollable", function(e, delta)  {
				// opera goes to opposite direction
				var step = $.browser.opera ? 1 : -1;
				
				self.move(delta > 0 ? step : -step, 50);
				return false;
			});
		}  
		
		// prev button		
		prev.addClass(conf.disabledClass).click(function() { 
			self.prev(); 
		});
		

		// next button
		next.click(function() { 
			self.next(); 
		});
		
		// prev page button
		nextPage.click(function() { 
			self.nextPage(); 
		});
		

		// next page button
		prevPage.addClass(conf.disabledClass).click(function() { 
			self.prevPage(); 
		});		

		
		// keyboard
		if (conf.keyboard) {
			
			// unfortunately window.keypress does not work on IE.
			$(window).unbind("keypress.scrollable").bind("keypress.scrollable", function(evt) {
				
				var el = current;	
				if (!el) { return; }
					
				if (horizontal && (evt.keyCode == 37 || evt.keyCode == 39)) {					
					el.move(evt.keyCode == 37 ? -1 : 1);
					return evt.preventDefault();
				}	
				
				if (!horizontal && (evt.keyCode == 38 || evt.keyCode == 40)) {
					el.move(evt.keyCode == 38 ? -1 : 1);
					return evt.preventDefault();
				}
				
				return true;
				
			});	 
		}

		// navi 			
		function load() {			
			
			navi.each(function() {
				
				var nav = $(this);
				
				// generate new entries
				if (nav.is(":empty") || nav.data("me") == self) {
					
					nav.empty();
					nav.data("me", self);
					
					for (var i = 0; i < self.getPageAmount(); i++) {		
						
						var item = $("<" + conf.naviItem + "/>").attr("href", i).click(function(e) {							
							var el = $(this);
							el.parent().children().removeClass(conf.activeClass);
							el.addClass(conf.activeClass);
							self.setPage(el.attr("href"));
							return e.preventDefault();
						});
						
						if (i === 0) { item.addClass(conf.activeClass); }
						nav.append(item);					
					}
					
				// assign onClick events to existing entries
				} else {
					
					// find a entries first -> syntaxically correct
					var els = nav.children(); 
					
					els.each(function(i)  {
						var item = $(this);
						item.attr("href", i);
						if (i === 0) { item.addClass(conf.activeClass); }
						
						item.click(function() {
							nav.find("." + conf.activeClass).removeClass(conf.activeClass);
							item.addClass(conf.activeClass);
							self.setPage(item.attr("href"));
						});
						
					});
				}
				
			});
			
			
			// item.click()
			if (conf.clickable) {
				self.getItems().each(function(index, arg) {
					var el = $(this);
					if (!el.data("set")) {
						el.bind("click.scrollable", function() {
							self.click(index);		
						});
						el.data("set", true);
					}
				});				
			}
			
			
			// hover
			if (conf.hoverClass) {
				self.getItems().hover(function()  {
					$(this).addClass(conf.hoverClass);		
				}, function() {
					$(this).removeClass(conf.hoverClass);	
				});
			}			
			
			return self;
		}
		
		load();
		
		
		// interval stuff
		var timer = null;

		function setTimer() {
			timer = setInterval(function()  {
				self.next();
				
			}, conf.interval);	
		}	
		
		if (conf.interval > 0) {			
			
			root.hover(function() {			
				clearInterval(timer);		
			}, function() {		
				setTimer();	
			});
			
			setTimer();	
		}
		
	} 

		
	// jQuery plugin implementation
	jQuery.prototype.scrollable = function(conf) { 
			
		// already constructed --> return API
		var api = this.eq(typeof conf == 'number' ? conf : 0).data("scrollable");
		if (api) { return api; }		
		
 
		var opts = {
			
			// basics
			size: 5,
			vertical:false,			
			clickable: true,
			loop: false,
			interval: 0,			
			speed: 400,
			keyboard: true,			
			
			// other
			activeClass:'active',
			disabledClass: 'disabled',
			hoverClass: null,			
			easing: 'swing',
			
			// navigational elements
			items: '.items',
			prev: '.prev',
			next: '.next',
			prevPage: '.prevPage',
			nextPage: '.nextPage',			
			navi: '.navi',
			naviItem: 'a',

			
			// callbacks
			onBeforeSeek: null,
			onSeek: null,
			alert: true
		}; 
		
		
		$.extend(opts, conf);		
		
		this.each(function() {			
			var el = new Scrollable($(this), opts);
			$(this).data("scrollable", el);	
		});
		
		return this; 
		
	};
			
	
})(jQuery);

$(document).ready(function() {

var menucount=loadtabs.length; var a = 0; var b = 1; do {easytabs(b, loadtabs[a]);  a++; b++;}while (b<=menucount);
if (autochangemenu!=0){start_autochange();}
});

$('a.sortdate').click(function(){  
		$("#g>div").tsort("span.date",{order:"desc"});
});  

$('a.sortmatch').click(function(){ 
		$("#g>div").tsort("span.match",{order:"asc"});
});

$('a.sortviews').click(function(){ 
		$("#g>div").tsort("span.views",{order:"desc"});
});

$('a.sorttipster').click(function(){ 
		$("#g>div").tsort("span.tipster",{order:"asc"});
});

$('a.sortstake').click(function(){ 
		$("#g>div").tsort("span.stake",{order:"desc"});
});

$('a.sortleague').click(function(){ 
		$("#g>div").tsort("span.league",{order:"asc"});
});

$('a.sortdate2').click(function(){  
		$("#f>div").tsort("span.date2",{order:"desc"});
});  

$('a.sortmatch2').click(function(){ 
		$("#f>div").tsort("span.match2",{order:"asc"});
});

$('a.sortviews2').click(function(){ 
		$("#f>div").tsort("span.views2",{order:"desc"});
});

$('a.sorttipster2').click(function(){ 
		$("#f>div").tsort("span.tipster2",{order:"asc"});
});

$('a.sortstake2').click(function(){ 
		$("#f>div").tsort("span.stake2",{order:"desc"});
});

$('a.sortleague2').click(function(){ 
		$("#f>div").tsort("span.league2",{order:"asc"});
});

$(document).ready(function() {
            $('#container img').animate({"opacity": .8 });

            $('#container img').hover(function() {
                $(this).stop().animate({ "opacity": 1 });
            }, function() {
                $(this).stop().animate({ "opacity": .8 });
            });
        });

$(document).ready(function() {	
	$("div.scrollable").scrollable({
		interval: 7000,
		clickable : false,
		loop: true, 
		speed: 600,
	    next: 'a.next', 
	    prev: 'a.prev'
	});
});
