//***** SKY SPORTS PRE-LOAD SCRIPT  : V1.02 11:14 17 June 2010 *****//

//***** JQUERY EXTENSIONS (ONLY SMALL GLOBAL EXTENSIONS TO JQUERY GO HERE, EVERYTHING ELSE USE THE PLUGIN ARCHITECTURE *****

	//multiple script loader (for loading plugins)
	/**
		 * Script loader plugin 1.2.1 - http://code.google.com/p/jquery-loadscript/
		 *
		 * Copyright (c) 2009 Filatov Dmitry (alpha@zforms.ru)
		 * Dual licensed under the MIT and GPL licenses:
		 * http://www.opensource.org/licenses/mit-license.php
		 * http://www.gnu.org/licenses/gpl.html
		 *
	 */

(function($){var scripts=[];function loadScript(url,callback,context){if(url.match(/undefined/)){url=""};var script=scripts[url]||(scripts[url]={loaded:false,callbacks:[]});if(script.loaded){return callback.apply(context)}script.callbacks.push({fn:callback,context:context});if(script.callbacks.length==1){$.ajax({type:'GET',url:url,dataType:'script',async:false,cache:true,complete:function(xhr){script.loaded=true;$.each(script.callbacks,function(){this.fn.apply(this.context)});script.callbacks.length=0}})}}$.getScripts=function(url,callback,context,options){if(typeof options==='undefined'&&context&&context.hasOwnProperty('parallel')){options=context;context=window}options=$.extend({parallel:true},options);if(!$.isArray(url)){return loadScript(url,callback,context)}var counter=0;if(options.parallel){return $.each(url,function(){loadScript(this,function(){if(++counter==url.length){callback.apply(context)}})})}(function(){if(counter==url.length){return callback.apply(context)}loadScript(url[counter++],arguments.callee)})()};$.getScripts.registerLoaded=function(url){$.each($.makeArray(url),function(){(scripts[url]||(scripts[url]={})).loaded=true})}})(jQuery);


//throttle and debounce - stops multiple event calls
/**
 * jQuery throttle / debounce - v1.1 - 3/7/2010
 * http://benalman.com/projects/jquery-throttle-debounce-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 **/
(function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this);


//adds new selectors for finding elements in the viewport
/**
 * Viewport - jQuery selectors for finding elements in viewport
 *
 * Copyright (c) 2008-2009 Mika Tuupola
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Project home:
 *  http://www.appelsiini.net/projects/viewport
 *
 **/
 
(function($){$.belowthefold=function(element,settings){var fold=$(window).height()+$(window).scrollTop();return fold<=$(element).offset().top-settings.threshold};$.abovethetop=function(element,settings){var top=$(window).scrollTop();return top>=$(element).offset().top+$(element).height()-settings.threshold};$.rightofscreen=function(element,settings){var fold=$(window).width()+$(window).scrollLeft();return fold<=$(element).offset().left-settings.threshold};$.leftofscreen=function(element,settings){var left=$(window).scrollLeft();return left>=$(element).offset().left+$(element).width()-settings.threshold};$.inviewport=function(element,settings){var $element=$(element);var offset=$element.offset();var $window=$(window);var windowTop=$window.scrollTop();var threshold=settings.threshold;if(offset.top-threshold<windowTop){if(offset.top+$element.height()+threshold>=windowTop){}else{return false}}else{if(offset.top-threshold<=windowTop+$window.height()){}else{return false}}var windowLeft=$window.scrollLeft();if(offset.left-threshold<windowLeft){if(offset.left+$element.width()+threshold>=windowLeft){}else{return false}}else{if(offset.left-threshold<=windowLeft+$window.width()){}else{return false}}return true};$.extend($.expr[':'],{"below-the-fold":function(a,i,m){return $.belowthefold(a,{threshold:0})},"above-the-top":function(a,i,m){return $.abovethetop(a,{threshold:0})},"left-of-screen":function(a,i,m){return $.leftofscreen(a,{threshold:0})},"right-of-screen":function(a,i,m){return $.rightofscreen(a,{threshold:0})},"in-viewport":function(a,i,m){return $.inviewport(a,{threshold:0})}})})(jQuery);


// JSON parse and stringify
;(function($){var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},s={'array':function(x){var a=['['],b,f,i,l=x.length,v;for(i=0;i<l;i+=1){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=','}a[a.length]=v;b=true}}}a[a.length]=']';return a.join('')},'boolean':function(x){return String(x)},'null':function(x){return"null"},'number':function(x){return isFinite(x)?String(x):'null'},'object':function(x){if(x){if(x instanceof Array){return s.array(x)}var a=['{'],b,f,i,v;for(i in x){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=','}a.push(s.string(i),':',v);b=true}}}a[a.length]='}';return a.join('')}return'null'},'string':function(x){if(/["\\\x00-\x1f]/.test(x)){x=x.replace(/([\x00-\x1f\\"])/g,function(a,b){var c=m[b];if(c){return c}c=b.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16)})}return'"'+x+'"'}};$.toJSON=function(v){var f=isNaN(v)?s[typeof v]:s['number'];if(f)return f(v)};$.evalJSON=function(v,safe){if(safe===undefined)safe=$.evalJSON.safe;if(safe&&!/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))return undefined;return eval('('+v+')')};$.evalJSON.safe=false})(jQuery);

