/*
    Author:     Michael Hay - mhay[at]williamhill.co.uk
    Website:    williamhill.com
    Version:    1.0
    Date:       10/09/2008
    Built For:  MooTools 1.2
*/

//Global Variables
var serverDate = new Date(strServerTime*1000);
var version = navigator.appVersion;

//Firebug
if (!window.console || !console.firebug){
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {}
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}}

//William Hill Core
var whHelp = {
	root: function() {
		void(0);

		var temp = strHelpUrl.replace(/lang\.cfg/g, strHelpLang.replace(/-/g, "_")+'.cfg');
		window.open(temp.replace(/lang\.custhelp/g, strHelpLang+'.custhelp'), 'RightNow', 'width=664,height=440,scrollbars=yes');		
		//window.open(strHelpUrl.replace(/lang/g, strHelpLang), 'RightNow', 'width=664,height=440,scrollbars=yes');
	},
	load: function(metaID, anchor) {
		void(0);
		window.open('http://williamhill-' + strHelpLang + '.custhelp.com/cgi-bin/williamhill_' + strHelpLang.replace(/-/g, "_")+ '.cfg/php/enduser/std_alp.php?meta=' + metaID + '#' + anchor, 'RightNow', 'width=664,height=440,scrollbars=yes');
	},
	faq: function(metaID) {
		void(0);
		window.open('http://williamhill-' + strHelpLang + '.custhelp.com/cgi-bin/williamhill_' + strHelpLang.replace(/-/g, "_") + '.cfg/php/enduser/meta_faq.php?meta=' + metaID, 'RightNow', 'width=664,height=440,scrollbars=yes');
	},
	faq2: function(metaID) {
		void(0);
		window.open('http://williamhill-' + strHelpLang + '.custhelp.com/cgi-bin/williamhill_' + strHelpLang.replace(/-/g, "_") + '.cfg/php/enduser/std_adp.php?p_faqid=' + metaID, 'RightNow', 'width=664,height=440,scrollbars=yes');
	},
	contact: function() {
		void(0);
		switch(document.body.id){
	            case 'casino_site':
			productId = 4;
	            	break;
	            case 'poker_site':
	            	productId = 5;
	                break;
	            case 'vegas_site':
	            	productId = 739;
	                break;	                
	            default:
	                productId = '';
            	}
		window.open('http://williamhill-' + strHelpLang + '.custhelp.com/cgi-bin/williamhill_' + strHelpLang.replace(/-/g, "_") + '.cfg/php/enduser/ask.php?p_prods=' + productId, 'RightNow', 'width=664,height=440,scrollbars=yes');
	}	
};

function whShowHideDiv(id) {
	if (!document.getElementById(id)) {return;}
	element = document.getElementById(id);
	if (element.style.display=='block') {element.style.display='none';}
	else{element.style.display='block';};
}

// launch bingo product
function launchBingo(gameName, gameType) {
	if (!gameName || gameName=="") {gameName="Bingo";}
	if (!gameType) {gameType="";}
	var winName = gameName.replace(/ /g,"");
	new_window = window.open("https://"+strTargetPageDomain+"/"+strBetDomain+"/EN?action=DoGameLaunch&systemName=VirtueFusion&base_url=https://williamhill.virtuefusion.com/igames/play/game_page.do&lang=EN&source=BN&gameType="+gameName+"&gameType="+gameType,winName, "toolbar=no,width=800,height=550,resizable=yes,scrollbars=yes");
	whTrack.getEETag('bingo');
	new_window.focus();
}

