var isIE = document.all;
var Adj = isIE?-1:-2
var Cloud = new Array(4);
var CloudNumber = 2;
var ImgPath = "Images/"
var HomePath = ""

function SetClouds() {
	Cloud[1] = new Image (40,300);
	Cloud[1].src = ImgPath + "cloud5.gif";
	Cloud[2] = new Image (40,300);
	Cloud[2].src = ImgPath + "cloud6.gif";
	Cloud[3] = new Image (40,300);
	Cloud[3].src = ImgPath + "cloud7.gif";
	Cloud[4] = new Image (40,300);
	Cloud[4].src = ImgPath + "cloud8.gif";
}

function g(which) {	return document.getElementById(which)}

function Init() {
	CenterWorld()
	MovePerpetual(g("Cloud1"),1,0,200)
	MovePerpetual(g("Cloud2"),1,0,250)
	if (g("CoordsDiv")) g("CoordsDiv").style.display = "none"
	if (g("ReserveDiv")) g("ReserveDiv").style.display = "none"
	if (g("ClickHere")) setTimeout('GrowCH()',1000);
	SetClouds()
}

function CenterWorld() {
	if (g("world")) {
		g("world").style.left = Math.max(document.body.clientWidth/2-500,0);
		g("NavTable").style.left = g("world").offsetLeft + 500 - g("NavTable").offsetWidth/2
	}
	if (g("innercontent")) {
		WinHeight = document.body.clientHeight
		OuterTop = g("content").offsetTop 
		InnerTop = g("innercontent").offsetTop
		g("innercontent").style.height = WinHeight - OuterTop - InnerTop - 30
	}
	if (g("HintDiv")) g("HintDiv").style.left = g("world").offsetLeft + 1000 - g("HintDiv").offsetWidth
	if (g("sidebar")) {
		WinHeight = document.body.clientHeight
		OuterTop = g("content").offsetTop 
		InnerTop = g("sidebar").offsetTop
		g("sidebar").style.height = WinHeight - InnerTop - OuterTop - 30
	}
}

function GrowCH() {
	thisImg = g("ClickHere")
	TotalGrowth = parseInt(thisImg.getAttribute("Growth"))
	if (TotalGrowth < 124) {
		thisImg.style.left = thisImg.offsetLeft - 1 
		thisImg.style.width = thisImg.offsetWidth + 2 
		thisImg.setAttribute("Growth",TotalGrowth+2)
		setTimeout('GrowCH()',100);
	}
}

function MoveBouncy(MoveWhat,x,y,delay,yBumpRange) {
	YBump = Math.random() * yBumpRange - yBumpRange/2
	newy = y + YBump
	moveBy(MoveWhat,x,newy);
	setTimeout('MoveBouncy(g("'+MoveWhat.id+'"),'+x+','+y+','+delay+','+yBumpRange+')',delay);
}

function MoveSmooth(MoveWhat,x,y,delay) {
	moveBy(MoveWhat,x,y);
	setTimeout('MoveSmooth(g("'+MoveWhat.id+'"),'+x+','+y+','+delay+')',delay);
}

function MovePerpetual(MoveWhat,x,y,delay) {
	if(parseInt(MoveWhat.style.left) < 1000) {
		moveBy(MoveWhat,x,y);
	} else {
		if(CloudNumber == 4) CloudNumber = 1;
		else CloudNumber ++;
		MoveWhat.src = Cloud[CloudNumber].src;
		MoveWhat.style.left = -450;
	}
	setTimeout('MovePerpetual(g("'+MoveWhat.id+'"),'+x+','+y+','+delay+')',delay);
}

function moveBy(what,x,y) {
	what.style.left = parseInt(what.style.left) + x
	what.style.top = parseInt(what.style.top) + y
}

var FirstClick = true
var AdXa = 100
var AdYa = 100
var AdXb = 0
var AdYb = 0
var AdWidth = 0
var AdHeight = 0
var BlockX = 0
var BlockY = 0
var StopX = false
var StopY = false
var BuyingAd = false

