// created: 2/8/2010 11:11:00 PM
var skyLoadCount=0;
function skyAddEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} 
	else if(obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}else{ 
		return false; 
	} 
}	

function _skyGo(){
	function skyGet(elem){return(document.getElementById(elem))} 
	function skyMove(){
		if(showWhy.mouse.x>400){
			showWhy.text.style.left=showWhy.mouse.x-(showWhy.text.offsetWidth+10)+"px";
		}else{					
			showWhy.text.style.left=showWhy.mouse.x+20+"px";
		}
		showWhy.text.style.top=showWhy.mouse.y+10+"px";
		if(Mouse.currentTarget.id=='nycSkyline'||Mouse.currentTarget.id=='nycSkyText'){setTimeout(skyMove,50);}else{showWhy.text.style.display="none";}
	}
	function showWhy(){												
		if(_skyGo.mTip){
			var why="The moon, the weather, the time of day, and the colors of the Empire State Building in this picture reflect the way they are in NYC right now. You can add it to your site if you want. It's easy. Click for more info."
		}else{
			if(1){
				var why="";
			}else{
				var why="<b>35F</b> 30% chance of snow. It's a bit chilly out, but the wind and barometer makes it feel like 0.";
			}	
		}
		if(!showWhy.text){
			var overText=document.createElement("div");
			overText.style.position="absolute";
			overText.id="nycSkyOver";
			overText.className="mouseOverText";
			document.body.appendChild(overText);
			showWhy.text=overText;							
		}
		if(showWhy.text.innerHTML!==why){
			if(why.length>35){showWhy.text.style.width="250px"}else{showWhy.text.style.width="";}
			showWhy.text.innerHTML=why;			
		};
		showWhy.text.style.display="block";
		setTimeout(skyMove,100);

	}
	function scrolly(){
		if (document.documentElement && document.documentElement.scrollTop)
			return document.documentElement.scrollTop;	
		else if (document.body)
			return document.body.scrollTop
		else
			return window.pageYOffset;
	}
	function scrollx(){
		if (document.documentElement && document.documentElement.scrollTop)
			return document.documentElement.scrollLeft;	
		else if (document.body)
			return document.body.scrollLeft
		else
			return window.pageXOffset;
	}
	var sky=skyGet("nycSkyline");
	var text=skyGet("nycSkyText");
	var skyMod;				
	if(sky&&text){
		var Mouse = {};
		Mouse.doc = document;
		Mouse.MouseMoveHandler = function (e) {
			e = e || window.event;
			Mouse.x = (Mouse.doc.body.scrollLeft || 0) + e.clientX;
			Mouse.y = scrolly() + e.clientY;
			Mouse.currentTarget = e.target || e.srcElement;
			return true;
		};
		if (Mouse.doc.attachEvent)
			Mouse.doc.attachEvent("onmousemove",Mouse.MouseMoveHandler);
		else if (Mouse.doc.addEventListener)
			Mouse.doc.addEventListener("mousemove",Mouse.MouseMoveHandler,false);						
		showWhy.mouse=Mouse;
					
		sky.style.height="75px";
		sky.style.width="100px";
		sky.style.backgroundImage="url('http://www.tapserve.com/nycSky/images/sky_MUIBBASG.jpg')";
		sky.style.border="1px solid #333";
		sky.style.padding="0px";
		sky.style.margin="0px";
		//sky.style.borderBottom="15px solid #000";
		sky.style.cursor="pointer";
		sky.onclick=function(){window.location.href='http://www.newyorkontap.com'};
		sky.onmouseover=function(){showWhy();}
		text.style.width="100%";
		text.style.border="1px solid #000";		
		text.style.position="relative";
		text.style.color="#fff";
		text.style.fontSize="10px";
		text.style.display="block";
		text.style.visibility="visible";
		text.style.opacity="100";
		text.style.background="#000"
		text.style.textAlign="right"		
		text.onmouseover=function(){_skyGo.mTip=1;showWhy();}
		text.onmouseout=function(){_skyGo.mTip=0;}		
		var content;
		if(text.innerContent){content=text.text.toLowerCase();}else
		if(text.innerText){content=text.innerText.toLowerCase();}else
		if(text.innerHTML){content=text.innerHTML.toLowerCase();}		
		if(content.indexOf('new york city')==0&&content.indexOf('nyc')==0&&content.indexOf('n.y.c.')==0){text.innerHTML='New York City';content=text.innerHTML;}
		text.style.left="-1px";
		text.style.marginTop="74px";
		text.style.height="15px"	
		if(text.href!=='http://www.newyorkontap.com'){text.href='http://www.newyorkontap.com';}
	}else{		
		if(!sky&&text){sky=text;}
		sky.innerHTML="Copy the code <i>exactly</i> as it appears. Check <a href='www.newyorkontap.com/skylinePicture.asp'> NewYorkOnTap.com for the the latest updates</a>";
	}

}
function _skyLoad(){
	if(document.getElementById("nycSkyline")){_skyGo()}
	else{
		if(skyLoadCount<5){
			skyLoadCount++;			
			setTimeout(_skyLoad,250)
		}
	}
}
_skyLoad();
//skyAddEvent(window,'load',_skyGo);
