function getParamFromUrl(name) {
	var re = new RegExp("(?:\\?|\\&)"+name+"=([^\\&]*)");
	var match = document.location.search.match(re);
	return (match != null) ? match[1] : "";
}

var Flag = {
	init:function() {
		Flag.raw = getParamFromUrl("f");
		Flag.values = Flag.raw.split("");
	},
	dict:["nxs", "popunder", "vsp", "ab"],
	get:function(name) {
		for (var i=0,ii=Flag.dict.length;i<ii;i++) {
			if (Flag.dict[i] == name) {
				return (Flag.values[i] && Flag.values[i] == "1") ? true : false;
			}
		}
		return null;
	}
}
Flag.init();

function _addjs(u) {
    if (navigator.appName.indexOf("Microsoft") == 0 && d) document.write("<scr" + "ipt defer='defer' async='true' src='" + u + "'></scr" + "ipt>");
    else {
	var s = document.createElement('script');
	s.type = 'text/javascript';
	s.async = true;
	s.src = u;
	(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(s);
    }
}

var bannerserverlink = (typeof(CONSTANTS.bannerserver) != "undefined" && CONSTANTS.bannerserver != "") ? CONSTANTS.bannerserver : "http://banner2.casino.com";

function gotourl(url) {
	isLink = true;
	document.location.href = url;
}
function $(name) { return document.getElementById(name); };
if (window.addEventListener) {
	window.addEventListener("load", updateDateSpan, false);
} else {
	window.attachEvent("onload", updateDateSpan);	
}
var agt = navigator.userAgent.toLowerCase();
function changelanguage(lang) {
	savecookie('language', lang, 1000);
}
function addLeadingZero(value) {
    if (value < 10) {
        return '0' + value;
    } else {
        return value;
    }
}
function getAMPM(value) {
    return (value >= 12) ? "PM" : "AM";
}
function cutHoursToAMPM(value) {
    return (value == 12 || value == 0) ? 12 : value % 12;
}
function updateDateSpan() {
    var dateSpan = $('dateContainer');
    if (dateSpan) {
        var date = new Date();
        dateSpan.innerHTML = Days[date.getUTCDay()] + ", " +
                             Months[date.getUTCMonth()] + " " +
                             addLeadingZero(date.getUTCDate()) + ", " +
                             addLeadingZero(date.getUTCFullYear()) + " - " +
                             cutHoursToAMPM(date.getUTCHours()) + ":" +
                             addLeadingZero(date.getUTCMinutes()) + " " + getAMPM(date.getUTCHours()) + " GMT";
    }
	//showpopup();    
	if ($("navigation")) tabdropdown.init("navigation", -1);
    setTimeout("updateDateSpan();", 10000);
}
function handleStartedSteps(step) {
	if ($('startedStep'+step).style.display == 'none') {
		$('startedStepImage'+step).src = 'http://images.casino.com/images/sarrowdown.gif';
		$('startedStep'+step).style.display = '';
	} else {
		$('startedStepImage'+step).src = 'http://images.casino.com/images/sarrowright.gif';
		$('startedStep'+step).style.display = 'none';
	}
}
var emerpcomp = null;
var counter = 0;
var userGuid = "";
document.EMERPCallbacks = [];
function EMERPCallback(comp, eventName) {
	emerpcomp = comp;
	userGuid = comp.GetUserID();
	document.shouldsendhphit = doubletracking();
	if (document.location.search.match(/[&\?]p=1/)) {
		document.shouldsendhphit = false;
		document.sshhwd = true;
	} else {
		document.sshhwd = false;
	}
	if (typeof(document.EMERPAdditionalCallback) != "undefined") document.EMERPAdditionalCallback(comp, eventName);
	else if (eventName == "DummyEvent") {
		if (typeof(document.shouldsendhphit) != "undfined" && document.shouldsendhphit) emerpcomp.SendEvent("", "?hphit", "cp");
	}
    	if (typeof(document.EMERPCallbacks) != "undefined" && typeof(document.EMERPCallbacks.length) != "undefined") {
        	for (var i=0,ii=document.EMERPCallbacks.length;i<ii;i++) {
            		document.EMERPCallbacks[i](comp, eventName);
        	}
    	}
	if (typeof(document.EMERPToUrchin) != "undefined") document.EMERPToUrchin(comp, eventName);
}
function getDownloadLink() {
	var pixel = (emerpcomp != null) ? emerpcomp.GetPixelID() : "";
	var dp = (emerpcomp != null) ? emerpcomp.GetDPID() : "";
	var downloadUrl = bannerserverlink+"/cgi-bin/SetupCasino.exe?creferer=UserGUID:"+userGuid+";pixelid:;dp:";
	return downloadUrl;
}
function findlanguage() {
	var language = "en";
	var m = null;
	if (document.location.href.match(/www\.casino\.com/)) m = document.location.href.match(/http:\/\/www.casino.com\/([a-z]{2})\/.*/);
	else m = document.location.href.match(/http:\/\/([^\.]*)\.casino\.com/);
	if (m != null) language = m[1];
	return language;
}

function getpropertybag() {
	var rs = [];
	if (readcookie("b") != null) rs.push("proposition:"+readcookie("b"));
	if (currentsrc != "") rs.push("DL:"+currentsrc);
	return rs.join(";");
}

function trackdownload(flash) {
	try { if (readcookie("_km") == "1" && userGuid != "") _kmq.push(['identify', userGuid]); savecookie("_km", "2", 1000);} catch (e) { }
    	try { _kmq.push(['record', (flash?'Flash':'Client')+' Download Attempt', {language:findlanguage()}]);} catch (e) {}
	try { _kmq.push(['record', 'Download Attempt', {language:findlanguage(), Type:(flash?'Flash':'Client')}]);} catch (e) {}
	var script = document.createElement("script");
	script.src = "http://stat.casino.com/stats/track.php?r="+escape(document.referrer)+((flash) ? "&__f=true" : "")+"&__d=true&__b=cc&pb="+getpropertybag();
	document.body.appendChild(script);
}
/*
try {
	_kmq.push(function(){
			document.downloadmethod = (navigator.userAgent.match(/(msie|firefox)/i)) ? KM.ab("Download Method", ["popup", "iframe"]) : "iframe";
	});
} catch (e) {}
*/
function doDownload(usepopup) {
	trackdownload();
	var w = null;
	if (usepopup) document.downloadmethod = "popup"; 
	if (document.location.href.match(/\/download\//i) || !navigator.userAgent.match(/(firefox|msie)/i)) document.downloadmethod = "iframe";

    	if (typeof(document.downloadmethod) != "undefined" && document.downloadmethod == "popup") {
		try {
			w = window.open(getDownloadLink(), "popDown", "width=1,height=1,top=0,left=0");
		} catch (e) {
			w = null;
		}
	
		if (w != null) {
			if (!redirectafterdownload || document.location.href.match(/\/download\//i)) return;
			document.location.href = CONSTANTS.download_link;
		}
	}
	if (w == null || typeof(document.downloadmethod) == "undefined" || document.downloadmethod == "iframe") {
		var downloadframe = document.getElementById("download_iframe");
		if (downloadframe == null) {
			downloadframe = document.createElement("iframe");
			downloadframe.width = "1px";
			downloadframe.height = "1px";
			downloadframe.position = "absolute";
			downloadframe.frameBorder = 0;
			downloadframe.left = "-100px";
			document.body.appendChild(downloadframe);
		}
		downloadframe.src = getDownloadLink();
		if (!redirectafterdownload || document.location.href.match(/\/download\//i)) return;
		window.setTimeout(function() { document.location.href = CONSTANTS.download_link; }, 4000); 
	}
}

var senddownload = false;
var downloadattempts = 0;
var redirectafterdownload = true;
var currentsrc = "";

function launchPlaytech(src) {
         var source = document.location.href.replace(/^.*\//, "");
	if (typeof(src) != "undefined") source += ((source != "") ? ":" : "")+src;

	currentsrc = src;

	if (typeof(trackdownload) != "undefined") trackdownload(true);
	window.open(bannerserverlink+"/flashcasino.php"+getCurrentLanguageParameter("?language="), "newwindow", "width=800, height=600");
	if (emerpcomp != null) {
		if (document.sshhwd) emerpcomp.SendEvents([["", "hphit", "cp"],["", "download", "cf"]], "download");
		else emerpcomp.SendEvent("", "download", "cf"); 
	} else sendflashdownload = true;
	if (typeof(pageTracker) != undefined) {
		pageTracker._trackEvent("Download", "flash", "full");
		pageTracker._trackPageview("/flashdownload.html");
	}
}

function getCurrentLanguageParameter(prefix) {
	if (CONSTANTS.language == "") {
		var a = document.location.href.match(/casino.com\/([a-z]{2})\//); return (a != null && a.length > 1) ?prefix+a[1]:"";
	} else {
		return (CONSTANTS.language != "") ? prefix+CONSTANTS.language : "";
	}
}

function startDownload(src, avoidredirection, usepopup) {
	if (avoidredirection) redirectafterdownload = false;
	var source = document.location.href.replace(/^.*\//, "");
	if (typeof(src) != "undefined") source += ((source != "") ? ":" : "")+src;

	currentsrc = src;

	if (typeof(pageTracker) != "undefined") {
		pageTracker._trackEvent("Download", "exe", source);
		pageTracker._trackPageview("/clientdownload.html?"+src);
	}

	isLink = true;
	var clienttype = "cd";
	try {
		if (!navigator.userAgent.match(/Windows/)) {
			clienttype = "cf";
		}
	} catch(e) {
	}

	downloadattempts = 0;
	startActualDownload(clienttype, usepopup);
}

function startActualDownload(clienttype, usepopup) {
    if (emerpcomp == null || !synced || !cookiesreloaded) {
		downloadattempts += 1;
		if (downloadattempts < 8) {
			reportserver("downloadattempt_"+downloadattempts, "download");
			window.setTimeout(function() { startActualDownload(clienttype); }, 1000);
			return;
		}
	}
	
    if (clienttype == "cd") doDownload(usepopup);
    else window.open(bannerserverlink+"/flashcasino.php", "newwindow", "width=800, height=600");

    if (emerpcomp != null) {
	if (document.sshhwd) emerpcomp.SendEvents([["", "hphit", "cp"],["", "download", clienttype]], "download");
	else emerpcomp.SendEvent("", "download", clienttype);
     } else senddownload = true;
    if (senddownload) reportserver("download");
    
}

function startDownloadWORedirection(src) {
	startDownload(src, true);

}

function openForgot() {
	$('forgotPassword').style.display = '';
}
function closeForgot() {
	$('forgotPassword').style.display = 'none';
}
function findPosition(obj) {
	var pos = {x:0, y:0}
	try { while (obj.nodeName.toLowerCase() != "body") {
			pos.x += parseInt(obj.offsetLeft, 10);
			pos.y += parseInt(obj.offsetTop, 10);
			obj = obj.offsetParent;
		}} catch (e) {	}
	return pos;
}
function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}
function openLanguages() {
	if ($('languages').style.display == 'none') {
		$('languages').style.display = '';
		$('langArrow').style.display = 'none';
		$('langArrowDown').style.display = '';
	} else {
		$('languages').style.display = 'none';
		$('langArrow').style.display = '';
		$('langArrowDown').style.display = 'none';
	}	
}
var traceoutput = "";
function trace(value) {
	//traceoutput += value+"\n";
	traceoutput += value+"_";
}
function syncAffiliate(source, destinations) {
	var value = readcookie(source);
	for (var i=0;i<destinations.length;i++) {
		savecookie(destinations[i], value);
	}
}
function setAffiliate(name, profile) {
	profile = profile ? profile : "default";
	var domain = "."+(document.domain.match(/\./ig).length > 1) ? document.domain.replace(/[^\.]*\./, "") : document.domain;
	
	var date = new Date();
	date.setTime(date.getTime()+(3*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = "banner_domainclick="+name+",,"+profile+",*,*"+expires+"; path=/"+((domain != "") ? ";domain="+domain : "");
	document.cookie = "banner_click="+name+",,"+profile+",*,*"+expires+"; path=/"+((domain != "") ? ";domain="+domain : "");
	document.cookie = "banner_download="+name+",,"+profile+",*,*"+expires+"; path=/"+((domain != "") ? ";domain="+domain : "");
}
function getaffiliate() {
	var match = (document.cookie.match(/banner_domainclick/)) ? document.cookie.match(/banner_domainclick=([\d\D]+)/i) : null;
	if (match != null && match[1].replace(/,.*/, "") != "default02") return match[1].replace(/,.*/, "");
	else return "";
}
function getdownloadaffiliate() {
	var match = (document.cookie.match(/banner_download/)) ? document.cookie.match(/banner_download=([\d\D]+)/i) : null;
	if (match != null && match[1].replace(/,.*/, "") != "default02") return match[1].replace(/,.*/, "");
	else {
		var tracker = getParamFromUrl("tracker");
		return (tracker != "default02") ? tracker : "";
	}
}
var __segment = "";
var synced = false;
var cookiesreloaded = false;

function doubletracking() {
	if (synced) return false;
	var shouldsendhphit = true;
	synced = true;
	var knownaffiliate = emerpcomp.GetProperty("aff");
	//trace("knwonaffiliate:"+knownaffiliate);
	trace("k1"+knownaffiliate);
	var knownsid = emerpcomp.GetProperty("sid");
	//trace("knownsid:"+knownsid);
	trace("k2"+knownsid);
	
	var affiliate = getaffiliate();
	var downloadaffiliate = getdownloadaffiliate();
	//trace("affiliate:"+affiliate);
	trace("a1"+affiliate);
	//trace("download affiliate:"+downloadaffiliate);
	trace("da"+downloadaffiliate);
	var sid = emerpcomp.GetSerialID();
	//trace("sid:"+sid);
	trace("s"+sid);
	var isnewaffiliate = (affiliate != "" && affiliate != knownaffiliate && !affiliate.match(/Convertonet/i));
	if (downloadaffiliate != "" && !downloadaffiliate.match(/Convertonet/i) && affiliate != downloadaffiliate && !isnewaffiliate) {
		isnewaffiliate = true;
		affiliate = downloadaffiliate;
		syncAffiliate("banner_download", new Array("banner_domainclick", "banner_click"));
	}
	
	var isnewsid = (sid != null && sid != "" && sid != knownsid);
	var isseo = getReferrer();
	var sidinurl =  document.location.search.match(/[\?\&]SID=[0-9]+/);
	//trace("isnewaffiliate:"+isnewaffiliate);
	trace("ia"+isnewaffiliate);
	//trace("isnewsid:"+isnewsid);
	trace("ic"+isnewsid);
	//trace("isseo:"+isseo);
	trace("is"+isseo);
	if (!isseo && affiliate == "" && sid == "") {
		//trace("traffic unknown. erase old referrers");
		trace("tu");
		emerpcomp.DeleteProperty("aff");
		emerpcomp.DeleteProperty("sid");
		emerpcomp.DeleteProperty("seo");
		__segment='Unknown';
		cookiesreloaded = true;
	} else if (isnewaffiliate && !sidinurl) {
		//trace("new affiliate. set ADV sid");
		trace("na");
		emerpcomp.SetProperty("aff", affiliate);
		emerpcomp.SetProperty("seo", 0);
//		emerpcomp.SetProperty("sid", 57324);
//		emerpcomp.SetSerialID(57324);
		setAFFILIATE(affiliate);
		syncAffiliate("banner_domainclick", new Array("banner_click", "banner_download"));
//		__segment='Affiliate/'+affiliate;
		shouldsendhphit = false;
	} else if (isseo && !isnewsid) {
		//trace("seo campaign, set convertonetC as an affiliate in ADV and SEO sid");
		trace("sc");
		emerpcomp.SetProperty("aff", "convertonetC");
		emerpcomp.SetProperty("seo", 1);
		setAffiliate("convertonetC", "seo");
		setSEO(isseo);
		__segment='SEO';
		shouldsendhphit = false;
	} else if (isseo && isnewsid) {
		//trace("sem campaign. set Convertonet as an affiliate in ADV");
		trace("smc");
		emerpcomp.SetProperty("aff", "Convertonet");
		emerpcomp.SetProperty("sid", sid);
		emerpcomp.SetProperty("seo", 0);
		setAffiliate("Convertonet", "sem");
		__segment='SEM';
		shouldsendhphit = false;
		cookiesreloaded = true;
	} else if (isnewsid) {
		//trace("new sid. set convertonetC as an affiliate in ADV");
		trace("ns");
		emerpcomp.SetProperty("aff", "convertonetC");
		emerpcomp.SetProperty("sid", sid);
		emerpcomp.SetProperty("seo", 0);
		setAffiliate("convertonetC", "media");
		__segment='Media/'+sid;
		cookiesreloaded = true;
	} else if (readcookie("__utmv") == null) {
		var _aff = emerpcomp.GetProperty("aff");
		var _sid = emerpcomp.GetProperty("sid");
		var _seo = emerpcomp.GetProperty("seo");
		if (_aff != "" && !_aff.match(/Convertonet/i)) __segment='Affiliate/'+_aff;
		else if (_seo == "1") __segment='SEO';
		else if (_sid != "") __segment='Media/'+sid;
		else __segment='Unknown';
		cookiesreloaded = true;
	} else {
		cookiesreloaded = true;
	}

	reportserver(traceoutput, "log");
	reportserver(document.referrer, "log");
	
	return shouldsendhphit;
}
function getReferrer() {
	return extractSearch(document.referrer);
	function extractSearch(url) {
		if (!url) return;
		var sites = [
			/^http:\/\/[^\/]*?\b(google)(?:\.[^\.]+)*\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(google\.com)\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(google\.ca)\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(google\.co\.uk)\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(yahoo)\.co(?:m|\.[^\.]+)\/.+?[\?&]p=([^&#]*)/i,
			/^http:\/\/search\.(yahoo\.com)\/.+?[\?&]p=([^&#]*)/i,
			/^http:\/\/(uk\.search\.yahoo\.com)\/.+?[\?&]p=([^&#]*)/i,
			/^http:\/\/(ca\.search\.yahoo\.com)\/.+?[\?&]p=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(bing\.com)\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(yandex)\.[^\/]*\/.+?[\?&]text=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(baidu)\.[^\/]*\/.+?[\?&]wd=([^&#]*)/i,
			/^http:\/\/[^\/]*?\bsearch\.(aol)\.[^\/]*\/.+?[\?&]q=([^&#]*)/i,
		""];
		for (var m, i = sites.length-2; i >= 0; --i)  {
			if (m = sites[i].exec(url)) {
				return {site:m[1], keyword:decodeURIComponent(m[2])};
			}
		}
	}
}

function reloadcookies(comp) {
	emerpcomp.SetProperty("aff", comp.GetProperty("aff"));
	emerpcomp.SetProperty("sid", comp.GetProperty("sid"));
	emerpcomp.SetProperty("seo", comp.GetProperty("seo"));
	emerpcomp.SetSerialID(comp.GetSerialID());
        cookiesreloaded = true;
}
var iframese = null;
function setAFFILIATE(name) {
	iframese = document.createElement("iframe");
	iframese.width = 1;
	iframese.height = 1;
	iframese.frameBorder = 0;
	iframese.src = "/core/EMERPECp/aff.php?callback=reloadcookies&name="+name+"&r="+Math.random()*100000;
	callse();
}
function setSEO(q) {
	iframese = document.createElement("iframe");
	iframese.width = 1;
	iframese.height = 1;
	iframese.frameBorder = 0;
	iframese.src = "/core/EMERPECp/se.php?callback=reloadcookies&keyword="+q.keyword+"&site="+q.site+"&r="+Math.random()*100000;
	callse();
}
function callse() {
	if (document.getElementById("emerpec") == null) {
		window.setTimeout(callse, 100);
		return;
	} else {
		document.getElementById("emerpec").parentNode.appendChild(iframese);
	}
}

function savecookie(name, value, days) {
	var date = new Date();
	date.setTime(date.getTime()+( ((typeof(days) != "undefined") ? days : 3)*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/;domain=.casino.com";
}

function readcookie(name) {
	var re=new RegExp("(?:^| )"+name+"=([^;]*)","i");
	var matches = document.cookie.match(re);
	return(matches && matches.length==2) ? matches[1] : null;
}

function deleteCookie(name) {
	savecookie(name, "", -1);
}

function reportserver(event, section) {
	var img = new Image();
	img.src = "/rs/"+((typeof(section) == "undefined") ? "events" : section)+"/"+escape(event)+".html?r="+Math.random()*100000;
}

var lastName = -1;
function gotoInfo(name) {
	if (lastName != -1 && name != lastName) {
		$(lastName).style.display = 'none';

		$(lastName+'Row').className = 'doTableRow';
		$(lastName+'Sep').className = 'doTableSep';
		$(lastName+'D').className = $(lastName+'D').className.replace('Open', '');
		$(lastName+'W').className = $(lastName+'W').className.replace('Open', '');

		$(lastName+'Frame').src = '';
	}

	if ($(name).style.display == 'none') {
		$(name).style.display = '';

		$(name+'Row').className = 'doTableRowOpen';
		$(name+'Sep').className = 'doTableSepOpen';
		$(name+'D').className = $(name+'D').className+'Open';
		$(name+'W').className = $(name+'W').className+'Open';

		$(name+'Frame').src = name+'/index.html?showlink=yes';
		document.location.href = '#link_'+name;
	} else {
		$(name).style.display = 'none';

		$(name+'Row').className = 'doTableRow';
		$(name+'Sep').className = 'doTableSep';
		$(name+'D').className = $(name+'D').className.replace('Open', '');
		$(name+'W').className = $(name+'W').className.replace('Open', '');

		$(name+'Frame').src = '';
	}
	lastName = name;
}

// Cross-sales Prompt
var isLink = false;

function on_unload() {
	if (document.location.search.match(/(client|nxs)=true/) || Flag.get('nxs')) document.cookie = "ptclient=true; path=/;domain=.casino.com";
	if (typeof(CONSTANTS.xsell_disabled) != "undefined" && CONSTANTS.xsell_disabled == "true") return false;
	if (isLink || readcookie("ptclient") == "true" || readcookie("x") == "true") {
		return false;
	} else {
                var under = Math.round(Math.random());
                var o = window.open(CONSTANTS.xsell_link+under, "_new", "width=1024, height=707");
                if (o != null) {
                        if (under == 0) {
                                o.blur();
                                window.focus();
                        }
                        document.cookie = "x=true; path=/;domain:.casino.com";
                }
		return true;
	}
}

function handleLinks(e) {
	if (window.event) {
		var srcEl = window.event.srcElement;
	} else {
		var srcEl = e.target;
	}

	var samePage = false;
	if (srcEl.href) {
		if (srcEl.href.toString().indexOf("#") != -1) {
			var path = srcEl.href.toString().substring(0, srcEl.href.toString().indexOf("#"));
			var name = srcEl.href.toString().substring(srcEl.href.toString().indexOf("#"));

			var urlpath = location.href.toString().substring(0, srcEl.href.toString().indexOf("#"));

			if (urlpath == path) {
				samePage = true;
			}
		}
	}

	var onclickLocation = false;
	if (!(null == srcEl.getAttribute('onclick'))) {
		if (srcEl.getAttribute('onclick').toString().indexOf("location") != -1) {
			onclickLocation = true;
		}
	}

	if (srcEl.tagName == 'A' || onclickLocation) {
		var parent = srcEl;
	} else {
		var parent = getParent(srcEl);
	}

	var hrefLink = false;
	if (!(null == parent.getAttribute('href')) && parent.getAttribute('href') != "") {
		if (parent.getAttribute('href').toString().indexOf("javascript") == -1) {
			hrefLink = true;
		}
	}

	var onclickLocationParent = false;
	if (!(null == parent.getAttribute('onclick'))) {
		if (parent.getAttribute('onclick').toString().indexOf("location") != -1) {
			onclickLocationParent = true;
		}
	}

	if ((parent.tagName == "A" && hrefLink && !samePage) || onclickLocationParent) {
		isLink = true;
	}
}

function getParent(obj){
	var p = obj;

	try {
		while (true) {
			if (p.tagName.toLowerCase() == "a" || p.getAttribute("onclick") != null) break;
			p = p.parentNode;
		}
		return p;
	} catch (e) {
		alert(e.description);
	}
}

//Drop Down Tabs Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Created: May 16th, 07'

	var tabdropdown={
		disappeardelay: 200, //set delay in miliseconds before menu disappears onmouseout
		disablemenuclick: false, //when user clicks on a menu item with a drop down menu, disable menu item's link?
		enableiframeshim: 1, //1 or 0, for true or false

		dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, previousmenuitem:null,
		currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), //get current page url (minus hostname, ie: http://www.dynamicdrive.com/)

		getposOffset:function(what, offsettype){
			var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
			var parentEl=what.offsetParent;
				while (parentEl!=null){
					totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
					parentEl=parentEl.offsetParent;
				}
			return totaloffset;
		},

		showhide:function(obj, e, obj2){ //obj refers to drop down menu, obj2 refers to tab menu item mouse is currently over
			if (this.ie || this.firefox)
				this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
			if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
				if (obj2.parentNode.className.indexOf("default")==-1) //if tab isn't a default selected one
					if (!obj2.className.match(/[ ]?ddopen/)) obj2.className+=" ddopen";
				obj.visibility="visible"
				}
			else if (e.type=="click")
				obj.visibility="hidden"
		},

		iecompattest:function(){
			return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
		},

		clearbrowseredge:function(obj, whichedge){
			var edgeoffset=0
			if (whichedge=="rightedge"){
				var windowedge=this.ie && !window.opera? this.standardbody.scrollLeft+this.standardbody.clientWidth-15 : window.pageXOffset+window.innerWidth-15
				this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
			if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
				edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
			}
			else{
				var topedge=this.ie && !window.opera? this.standardbody.scrollTop : window.pageYOffset
				var windowedge=this.ie && !window.opera? this.standardbody.scrollTop+this.standardbody.clientHeight-15 : window.pageYOffset+window.innerHeight-18
				this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
				if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
					edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
					if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
						edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
				}
				this.dropmenuobj.firstlink.style.borderTopWidth=(edgeoffset==0)? 0 : "1px" //Add 1px top border to menu if dropping up
			}
			return edgeoffset
		},

		dropit:function(obj, e, dropmenuID){
			if (this.dropmenuobj!=null){ //hide previous menu
				this.dropmenuobj.style.visibility="hidden" //hide menu
				if (this.previousmenuitem!=null && this.previousmenuitem!=obj){
					if (this.previousmenuitem.className.indexOf("default")==-1) //If the tab isn't a default selected one
						this.previousmenuitem.className=this.previousmenuitem.className.replace(/[ ]?ddopen/g, "");
				}			
			}
			this.clearhidemenu()
			if (this.ie||this.firefox){
				obj.onmouseout=function(){tabdropdown.delayhidemenu(obj)}
				obj.onclick=function(){return !tabdropdown.disablemenuclick} //disable main menu item link onclick?
				this.dropmenuobj=document.getElementById(dropmenuID)			
				this.dropmenuobj.onmouseover=function(){tabdropdown.clearhidemenu()}
				this.dropmenuobj.onmouseout=function(e){tabdropdown.dynamichide(e, obj)}
				this.dropmenuobj.onclick=function(){tabdropdown.delayhidemenu(obj)}
				this.showhide(this.dropmenuobj.style, e, obj)
				this.dropmenuobj.x=this.getposOffset(obj, "left")
				this.dropmenuobj.y=this.getposOffset(obj, "top")		
				this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
				this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
				this.previousmenuitem=obj //remember main menu item mouse moved out from (and into current menu item)
				this.positionshim() //call iframe shim function
			}
		},

		contains_firefox:function(a, b) {
			while (b.parentNode)
			if ((b = b.parentNode) == a)
				return true;
			return false;
		},

		dynamichide:function(e, obj2){ //obj2 refers to tab menu item mouse is currently over
			var evtobj=window.event? window.event : e
			if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
				this.delayhidemenu(obj2)
			else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
				this.delayhidemenu(obj2)
		},

		delayhidemenu:function(obj2){
			this.delayhide=setTimeout(function(){
				tabdropdown.dropmenuobj.style.visibility='hidden'; if (obj2.className.indexOf('default')==-1) { 	
					obj2.className=obj2.className.replace(/[ ]?ddopen/g, "");
				}
			},this.disappeardelay) //hide menu
		},

		clearhidemenu:function(){
			if (this.delayhide!="undefined")
				clearTimeout(this.delayhide)
		},

		positionshim:function(){ //display iframe shim function
			if (this.enableiframeshim && typeof this.shimobject!="undefined"){
				if (this.dropmenuobj.style.visibility=="visible"){
					this.shimobject.style.width=this.dropmenuobj.offsetWidth+"px"
					this.shimobject.style.height=this.dropmenuobj.offsetHeight+"px"
					this.shimobject.style.left=this.dropmenuobj.style.left
					this.shimobject.style.top=this.dropmenuobj.style.top
				}
			this.shimobject.style.display=(this.dropmenuobj.style.visibility=="visible")? "block" : "none"
			}
		},

		hideshim:function(){
			if (this.enableiframeshim && typeof this.shimobject!="undefined")
				this.shimobject.style.display='none'
		},

		isSelected:function(menuurl){
			var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "")
			return (tabdropdown.currentpageurl==menuurl)
		},

		init:function(menuid, dselected){
			this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
			var menuitems=document.getElementById(menuid).getElementsByTagName("td")
			for (var i=0; i<menuitems.length; i++){
				if (menuitems[i].getAttribute("rel")){
					var relvalue=menuitems[i].getAttribute("rel")
					document.getElementById(relvalue).firstlink=document.getElementById(relvalue).getElementsByTagName("a")[0]
					menuitems[i].onmouseover=function(e){
						var event=typeof e!="undefined"? e : window.event
						tabdropdown.dropit(this, event, this.getAttribute("rel"))
					}
				}
				if (dselected=="auto" && typeof setalready=="undefined" && this.isSelected(menuitems[i].href)){
					if (!menuitems[i].className.match(/[ ]?ddopen/)) menuitems[i].className+=" ddopen";
					var setalready=true
				}
				else if (parseInt(dselected)==i)
					if (!menuitems[i].className.match(/[ ]?ddopen/)) menuitems[i].className+=" ddopen";
			}
		}
	}

// New Cross-Sell;	
function initxsell(priority) {
	if (typeof(CONSTANTS.xsell_disabled) == "undefined" || CONSTANTS.xsell_disabled != "no") {
		if (typeof(showxsell) != "undefined") 
			CONSTANTS.xsell_disabled = (priority == "maybe") ? showxsell() : priority;
	}
	if (document.location.search.match(/[\?&]p=1/) || Flag.get('popunder')) CONSTANTS.xsell_disabled = "true";
	var Browser = {
		name:"", version:6,
		init:function() {
			navigator.userAgent.replace(/(chrome|safari|opera|firefox|msie)/i, function(a, b) {
				Browser.name = b.toLowerCase();
				try {
					switch (Browser.name) {
						case "msie":
							Browser.version = parseInt(navigator.userAgent.match(/msie ([0-9])/i)[1], 10);
							break;
						case "safari":
							var version = parseInt(navigator.userAgent.match(/version\/([0-9])/i)[1], 10);
							Browser.version = (version >= 4) ? 8 : (version == 3) ? 7 : 6;
							break;
						default:
							Browser.version = (typeof document.body.style.maxHeight != "undefined") ? 7 : 6;
					}
				} catch (e) {
				}
			});
		}
	}
	Browser.init();
	if (Browser.version >= 7) document.onmousemove = mousemove;
}

var pos = [];
function flat(arr) {
	var output = [];
	for (var i=0;i<pos.length;i++) output.push(pos[i].x+","+pos[i].y);
	return output.join("<br />");
}

var mousecheckinterval = 0;
function mousemove(e) {
	window.clearInterval(mousecheckinterval);
	e = e || event;
	if (pos.length == 0 || pos[pos.length-1].y > e.clientY) {
		pos.push({x:e.clientX, y:e.clientY});
		mousecheckinterval = window.setTimeout(checkmouseposition, 1500);
	} else pos = [];
}

function checkmouseposition() {
	if (pos.length < 2 || pos[pos.length-1].y > 150) { pos = []; return; }
	if (pos[pos.length-1].y > 10) {
		var lastgap = 10000;
		for (var i=pos.length-1;i>=1;i--) {
			var gap = pos[i-1].y-pos[i].y;
			//console.info("gap:"+gap+", lastgap:"+lastgap);
			if (gap >= lastgap) { pos = []; return; }
			lastgap = gap;
		}
	}
	popup.show('xsell');
}

var popup = {}
popup.show = function(popup) {
	var currentHeight = 0;
	containerHeight = (document.all) ? document.documentElement.offsetHeight-4 : document.documentElement.scrollHeight;
	bodyHeight = window.document.body.offsetHeight;
	
	if (containerHeight < bodyHeight) {
		currentHeight = bodyHeight;
	} else { 
		currentHeight = containerHeight;
	}
		
        if (document.location.search.match(/(client|nxs)=true/) || Flag.get('nxs')) document.cookie = "xsell=true; path=/;domain=.casino.com";
        if (typeof(CONSTANTS.xsell_disabled) != "undefined" && CONSTANTS.xsell_disabled == "true") return false;

	var xSellCookie = readcookie("xsell");
	if (xSellCookie=="true") return;
	else {
		$("blocker").style.height = currentHeight+"px";
		$("blocker").style.display = '';
		$('xsell_title').innerHTML=CONSTANTS.xsellTitle;
		$('xsell_offer').innerHTML=CONSTANTS.xsellOffer;
		$('xsell_visit').innerHTML=CONSTANTS.xsellVisitURL;
		$('download_button').innerHTML=CONSTANTS.xsellDownloadTitle;
	
	
		$(popup).style.display = '';
		document.cookie="xsell=true";

		$('xsell_iframe').src = "/xsell/gaxsell.html";
	}
}

function hideXsell(popup) {
	var iframe = document.getElementById('xsell_iframe').contentWindow; 
	iframe.sendpageview('exit');
	
	$("blocker").style.display = 'none';    
	$(popup).style.display = 'none';    
}	
	
function goTo(target) {
	var iframe = document.getElementById('xsell_iframe').contentWindow; 
	if (target=='main') {
		iframe.sendpageview('main');
		location.href=CONSTANTS.xsell_link;
	}
	else {
		iframe.sendpageview('download');
		location.href=CONSTANTS.xsellDownloadLink;
	}
}
function limitEvent(e) {
    if (!e && window.event) { //IE
        window.event.cancelBubble = true;
    } else if (e && e.stopPropagation) { //standard
        e.stopPropagation();
    }
}

function openWin(action) {
	if (action=='download' || action=='bonus') {launchPlaytech();}
	else {window.open("http://www.casino.com/za/info.html","infowindow",'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,width=670,height=470');}
	return false;
}

var bannerbuttonSet="0";
function setbannerbuttons(param) {
	if (bannerbuttonSet=="0"){
		var action = param[0].action;
		if (document.getElementById('instantplay')) {document.getElementById('instantplay').style.display='none'}
		if (action!='none') {setButton(param[0].width,param[0].height,param[0].top,param[0].left,'swf_wrapper',action);}
	}
	setbannerbuttons = "1";
	return false;
}

function setButton(width,height,top,left,parentId,action) {
	if (isNaN(width)) width = 680;
	if (isNaN(height)) height = 480;
	if (isNaN(left)) left = 0;
	if (isNaN(top)) top = 0;

	var newdiv=document.createElement("div")
	//newdiv.id = "popupButton";
	//newdiv.style.backgroundColor = "red";
	newdiv.style.width = width+"px";
	newdiv.style.height = height+"px";
	newdiv.style.position = "absolute";
	newdiv.style.top = top+"px";
	newdiv.style.left = left+"px";
	newdiv.style.cursor = "pointer";
	document.getElementById(parentId).appendChild(newdiv);
//	jQuery('#popupButton').click(function() {
//		window.open("http://www.casino.com/za/info.html","infowindow",'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,width=670,height=470');
//		return false;
//	});
	newdiv.onclick=function(event){
		limitEvent(event);
		openWin(action);
	};
}

function _as(u) {
	setTimeout(function(){
		var s = document.createElement('script'); 
		var f = document.getElementsByTagName('script')[0]; 
		s.type = 'text/javascript'; 
		s.async = true;
		s.src = u; 
		f.parentNode.insertBefore(s, f);
	}, 1);

}

function markuser(s) {
	_as("//stat.casino.com/stats/track.php?__d=true&__b=cc&pb="+s);	
}