function ShowCoords(e) {
if (!BuyingAd) {
	if (!e) e = window.event;
	x = isIE? e.offsetX : e.layerX
	y = isIE? e.offsetY : e.layerY
	NewLeft = x + 10
	NewTop = y + 10
	thisElement = isIE? e.srcElement: e.target
  	switch (thisElement.id) {
	  	case ("earth"):
			BlockX = Math.ceil(x/10)
			BlockY = Math.ceil(y/10)
			if((x < AdXa*10) && (y < AdYa*10)) FirstClick = true
			else FirstClick = false
			if (FirstClick) {
				DivCode = "Coordinates: " + BlockX + "," + BlockY
				DivCode += "<br>Click to set upper left corner of your ad"
				g("CoordsDiv").innerHTML = DivCode
				StopX = false
				StopY = false
			} else {
				if (!StopX) StopX = CheckForAdH()
				if (!StopY) StopY = CheckForAdV()
				if (!StopX) AdWidth = Math.max((BlockX - AdXa + 1) * 10,10)
				if (!StopY) AdHeight = Math.max((BlockY - AdYa + 1) * 10,10)
				if ((StopX) || (StopY)) g("CoordsDiv").innerHTML = "Sorry, ads can't overlap<br>Only one ad per pixel!"
				g("ReserveDiv").style.width = AdWidth + Adj
				g("ReserveDiv").style.height = AdHeight + Adj
			}
			PlaceAt(g("CoordsDiv"),NewLeft,NewTop)
			break;
		case ("ReserveDiv"):
			StopX = false
			StopY = false
			AdWidth = Math.max(AdWidth,10)
			AdHeight = Math.max(AdHeight,10)
			DivCode = "Click to buy this " + AdWidth + " X " + AdHeight + " ad"
			DivCode += "<br>(" + (AdWidth * AdHeight) + " pixels)"
			g("CoordsDiv").innerHTML = DivCode
			PlaceAt(g("CoordsDiv"),g("ReserveDiv").offsetLeft + NewLeft,g("ReserveDiv").offsetTop + NewTop)
			break;
		case ("ad"):
			if (!FirstClick) {
				if (x > 2) StopY = true
				if (y > 2) StopX = true
			}
			g("CoordsDiv").innerHTML = thisElement.getAttribute("desc")
			PlaceAt(g("CoordsDiv"),thisElement.offsetLeft + NewLeft,thisElement.offsetTop + NewTop)
			break;
		case ("demo"):
			thisTop = thisElement.offsetTop + NewTop + g("innercontent").offsetTop
			PlaceAt(g("CoordsDiv"),thisElement.offsetLeft + NewLeft,thisTop)
			break;
	}
}
}
//Ads = new Array(new Array(AdX,AdY,AdWidth,AdHeight))
function CheckForAdH() {
	for(i = 0;i < Ads.length;i++) {
		if(BlockX == Ads[i][0]/10) {
			if((Ads[i][1]/10 <= AdYa) && ((Ads[i][1]+Ads[i][3]-1)/10 >= AdYa)) return true
			if((Ads[i][1]/10 >= AdYa) && (Ads[i][1]/10 <= BlockY)) return true
		}
	}
	return false
}

function CheckForAdV() {
	for(i = 0;i < Ads.length;i++) {
		if(BlockY == Ads[i][1]/10) {
			if((Ads[i][0]/10 <= AdXa) && ((Ads[i][0]+Ads[i][2]-1)/10 >= AdXa)) return true
			if((Ads[i][0]/10 >= AdXa) && (Ads[i][0]/10 <= BlockX)) return true
		}
	}
	return false
}

function getNext(CoordArray,Block) {
	for(i = 0;i < CoordArray.length;i++) {
		if(CoordArray[i][0]/10 > Block) return CoordArray[i]
	}
}

function PlaceAt(which,x,y) {
	which.style.display = ""
	if (x > 500) x -= which.offsetWidth + 20
	if (y > 500) y += -15 - which.offsetHeight
	which.style.left = g("world").offsetLeft + x
	thisTop = (g("earth"))?g("earth").offsetTop:g("content").offsetTop
	which.style.top = thisTop + y
}

function BuyAd(which) {
	BuyingAd = true
	WriteAdSpecs()
	g("AdType").value = "regular"
	g("AdSize").value = parseInt(g("AdWidth").value) * parseInt(g("AdHeight").value)
	ConfirmText = "Buy a " + g("AdWidth").value + " X " + g("AdHeight").value + " ad, "
	ConfirmText += "at coordinates " + g("AdXa").value + "," + g("AdYa").value + "?"
	if (confirm(ConfirmText)) {
		g("ReserveDiv").style.display = "none"
		Form.submit()
	} else Reset()
}

function hc(e) {
	if (g("CoordsDiv"))  {
		g("CoordsDiv").style.display = "none"
		status = ""
		if (!e) e = window.event;
		thisElement = isIE? e.srcElement: e.target
		if (thisElement.tagName == "AREA") g("CoordsDiv").innerHTML = ""
	}
}

function ss(which,e) {
	if (g("CoordsDiv"))  {
		g("CoordsDiv").innerHTML = which.getAttribute("desc")
		if (!e) e = window.event;
		x = isIE? e.offsetX : e.pageX - g("world").offsetLeft
		y = isIE? e.offsetY : e.pageY - 30
		NewLeft = x + 10
		thisTop = (g("earth"))?g("earth").offsetTop:g("content").offsetTop
		PlaceAt(g("CoordsDiv"),NewLeft,y + 50 - thisTop)
	}
}