/** Special event for image load events Needed because some browsers does not trigger the event on cached images.
MIT License
 Paul Irish     | @paul_irish | www.paulirish.com
 Andree Hansson | @peolanha   | www.andreehansson.se
 2010.
**/
(function($){$.event.special.load={add:function(hollaback){if(this.nodeType===1&&this.tagName.toLowerCase()==='img'&&this.src!==''){if(this.complete||this.readyState===4){hollaback.handler.apply(this)}else if(this.readyState==='uninitialized'&&this.src.indexOf('data:')===0){$(this).trigger('error')}else{$(this).bind('load',hollaback.handler)}}}}}(jQuery));

// add reverse to jquery object
jQuery.fn.reverse=function(){return this.pushStack(this.get().reverse(), arguments);};

//***** JAVASCRIPT CSS  (USE THIS TO STYLE ELEMENTS TO HIDE THE DELAY IN JAVASCRIPT BEEN APPLIED *****
document.write("<style type=text/css> .js-inv{visibility:hidden} .js-hdn,.tabs-hide{display:none} div.ms-select ul {z-index:20001;display:none;position:absolute;min-height:80px;max-height:200px;_height:200px;} * object{display:inline!important} .js-preload .carousel-hero-holder, .js-preload .carousel-list-holder {visibility:hidden}</style>");

if(navigator.userAgent.match(/Safari/g) && !navigator.userAgent.match(/chrome/g)){document.write("<style type=text/css>body button.v5-btn-t2 div,body button.v5-btn-t1 div{margin-right:2px!important}</style>")}

if(navigator.userAgent.match(/iP/g)){document.write("<style type=text/css>body button.v5-btn-t2 div,body button.v5-btn-t1 div{margin-right:-5px!important}.v5-form-textarea{min-height:160px}</style>")}

//BASE FUNCTIONS OBJECT
var bskyb = {}


