//-----------------------------------------
// SET MAX WIDTH
//-----------------------------------------

window.onload = checkAvailableWidth;
window.onresize = checkAvailableWidth;
function checkAvailableWidth(){
	document.getElementById("masthead").style.width=(document.body.clientWidth >1200)? "1200px" : "100%";
	document.getElementById("layout").style.width=(document.body.clientWidth >1200)? "1200px" : "100%";
//	document.getElementById('advert').style.background='#d3d3d3';
}

function debug(msg) {
	document.getElementById('debug').innerHTML=msg;
}
//-----------------------------------------
// MENU FUNCTIONS
//-----------------------------------------

function setMenuLocation() {
	for (menuNumber=1; menuNumber<=7; menuNumber++) {
	menuObj = document.getElementById('menu'+menuNumber);
	submenuObj=document.getElementById('submenu'+menuNumber);
	submenuObj.style.top = findTop(menuObj)+17;
	submenuObj.style.left = findLeft(menuObj);
	}
}

function showMenu(menuNumber) {
	hideAllMenus();
	menuObj = document.getElementById('menu'+menuNumber);
	submenuObj=document.getElementById('submenu'+menuNumber);
//	submenuObj.style.top = findTop(menuObj)+17;
//	submenuObj.style.left = findLeft(menuObj);
	submenuObj.style.visibility = 'visible';

	toggleSelects('hidden');
}

document.onclick=hideAllMenus;

function hideAllMenus() {
	for (counter=1; counter<=7; counter++) {
		document.getElementById('submenu'+counter).style.visibility='hidden';
	}
	toggleSelects('visible');
}

function toggleSelects(theValue) {
	dl = location;
	woo = 'http://wizardofodds.com';
	if (dl==woo || dl==woo+'/' || dl==woo+'/index.html' || dl==woo+'/test.html') {
		document.getElementById('selGamb').style.visibility=theValue;
		document.getElementById('selGame').style.visibility=theValue;
		document.getElementById('selPlay').style.visibility=theValue;
		document.getElementById('selOnline').style.visibility=theValue;
	}
}

//----------------------------------------------------------------
	preloadCounter=-1;
	preloadURLs= new Array;
	img0 = new Image();
//----------------------------------------------------------------
function preload() {

	for (counter=0; counter<=preloadCounter; counter++) {
		theURL   = preloadURLs[counter];
		img0.src = theURL;
	}
}

//----------------------------------------------------------------
function gloss(whichTerm) {
	window.open('/parts/glossary.cgi?'+whichTerm,'theWindow','width=400,height=300,scrollbars');
}

//----------------------------------------------------------------
function getBg() {
	areas = ['perimeter','menu','advert','content'];
	for (counter=0; counter<=3; counter++) {
		name = 'wiz'+areas[counter]+'color';
		nameEQ = name + "=";
		cookieArray = document.cookie.split(';');
		for(var i=0;i < cookieArray.length;i++) {
			cookie = cookieArray[i];
			while (cookie.charAt(0)==' ') cookie = cookie.substring(1,cookie.length);
			if (cookie.indexOf(nameEQ) == 0) {
				theColor = cookie.substring(nameEQ.length,cookie.length);
				if (name=='wizbodycolor') { document.bgColor=theColor;}
				else { document.getElementById(areas[counter]).style.background=theColor;}
			}
		}
	}
}

//----------------------------------------------------------------
function findLeft(obj) {
//----------------------------------------------------------------
	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 findTop(obj) {
//----------------------------------------------------------------
	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 fillerUp() {
//----------------------------------------------------------------
	if (document.location.href.indexOf('hr4411')>-1) { return;}

	obj = document.getElementById("marker");
	pageLength = findTop(obj);
	stockHeight = usedHeight = 1300;
	contextFilenames	= ['classicbj','craps7','roulette7','slots7','vidpoker7','casino7','casino7B','classicletitride'];

	contexts= ['blackjack','craps','roulette','slot', 'videopoker','jacksorbetter','deuceswild','letitride'];
	creativeIndex=[93,77,78,79,85,85,85,94];  // map the picked creativeIndex[] to the contexts[]; this line matches the previous 1:1
	FilenameIndex = [0,1,2,3,4,4,4,7]; // map the picked creativeIndex[] to the urls[]

	randomCreatives=[93,78,79,98]; // if editing this line, edit the next one, too!
	randomFilenames = ['classicbj','roulette7','slots7','mobilecasino08'];

	// PICK A CONTEXT
	creativeID = 'dummy';
	pageID	 = document.URL;

	for (counter=0; counter<= contexts.length-1; counter++) {
		if (pageID.indexOf(contexts[counter])>-1) {
			creativeID = creativeIndex[counter];
			url = contextFilenames[FilenameIndex[counter]];
//if (document.cookie.indexOf('admin')>-1) {alert(counter+' '+urls[FilenameIndex[counter]]);}
			break;
		}
	}

	// BUILD THE STRING
	stringToWrite='';
	for ( counter=0; usedHeight<=pageLength; counter++) {
		if (usedHeight + 640 <=pageLength) {

			if (creativeID =='dummy') { 
				randomNumber = Math.floor(Math.random()*randomFilenames.length);  // no bias at either end
				url = randomFilenames[randomNumber];
				creativeID = randomCreatives[randomNumber]; // for recording the click in the DB
			}

			adURL	 = '/adz/120x600-'+url+'.gif';
			rollURL  = '/adz/120x600-'+url+'X.gif';
			
			// Strip the 'http://WizardOfOdds.com/' from the pageID
			regexp   = /http:\/\/WizardOfOdds.com\/(.*)/i;
			pageID	 = '/' + pageID.replace(regexp, "$1");

			// If there are two leading slashes, turn them in to one
			regexp	 = /\/(\/.*)/;
			pageID	 = pageID.replace(regexp, "$1");

			clickURL = '/clicks.cgi?120x600+' +creativeID+'+'+pageID;
			stringToWrite += '<p style="padding-top:36px"><A href="' +clickURL+ '"><IMG SRC="'+adURL+'" class=banner border=0';

			if (stringToWrite.indexOf(rollURL)==-1) { img0.src = rollURL;}
			rollCode= ' onmouseover="this.src=\''+rollURL+'\'"; onmouseout="this.src=\''+adURL+'\'"';
			stringToWrite+=rollCode;
			stringToWrite+='></A>';
		}
		usedHeight += 654; //640 without disclaimer; 668 w/bonus promo
	}

	document.getElementById('filler').innerHTML = stringToWrite;
}