function ReserveBlock(e) {
	if (!e) e = window.event;
	thisElement = isIE? e.srcElement: e.target
  	if (thisElement.id == "earth") {
		g("ReserveDiv").style.display = ""
		if (FirstClick) {
			AdXa = BlockX
			AdYa = BlockY
			AdXb = 0
			AdYb = 0
			AdWidth = 10
			AdHeight = 10
			g("ReserveDiv").style.left = BlockX * 10-10
			g("ReserveDiv").style.top = BlockY * 10-10
			g("ReserveDiv").style.width = AdWidth + Adj
			g("ReserveDiv").style.height = AdHeight + Adj
			WriteAdSpecs()
			FirstClick = false
		} else Reset()
	}
}

function Reset() {
	g("ReserveDiv").style.display = "none"
	g("ReserveDiv").style.width = 10
	g("ReserveDiv").style.height = 10
	g("ReserveDiv").style.left = 0
	g("ReserveDiv").style.top = 0
	AdXb = BlockX
	AdYb = BlockY
	WriteAdSpecs()
	FirstClick = true
	AdXa = 100
	AdYa = 100
	AdXb = 0
	AdYb = 0
	AdWidth = 10
	AdHeight = 10
	BuyingAd = false
}

function WriteAdSpecs() {
	g("AdXa").value = AdXa
	g("AdYa").value = AdYa
	g("AdXb").value = AdXb
	g("AdYb").value = AdYb
	g("AdWidth").value = AdWidth
	g("AdHeight").value = AdHeight
}

function cs(which) {
	if (g("CoordsDiv"))  {
		g("Form").action = HomePath + "buypixels.php"
		g("AdType").value = "irregular"
		g("AdParcel").value = which.id
		g("AdSize").value = which.getAttribute("size")
		if (which.offsetLeft == 0) {
			coordArray = g(which.id).coords.split(",")
			g("AdXa").value = coordArray[0]
			g("AdWidth").value = 20
		} else {
			g("AdXa").value = which.offsetLeft
			g("AdWidth").value = which.offsetWidth
		}
		ConfirmText = "Buy Skyline parcel " + which.id + " (" + which.getAttribute("size") + " pixels)?"
		if (confirm(ConfirmText)) {
			g("Form").action = HomePath + "buypixels.php"
			g("Form").submit()
		}
	}
}

function rc(which) {
	temp = new Image (10,10);
	temp.src = "inc/rc.php?AdID=" + which.id;	
}

function NavHere(which) {
	which.setAttribute("CanGrow",true)
	Grow(which)
}

function NavGone(which) {
	which.setAttribute("CanGrow",false)
	Shrink(which)
}

var Growth = 1
var GrowthSpeed = 50
var GrowthLimit = 15

function Grow(which) {
	if (which.id == "AustinManiA") window.status = ""
	TotalGrowth = parseInt(which.getAttribute("Growth"))
	thisCanGrow = isIE? which.getAttribute("CanGrow") : (which.getAttribute("CanGrow") == "true")
	if ((TotalGrowth < GrowthLimit) && thisCanGrow) {
		g("NavTable").style.left = g("NavTable").offsetLeft - Growth
		which.style.width = which.offsetWidth + Growth * 2 
		which.setAttribute("Growth",TotalGrowth+Growth)
		setTimeout('Grow(g("'+which.id+'"))',GrowthSpeed);
	}
}

function Shrink(which) {
	if (which.id == "AustinManiA") window.status = ""
	TotalGrowth = parseInt(which.getAttribute("Growth"))
	if (TotalGrowth > 0) {	
		g("NavTable").style.left = g("NavTable").offsetLeft + Growth
		which.style.width = which.offsetWidth - Growth * 2
		which.setAttribute("Growth",TotalGrowth-Growth)
		setTimeout('Shrink(g("'+which.id+'"))',GrowthSpeed);
	}
}

function ShowHint(delay) {
	g("RestartSpan").style.display = "none"
	g("HintSpan").setAttribute("currHint",0)
	setTimeout('NextHint()',delay);
}

function CloseHint() {
	if (g("HintDiv")) g("HintDiv").style.display = "none"
	if (g("HintDiv2")) g("HintDiv2").style.display = "none"
}

var Hints = new Array()
Hints.push("Have you figured out how to get to the AustinMania! page yet?<br><div align='center'>Um, <u>No !</u></div>")
Hints.push("If you'd like a hint or two, click me again")
Hints.push("As you can see, it's not here.  You will have to look elsewhere")
Hints.push("Try the Nav Blobs above")
Hints.push("Does it make sense to click on the Nav Blob of the page you are on?")
Hints.push("Only if you're Home!")

function NextHint() {
	g("HintDiv").style.display = ""
	CurrHint = parseInt(g("HintSpan").getAttribute("currHint"))
	if (CurrHint < Hints.length) {
		if (CurrHint == Hints.length-1) g("RestartSpan").style.display = ""
		g("HintSpan").innerHTML = Hints[CurrHint]
		g("HintSpan").setAttribute("currHint",CurrHint + 1)
		g("HintDiv").style.left = g("world").offsetLeft + 1000 - g("HintDiv").offsetWidth
	}
}

function ShowPic(which) {
	WinFeatures = "status, resizable"
	PicWin = open(which.src,"PicWin",WinFeatures)
}