//LETS SET UP SOME GLOBAL FUNCTIONS THAT NEED TO BE AVAILABLE BEFORE PAGE LOAD

	//cookies
	bskyb.cookie = {

		get:function(name){
			
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			
			return null;

		},
		
		set:function(name,value,days,domain){
			
			if (days && days!=""){
			
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
				
			}
			else expires = "";
			
			var d = "domain=";
			if(!domain || domain==" ") {d = " "};
			
		
			document.cookie = name+"="+value+expires+";"+d+domain+"; path=/" ;
		
		},
		
		
		kill:function(){
		
		
		
		}

	}
	//backwards compatibility with old code
	window.getCookie = bskyb.cookie.get,window.setCookie = bskyb.cookie.set;
	
	
	//styleswitcher
	bskyb.styleswitcher = function(p){
	
		
	}
	
	//popups: <a href='link' rel='popup|w|h|(0 or 1 for scrollbars)'> or <a href='link' rel='live'> for scorecentre
	($(function(){$("a[rel='live'],a[rel^='pop']").live('click',function(){var rn=Math.floor(Math.random()*1111111);var p=$(this).attr('rel').split("|"),b,h,w,s,t,l,r,ty;switch(p[0].toLowerCase()){case'live':w=1018,h=680,t=((screen.height-680)/2),l=((screen.width-1018)/2),s='0',r='yes',ty='fullWindow',b=screen.height<770?'yes':'no';break;case'popup':w=p[1],h=p[2],s=p[3]||'1',b='no',r='yes',t=((screen.height-p[2])/2),l=((screen.width-p[1])/2);break}window.open(this.href,rn,"width="+w+",height="+h+",top="+t+",left="+l+",type="+ty+",resizable="+r+",scrollbars="+s+",channelmode="+b);return false})}))
	
		
		
	//some utilities
	bskyb.util = {
		checkFunc:function(f,c){
		
			if(f){return c('done')}
			
			else{
				window.checkF = setInterval(function(f){
					
					if(f){clearInterval(window.checkF);return c('done');}
					
				},300);
			}
		
		},
		ordinal:function(n) {
			var sfx = ["th","st","nd","rd"];
			var val = n%100;
			return n + (sfx[(val-20)%10] || sfx[val] || sfx[0]);
		}
		,
		//check for flash versions
		hasFlash:function(){
			var isInstalled = false;
			var version = null;
			if (window.ActiveXObject) {
				var control = null;
					try {
						control = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
						
					} catch (e) {
						version=0
						
				
				}
				
					if (control) {
						isInstalled = true;
						version = control.GetVariable('$version').substring(4);
						version = version.split(',');
						version = parseFloat(version[0] + '.' + version[1]);
						
					}

					
			} 
			
			else {
				if(navigator.plugins['Shockwave Flash']){
					version = navigator.plugins['Shockwave Flash'].description;
					version = version.split('.')[0];
					version = parseInt(version.split('Flash ')[1]);
				}
				
				else{version=0}
				
			}
			
			return version;
		},
		
		getquery:function(p){
		
			var q = window.location.search.substring(1);
			q = q.replace('&amp;','&');
			
			var v = q.split("&");
		
			for(var i=0;i<v.length;i++){

				var pair = v[i].split("=");
				return (pair[0] == p) ? pair[1]:false
				
			}
			
		},
		
		getoptions:function(p){
			
			var r = p.def || 'false';
						
				if(p.opts && p.opts.length>1){
							
					var o = p.opts.split("&");
					$(o).each(function(i){ o[i].split('=')[0]==p.val && (r = o[i].split('=')[1]) })
							
				}
				
			return p.parse ? parseInt(r) : r;				
		

		},
		
		getStyleProperty:function(propName, element) {
			
			var prefixes = ['Moz', 'Webkit', 'Khtml', 'O', 'Ms'];
			
			element = element || document.documentElement;
			
			var style = element.style, prefixed;
			
			if (typeof style[propName] == "string") {
				return propName;
			}
			
			propName = propName.charAt(0).toUpperCase() + propName.slice(1);
			
			 for (var i=0, l=prefixes.length; i<l; i++) {

			prefixed = prefixes[i] + propName;
				
				if (typeof style[prefixed] == "string") {
				
					return prefixed;
					
				}
			}
		},
		
		debug:function(p){
			
			if(location.href.match('demodesign2')){
			
				if(window.console){
				
					console.log(p);
				}
				
				else {
				
					alert(p);	
				}
				
			}
		}
		

	};
	
	//backwards compatibility with old code
	window.getquery = bskyb.util.getquery;
	
	
	//advertising dropdown functions
	bskyb.ads = {
		
		init:function(p,c,id){
			if(bskyb.util.hasFlash() == 0) {return false};
			bskyb.ads.el = id || $('#base-ad-leaderboard')[0] || $('#ss-ad-sponsor-expand')[0];
			bskyb.ads.f = $('#connect-sponsorAd1')[0] || 0;
			!c && (c='dropDownSponsor');
			!p && (p=8);
			p = p*1000;
		
			if(bskyb.cookie.get(c)!='false'){
				
				$(bskyb.ads.el).animate({height:308,opacity:100},250,function(){
				
					bskyb.ads.f!=0 && bskyb.ads.f.GotoFrame('2');
					setTimeout(function(){bskyb.ads.f!=0 && bskyb.ads.f.GotoFrame('3') | $(bskyb.ads.el).animate({height: 115, opacity: 100}, 300)},p);
					bskyb.cookie.set(c,'false');
			
				})
				
			}
		},
		
		open:function(){$(bskyb.ads.el).animate({height: 308, opacity: 100}, 300)},
		close:function(){$(bskyb.ads.el).animate({height: 115, opacity: 100}, 300)}
	}
	//backwards compatibility with old code
	window.initSponsor = bskyb.ads.init,window.openSponsor = bskyb.ads.open,window.closeSponsor = bskyb.ads.close;
	

	//some browser specific stuff
	(function(p){
		if(p.msie){
			//stop flickering backgrounds
			document.execCommand("BackgroundImageCache", false, true);
		}
	})($.browser);
	
	
	
//*****MOST STUFF BELOW IS BACKWARDS COMPITIBILTY WITH OLD CODE*****//
	var segQS;
	//bind navigation functions as soon as available
	navBuild = function(){
	
		$.getScripts(window.scriptpath+'bskyb.nav.js',function(){});
		
		$('div.ms-select-t2').addClass('select-ul-t2');
		
		$('div.ms-select').live('mouseenter mouseleave',function(e){
			
			if(e.type=='mouseover'){
			
				$(this).click(function(){ $(this).children('ul').show()})
			
			}
			
			else {
			
				$(this).children('ul').hide()
			
				}
			}
			
		)
	
	};
	
	//validation aide form forms
	jQuery.fn.validationAideEnable = function(){
		var form = $(this);
		$.getScripts(window.scriptpath+'validationaide.js',function(){
		
			form.validationAideEnable();
		
		});
	}
	
	
	
//global script variables
	var basescriptpath = document.getElementById("base-script");
	basescriptpath ? eval(basescriptpath.innerHTML) : window.scriptpath = "/scripts/";
	
	