// launch casino and poker downloads or instant plays
var whLaunch = {
	launchDownload: function(version) {
		whTrack.getTag('download');
		switch(document.body.id){
	            case 'casino_site':
			if (version=='usd') {target='http://72.52.5.229/xgcasino/WilliamHillUSDCasinoInstall.exe';}
			else {target='http://72.52.5.229/xpcasino/WilliamHillClassicCasinoInstall.exe';};
	            	break;
	            case 'poker_site':
	            	if (strLang!='en') {target='http://72.52.5.229/xppoker/WilliamHillPokerInstall_'+strLang+'.exe';}
	            	else {target='http://72.52.5.229/xppoker/WilliamHillPokerInstall.exe';}
	                break;
            	}
		$('modalPopupIframe').src = target;
		whLaunch.centre_element('modalPopup');
	},
	centre_element: function(element) {
		// position popup
		new Fx.Scroll(window).toTop();
		var winSize = window.getSize();
		console.log(parseInt($(element).getStyle('height')));
		$(element).setStyles({
		    left: ((winSize.x/2)-240),
		    top: ((winSize.y/2)-parseInt($(element).getStyle('height'))/1.5),
		    display: 'block'
		});
		$('modalDimmer').setStyles({
		    height: document.body.offsetHeight,
		    display: 'block'
		});
	},
	close: function() {
		$('modalPopup').setStyle('display', 'none');
		$('modalDimmer').setStyle('display', 'none');
	},
	launchInstant: function() {
		whTrack.getTag('instant');
		switch(document.body.id){
	            case 'casino_site': window.open('https://www.ifunds.com/XP/00/index.ehtml','instant','width=800,height=600,toolbar=no,status=yes,scrollbars=yes'); break;
	            case 'poker_site': window.open('https://ndpoker.wagerlogic.com/Poker/PokerFlex.html','instant','width=800,height=600,toolbar=no,status=yes,scrollbars=yes'); break;
            	}
	},
	getFile: function() {
		window.location = target;
	},
	launchPrompt: function() {
		// check for no_prompt cookie per site
		var cookieName = document.body.id+'_no_prompt';
		if (Cookie.read(cookieName)) {return;}
		whTrack.getTag('downloadPrompt');
		whLaunch.centre_element('modalPopup2');
	},
	acceptPrompt: function() {
		whTrack.getTag('downloadPrompt/Yes');
		whLaunch.dropPromptCookie();
		$('modalPopup2').setStyle('display', 'none');
		whLaunch.launchDownload();
	},
	cancelPrompt: function() {
		whTrack.getTag('downloadPrompt/No');
		whLaunch.dropPromptCookie();
		$('modalPopup2').setStyle('display', 'none');
		$('modalDimmer').setStyle('display', 'none');
	},
	dropPromptCookie: function() {
		var cookieName = document.body.id+'_no_prompt';
		Cookie.write(cookieName, '1', {duration: 30, path: '/'});
	}
};

var whTrack = {
	getCookie: function(c_name) {
		if (document.cookie.length > 0) {
			c_start = document.cookie.indexOf(c_name + "=");
			if (c_start != -1) {
				c_start = c_start + c_name.length + 1;
				c_end = document.cookie.indexOf(";", c_start);
				if (c_end == -1) c_end = document.cookie.length;
				return unescape(document.cookie.substring(c_start, c_end));
			}
		}
		return "";
	},
	getTag: function(strTag) {
		try{
			imgRedEye = new Image();
			var srcURL = strReGif+ "?nosubsite=" + strLang+ "&norefer=" + this.urlEncode(document.referrer) + "&nourl=www.willhill.com/" + strLang + "/" + strPageTag + "/" + strTag;
			if(strExistingUser != "1"){
			    srcURL += '&noscres='+screen.width+'x'+screen.height+'&amp;browser='+navigator.userAgent+'&amp;platform='+navigator.platform+'&amp;color='+screen.colorDepth+'&amp;flash='+flashinstalled+'/'+flashversion;
			}
			imgRedEye.src = srcURL;
			console.log(" - Fire Tag: " + srcURL );
		}catch(e){
			console.error("Tracking Error: " + e)
		}
	},
	getEETag: function(strTag) {
		imgEE = new Image();
		var srcURL = "http://www.williamhill.com/index.php/site/click_track/"+(Math.ceil(9999*Math.random()))+"?tag=" + strTag;
		imgEE.src = srcURL;
	},
	urlEncode: function(encodeHtml){
	     encodedHtml = escape(encodeHtml);
	     encodedHtml = encodedHtml.replace(/\//g,"%2F");
	     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
	     encodedHtml = encodedHtml.replace(/=/g,"%3D");
	     encodedHtml = encodedHtml.replace(/&/g,"%26");
	     encodedHtml = encodedHtml.replace(/@/g,"%40");
	     return encodedHtml;
	}
}

var Kwix = {
    start: function(){Kwix.parseKwicks();},
    parseKwicks: function(){
        var squeeze_to = 58;
        var max_height = 148;
        var start_heights = new Array();
        var slider = $$('#col_right_3step ul')

        slider.each(function(item, index){
            var items = item.getElements('li');
            var fx = new Fx.Elements(items, {wait: false, duration: 250, transition:Fx.Transitions.Cubic.easeOut});
            items.each(function(kwick, i){
                start_heights[i] = kwick.getStyle('height').toInt();
                kwick.addEvent('mouseenter', function(e){
                    var obj = {};
                    obj[i] = {
                        'height': [kwick.getStyle('height').toInt(), max_height]
                    };

                    var counter = 0;

                    items.each(function(other, j){
                        if (other != kwick){
                            var w = other.getStyle('height').toInt();
                            if (w != squeeze_to) obj[j] = {'height': [w,squeeze_to] };
                        }
                    });
                    fx.start(obj);
                });
            });
        });
    }
};

var tip = new Class({
    Implements: [Options],
    options: {
        elLock: document.body,
        tipDelay: 0,
        tipDuration: 60000,
        tipBounce: 10000,
        msg: ''
    },
    initialize: function(options) {
        var tip = new Element('div', {
            'class': 'tipContainer',
            'style': 'margin-top: 35px;',
            'html': '<div class="tipText">' + options.msg + '</div><div class="tipCap">&nbsp;</div>'
        });

        tip.setOpacity(0);
        tip.inject(document.body, 'top');
	
        var tipFx = new Fx.Morph(tip, {duration: 1000, transition: Fx.Transitions.Bounce.easeOut});
        this.setTipPosition(options.elLock, tip);
        window.addEvent('resize', function(){
        	setTipPosition(options.elLock, tip);
        });
        
        (function(){
            tipFx.start({
                'opacity': 1,
                'margin-top': 0
            });
            if(options.tipBounce > 0){
                var tipBounceStartFx = new Fx.Morph(tip, {duration: 250, transition: Fx.Transitions.Quad.easeInOut});
                var tipBounceEndFx = new Fx.Morph(tip, {duration: 1000, transition: Fx.Transitions.Bounce.easeOut});
                var bounceTmr = function(){
                    tipBounceStartFx.start({
                        'margin-top': [0 , 16]
                    }).chain(function(){
                    tipBounceEndFx.start({
                        'margin-top': [16 , 0]
                    })});
                }.periodical(options.tipBounce);
            };
            (function(){
                new Fx.Tween(tip).start('opacity', 0).chain(function(){
                    $clear(bounceTmr);
                    tip.destroy();
                })
            }).delay(options.tipDuration);
        }).delay(options.tipDelay);
    },
    setTipPosition: function(el, tip){
        var alignTo = $(el).getCoordinates();
        if(alignTo.left.toInt() + tip.getSize().x > 996){
            tip.setStyles({
                top: alignTo.top + alignTo.height + 7,
                left: (alignTo.left - tip.getSize().x) + alignTo.width,
                backgroundPosition: 'top right'
            });
        }else{
            tip.setStyles({
                top: alignTo.top + alignTo.height + 7,
                left: alignTo.left
            });
        }
    
    }
});


var SliderNav = new Class({
    //implements
    Implements: [Options],

    //options
    options: {
        scrollArea: '',
        scrollControl: '',
        autoScroll: true
    },
    
    //initialization
    initialize: function(options) {
        var scrollAreas = $$(options.scrollArea);
        var scrollControls = $$(options.scrollControl);
        
        var itemCount = [];
        var itemCurrent = [];
        var navCount = [];
        var navCurrent = [];
        var scrollView = [];
        var scrollOffset = [];
        var scrollFx = [];
        var scrollBusy = [];
        var duration = 600;

        scrollAreas.each(function(item, index){
            var scrollItems =  item.getElements('li');
            scrollBusy[index] = false;
            itemCount[index] = scrollItems.length;
            
            // Crossed out for further research
            //navCount[index] = scrollControls[index].getElements('li.dot').length;
            navCurrent[index] = 0;

            scrollView[index] = itemCurrent[index];
            scrollOffset[index] = scrollItems[0].getSize().x;

            scrollFx[index] = new Fx.Scroll(item, {
            	duration: 500,
                wheelStops : false,
                transition: Fx.Transitions.Quad.easeInOut
            });
        }); 
        
        scrollControls.each(function(navItems, conIndex){
        	var navLinks = navItems.getElements('li');
		navLinks .each(function(item, index){
			if(index == 0){updateDots(navItems, 0);}
			item.addEvent('click', function(event){
				event.stop();
				if(navLinks .length > 1){
					scrollMe(navItems, conIndex, index);
				}
			});
		});

        });
               
        function scrollMe(navItems, conIndex, index){
        	updateDots(navItems, index);
		scrollFx[conIndex].start((scrollOffset[conIndex]) * index+1, 0).chain(function(){
			navCurrent[conIndex] = index;
			scrollBusy[conIndex] = false;
		});
        }
        

        function updateDots(navItems, navCurrent){
            navItems.getElements('li.dot').each(function(item, index){
                if(index == navCurrent){item.addClass('on');}else{item.removeClass('on');}
            });
        }
    }
});

var winners = new Class({
    Implements: [Options],
    options: {
        table: ''
    },
    initialize: function(options) {
	var tables = $$(options.table)
		if(tables.length > 0){
			var dataRows = $$(options.table)[0].getElements('li.dataRow');
			(function(){
				dataRows.each(function(item, index){
				if(item.getElement('.seconds')){
					var secDom = item.getElement('.seconds');
					var endDate = new Date(item.getElement('.timestamp').innerHTML*1000)
					var endMins = Math.round((endDate - serverDate)/(60*1000));
					if (!secDom) {return;}
					if (endMins > 0){
						if(endMins == 1){
							secDom.innerHTML = "< " + endMins;
						}else{
							secDom.innerHTML = endMins;
						}
					}else{
						item.fade(.3);
						item.getElement('.playNow a').href = "javascript:;";
						item.getElement('.playNow a').setStyle('cursor', 'default');
						(function(){
							item.dispose();
							if(dataRows.length > index + 5){
								dataRows[index + 5].setStyle('display', 'block');
							}
						}).delay(30000)
					}
				}
				}); 
			}).periodical(30000);
		}
    }
});

var whMessaging = {
	init: function() {
	    var msgBar = $$('#contentCenter .headerBG .siteMessages');
	    if(msgBar.length > 0){
	    	if(!Cookie.read('msg_'+msgBar[0].id)){
	    	msgBar[0].setStyle('display', 'block');
		msgBar[0].getElement('#rightMessage a').addEvent('click', function(event){
			Cookie.write('msg_'+msgBar.id, true, {duration: 1, path: ''});
			msgBar[0].setStyle('display', 'none');
		});
		}
	    }
	}
};

var whLogin = {
	init: function() {
		if (strRequestScheme == "https") strLoginFormAction = "GetSslXLoginForm";
		else strLoginFormAction = "GetXLoginForm";
	    $('signinDetails').setStyle('display','none');
	    if(Cookie.read('cust_login') == "" || Cookie.read('cust_login') == null){
		console.log(' - Authenticated: N');
		    var loginBar = $('login');
		    if(loginBar.length > 0){
		    	$('password').addEvent('focus', function(event){
				//this.clone().set('value', '').setProperty('type','password').setProperty('id','password').injectAfter(this);
				//this.dispose();
				//$('password').focus();
			});
			$('user').addEvent('focus', function(event){
				//this.set('value', '');
			});
			$('login').addEvent('submit', function(e) {
				e.stop();
				$('signinLoader').setStyle('display','block');
	    	    		$('signinForm').setStyle('display','none');
	    	    		$('loadingMessage').innerHTML = "";
	    	    		var lgnForm = this;
				console.log(' - Login Request Sent');
				new Asset.javascript(strRequestScheme+'://'+strTargetPageDomain+'/'+strBetDomain+'/'+strLang.toUpperCase()+'?action='+strLoginFormAction+'&lang='+strLang+'&t=' + serverDate.getTime(), {
					onload: function(){
					    console.log(' - Response From Login Server - Auth: '+ WHX.authenticated);
				            	if(WHX.authenticated == 'N'){
							new Element('div',{html: WHX.data.obFormHidden}).inject(lgnForm ,'bottom');
							new Element('input', {type: 'hidden', name: 'target_page', value: strTargetPage}).inject(lgnForm , 'top');
							lgnForm.submit();
				            	}
					},
					onFailure: function(){
						console.log(' - Login Failed ');
					}
				});
			});
		    }
		    $('signinLoader').setStyle('display','none');
			$('signinForm').setStyle('display','block');
	    }else{
	    	$('signinLoader').setStyle('display','block');
	    	$('signinForm').setStyle('display','none');
		console.log(' - Auth Request Sent');
		new Asset.javascript(strRequestScheme+'://'+strTargetPageDomain+'/'+strBetDomain+'/'+strLang.toUpperCase()+'?action='+strLoginFormAction+'&lang='+strLang+'&t=' + serverDate.getTime(), {
			onload: function(){
		            console.log(' - Response From Login Server - Auth: '+ WHX.authenticated);
		            	if(WHX.authenticated == 'Y' && strPlayer == 'logged'){
							//$('obGreetingLabel').innerHTML = WHX.data.obGreetingLabel;
							$('obClientName').innerHTML = WHX.data.obClientName;
							//$('obAccountLabel').innerHTML = WHX.data.obAccountLabel;
							$('obAccountNumber').innerHTML = WHX.data.obAccountNumber;
							//$('obBalanceLabel').innerHTML = WHX.data.obBalanceLabel;
							//$('userBalance').innerHTML = WHX.data.obBalanceCurrency + WHX.data.obBalanceAmount;
							//$('obDepositLabel').innerHTML = WHX.data.obDepositLabel;
							//$('obMessageLabel').innerHTML = WHX.data.obMessageLabel;
							$('obMessageNumber').innerHTML = WHX.data.obMessageNumber;
							
							//$('obLogoutValue').innerHTML = WHX.data.obLogoutValue;
							$('signinLoader').setStyle('display','none');
							$('signinDetails').setStyle('display','block');
		            	}
			},
			onFailure: function(){
				console.log(' - Login Failed ');
			}
		});
	    }
	},
	showSimple: function() {
		$('signinLoader').setStyle('display','none');
		$('signinError').setStyle('display','block');
	},
	getBalance: function() {
		var request = new Request({
			url: 'https://games.williamhill.com/getBalance/',
			onComplete: function(jsonObj) {
				var loginObj = JSON.decode(jsonObj);
				if(loginObj.result == 'OK'){
					$('userBalance').innerHTML = loginObj.amount;
				}else{
					$('userBalance').innerHTML = 'Error';
				}
			}
		}).send();
	},
	logOut: function(outDest) {
		//if(strLang != 'en'){outDest += strLang + '/index/';}
		window.location = 'http://'+strTargetPageDomain+'/'+strBetDomain+'/'+strLang.toUpperCase()+'?action=DoLogout&target_page=' + whTrack.urlEncode(outDest + "?t=" + serverDate.getTime());
	}
};

//Product Specific
var whAnnouncementScroll = {
	items:[],
	selected:0,
	init: function() {
		if($chk('#contentHeadText')){
			$$('#contentHeadText li').each(function(item, index){
				whAnnouncementScroll.items.push(item);
				item.style.display='none';
			})
			switch(whAnnouncementScroll.items.length){
				case 0: 
					return;
					break;
				case 1: 
					whAnnouncementScroll.items[0].style.display = 'block';
					break;
				default:
					whAnnouncementScroll.nextItem();
					break;
			}
		}
	},
	nextItem: function() {
		var t = 1000; 	// ms
		var d = 100; 	//px
		var pause = 4;
		var element = whAnnouncementScroll.items[whAnnouncementScroll.selected];
		element.setOpacity(0);
		element.style.display = 'block';
		var myFx = new Fx.Morph(element,{duration:t,transition: Fx.Transitions.Quad.easeOut});
		myFx.start({
			'opacity': [0, 1],
			'margin-left':[d, 0]
		}).chain(
			// set time to wait until the item is faded out
			function(){
				(function() {
					myFx.start({
						'opacity': [1, 0],
						'margin-left':[0, -1*d]
					});	
				}).delay(t*pause);
			},
			// begin the next item
			function(){
				element.style.display = 'none';
				whAnnouncementScroll.selected++;
				if (whAnnouncementScroll.selected == whAnnouncementScroll.items.length) { whAnnouncementScroll.selected = 0; }
				whAnnouncementScroll.nextItem();
			}			
		);
	}
}

//Product Specific for IE6
var whAnnouncementScrollIE6 = {
	items:[],
	selected:0,
	init: function() {
		if($chk('#contentHeadText')){
			$$('#contentHeadText li').each(function(item, index){
				whAnnouncementScrollIE6.items.push(item);
				item.style.display='none';
			})
			switch(whAnnouncementScrollIE6.items.length){
				case 0: 
					return;
					break;
				case 1: 
					whAnnouncementScrollIE6.items[0].style.display = 'block';
					break;
				default:
					whAnnouncementScrollIE6.nextItem();
					break;
			}
		}
	},
	nextItem: function() {
		var t = 1000; 	// ms
		var d = 100; 	//px
		var pause = 4;
		var element = whAnnouncementScrollIE6.items[whAnnouncementScrollIE6.selected];
		element.setOpacity(0);
		element.style.display = 'block';
		var myFx = new Fx.Morph(element,{duration:t,transition: Fx.Transitions.linear});
		myFx.start({
			'opacity': [0, 1]
		}).chain(
			// set time to wait until the item is faded out
			function(){
				(function() {
					myFx.start({
						'opacity': [1, 0]
					});	
				}).delay(t*pause);
			},
			// begin the next item
			function(){
				element.style.display = 'none';
				whAnnouncementScrollIE6.selected++;
				if (whAnnouncementScrollIE6.selected == whAnnouncementScrollIE6.items.length) { whAnnouncementScrollIE6.selected = 0; }
				whAnnouncementScrollIE6.nextItem();
			}			
		);
	}
}

var gameNav = {
	init: new Class({
	    initialize: function(options) {
	    if($chk('#productsContainer')){
		var cats = [];
		$$('#category li a').each(function(item, index){
			if(index == 0){item.addClass('sel');}
			cats.push(item.id);
			item.addEvent('click', function(event){
				event.stop();
				var sel = this.id;
				cats.each(function(cat, index){
					if(sel == cat){
						$(cat).addClass('sel');
						$(cat.substring(4)).setStyle('display', 'block');
						$$('#' + cat.substring(4) + ' li').each(function(game, index){
						    game.setStyle('display', 'none');
						    (function(){
						    	var myFx = new Fx.Tween(game);
						    	myFx.set('opacity', 0);
						    	game.setStyle('display', 'block');
					                myFx.start('opacity', 1);
					            }).delay(index*100);
						});
					}else{
						$(cat).removeClass('sel');
						$(cat.substring(4)).setStyle('display', 'none');
					}
				}); 
				
			});
		}); 
	    }}
	}),
	load: function(strGameCode, type) {
		void(0);
		var gamePath = ""
		var strLangUp = strLang.toUpperCase();
		switch(strLang){
			case 'el': langLong = 'Greek'; break;
			case 'en': langLong = 'English'; break;
			case 'es': langLong = 'Spanish'; break;
			case 'fr': langLong = 'French'; break;
			case 'zh': langLong = 'Chinese'; break;
			case 'de': langLong = 'German'; break;
			case 'tr': langLong = 'Turkish'; break;
			case 'it': langLong = 'Italian'; break;
		}
		
		switch(strGameCode){
		   //Games
			case 'QW': gamePath = 'quick_bet_wheel/quick_bet_wheel_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'QC': gamePath = 'quick_bet_cards/quickbet_cards_54_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'QD': gamePath = 'quick_bet_darts/gameloader.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'HL': gamePath = 'quick_bet_hilo_cards/gameloader.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'QT': gamePath = 'quick_bet_triple_hi_lo/quick_bet_triple_hi_lo_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'QH': gamePath = 'quick_bet_hexagons/quick_bet_hexagons_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'BR': gamePath = 'bagatelle_roulette/bagatelle_roulette_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'PT': gamePath = 'quick_bet_poker/quick_bet_poker_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'FW': gamePath = 'final_score_worldCup/finalscore_worldcup_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'HP': gamePath = 'poker_holdem/poker_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'RO': gamePath = 'quick_bet_roulette/roulette_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'KE': gamePath = 'quick_bet_keno/keno_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'KI': gamePath = 'quick_bet_keno/keno_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'FS': gamePath = 'finalscore_multi-league/finalscore_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'QF': gamePath = 'quick_bet_final_score/gameloader.asp&gameCode='+'FS'+strLangUp+'&'; break;
			case 'GO': gamePath = 'quick_bet_golf/golf_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'RE': gamePath = 'viva_las_vegas/vegas_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'QS': gamePath = 'quick_bet_spoof/quickbet_spoof_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'VD': gamePath = 'virtual_dogs/virtual_dogs_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'KA': gamePath = 'KingArthur/king_arthur_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'TS': gamePath = 'TopOfTheSlots/top_slots_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'BJ': gamePath = 'SuperBlackJack/gameloader.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'RF': gamePath = 'RichAndFamous/rich_and_famous_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'AW': gamePath = 'AroundTheWorld/around_the_world_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'VH': gamePath = 'virtual_horses/virtual_horses_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'WF': gamePath = 'WhaleOfFortune/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'ZZ': gamePath = 'ZodiacZillions/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'HD': gamePath = 'HouseOfDragons/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
		    //Vegas
			case 'B1': gamePath = 'BlackJack/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case '3P': gamePath = '3_card_brag/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'JP': gamePath = 'JokerPoker/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'JB': gamePath = 'Jacks_or_Better_multihand/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'R2': gamePath = '3DRoulette/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'CW': gamePath = 'BeatTheDealer/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'CS': gamePath = 'CasinoPoker/game_load.asp&gameCode=CS'+strLangUp+'&'; break;
			case 'PO': gamePath = 'PharaohsTreasure/game_load.asp&gameCode=PO'+strLangUp+'&'; break;
			case 'GR': gamePath = 'GoldRush/game_load.asp&gameCode=GR'+strLangUp+'&'; break;
			case 'GG': gamePath = 'GoForGold/game_load.asp&gameCode=GG'+strLangUp+'&'; break;
			case 'LR': gamePath = 'KeepEmGoing/game_load.asp&gameCode=LR'+strLangUp+'&'; break;
			case 'JA': gamePath = 'JewelsOfAtlantis/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'FM': gamePath = 'FruitMadness/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'CC': gamePath = 'CoffinUpTheCash/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'VS': gamePath = 'VegasSolitaire/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'AZ': gamePath = 'AmazonWild/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;	
			case 'SB': gamePath = 'Slotris/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'HU': gamePath = 'HeadsUpPoker/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'BA': gamePath = 'LightningBalls/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'L8': gamePath = 'Lucky8/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'TM': gamePath = 'TimeMachine/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;
			case 'GJ': gamePath = 'GinJointJackpot/game_load.asp&gameCode='+strGameCode+strLangUp+'&'; break;		
		    //Default
		        default: gamePath = '3DRoulette/game_load.asp&gameCode=R2'+strLang+'&'; break;
		}
		var new_window;
		if (new_window != null && !new_window.closed) {new_window.focus();}else{
		    switch(type){
	                case 'LD':
	                    whTrack.getTag(strGameCode+'/live');
		            new_window = window.open("https://"+strTargetPageDomain+"/"+strBetDomain+"/" +strLang+ "?action=DoGameLaunch&systemName=Evolution&base_url=https://willhill.evolutiongaming.com/cgibin/UserAuthentication&lang=" +strLang+ "&source=VA&gameCode=" + strGameCode ,"", "toolbar=no,width=800,height=550,resizable=yes");
		            break;
		        case 'RP':
		            whTrack.getTag(strGameCode+'/real');
		            switch(document.body.id){
        			case 'vegas_site': new_window = window.open("https://"+strTargetPageDomain+"/"+strBetDomain+"/" +strLang+ "?action=DoGameLaunch&systemName=Vegas&base_url=http://vegas-gs.williamhill.com/FOB/"+langLong+"/"+ gamePath + "lang=" +strLang + "&source=VA" ,"", "toolbar=no,width=800,height=550,resizable=yes"); break;
		                case 'games_site': new_window = window.open("https://"+strTargetPageDomain+"/"+strBetDomain+"/" +strLang+ "?action=DoGameLaunch&systemName=Games&base_url=http://games-gs.williamhill.com/FOB/"+langLong+"/"+ gamePath + "lang=" +strLang + "&source=GM","", "toolbar=no,width=800,height=550,resizable=yes"); break;
		            }
			    break;		
			case 'FP':
		            whTrack.getTag(strGameCode+'/demo');
		            switch(document.body.id){
        			case 'vegas_site': new_window = window.open("http://demo.williamhill.com/"+strLang+"/FOBredirectFun.asp?gamecode=" + strGameCode + "&product=" + productCode + "&source=VA", "", "toolbar=no,width=800,height=550,resizable=yes"); break;
		                case 'games_site': new_window = window.open("http://demo.williamhill.com/"+strLang+"/FOBredirectFun.asp?gamecode=" + strGameCode + "&product=" + productCode + "&source=GM", "", "toolbar=no,width=800,height=550,resizable=yes"); break;
		            }
		            break; 
		    }
		}
	}
};

//Lock & Load!
window.addEvent('domready', function() {
    //Start Server Clock
    console.log('William Hill Core v 1.1');
    console.log(' - Server Compile Time: ' + strCompileTime);
    console.log(' - Server Query Count: ' + strQueries);
    console.time('Execute Time');
    
    //Initialise Common Functions
    (function(){
	serverDate.setTime(serverDate.getTime() + 1000);
	//$('serverClock').innerHTML = (serverDate.toTimeString().split(' ')[0] + " UK");
    }).periodical(1000);
    
    //Initialise Site Specific Functions
    if(Browser.Engine.trident4){
	$$('.headerBG li').each(function(item, index){
	    item.onmouseover=function() {
		this.className+=" sfhover";
	    }
	    item.onmouseout=function() {
		this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
	    }
	});
    }

    //Detect Page
    switch(document.body.id){
        case 'root_site':
            Kwix.start();
            break;
        case 'bingo_site':
            whLogin.init();
            new SliderNav({
                scrollArea: '.scrollContent',
                scrollControl: '.scrollControl'
            });
	    new winners({
                table: '.scheduleTable'
            });
            break;
        case 'news_site':
            //whLogin.showSimple();
            whLogin.init();
            break;
        case 'vegas_site':
            whLogin.init();
            productCode = "VA";
            new gameNav.init();
            new SliderNav({
                scrollArea: '.scrollContent',
                scrollControl: '.scrollControl'
            });
            new whAnnouncementScroll.init();
            break;
        case 'games_site':
            whLogin.init();
            productCode = "GA";
            new gameNav.init();
            new SliderNav({
                scrollArea: '.scrollContent',
                scrollControl: '.scrollControl'
            });
            new whAnnouncementScroll.init();
            break;
        case 'casino_site':
            whLogin.init();
            productCode = "CA";
            new SliderNav({
                scrollArea: '.scrollContent',
                scrollControl: '.scrollControl'
            });
            whLaunch.launchPrompt();
            break;
        case 'poker_site':
            whLogin.init();
            productCode = "PK";
            new SliderNav({
                scrollArea: '.scrollContent',
                scrollControl: '.scrollControl'
            });
            whLaunch.launchPrompt();
            break;    
        case 'affiliate_site':
            whLogin.showSimple();
            Kwix.start();
            break;   
        case 'skill_site':
            whLogin.init();
            new SliderNav({
	            scrollArea: '.scrollContent',
	            scrollControl: '.scrollControl'
            });
            break;               
        default:
            //Default;
            break;
    }
       
    //All Pages
    //var helpTip = new tip({
    //    elLock: 'helpLink',
    //    tipDelay: 2000,
    //    tipDuration: 60000,
    //    tipBounce: 5000,
    //	msg: '<b>Need Assistance?</b> - Try our Help Centre.'
    //});
          
    whTrack.getTag('&statCompile=' + strCompileTime + '&statQueries=' + strQueries);
    whMessaging.init();
    
    console.timeEnd('Execute Time')
});

function lang_change(value) {
	document.cookie = "cust_lang=" + value + ";domain=" + strTargetCookieDomain + ";path=/;";
	//alert(getCookie('cust_lang'));
	//Cookie.write("cust_lang", value, {duration: 30, domain: strTargetCookieDomain, path: '/'});
}
// function for floating window promotions page

 	//window.addEvent('domready', function(event) {window.addEvent('scroll', function(ev) { var offset = $(document).getScrollTop();  $('floatMenu').tween('top', offset + 'px');  });});