// JavaScript Document

/* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

function getCookie(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 null
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate)
}


function openWindow(url, windowname, unit_number) {
	if (windowname=='unit') {
		w = 780;
		h = 680;
	}
	else if (windowname=='spotlight'){
		w = 900;
		h = 600;
	}
	else {
		w = 680;
		h = 600;
	}
	if (unit_number!='' && unit_number!=null) {
	url=url+'?unitnumber='+unit_number;
	}
	popwindow = window.open(url, windowname, 'left=20,top=20,width='+w+',height='+h+',toolbar=0,scrollbars=0');
	popwindow.focus();
}

function overmap() {
	document.getElementById('map').className = 'on';
}

function offmap() {
	document.getElementById('map').className = 'off';
}

function mapselect(mapsection) {
	document.body.className=mapsection;
}

function showLocDetail(loc, event) {
	y = event.clientY;
	x = event.clientX;
	
	bodyArray = document.getElementsByTagName('body')

	info_tag = document.getElementById(loc);
	if (x > 500 && bodyArray[0].className!='residences') {
		xOffset = -180;
	}
	else {
		xOffset = 10;
	}
	if (y > 340 && bodyArray[0].className!='residences') {
		yOffset = -80;
	}
	else {
		yOffset = 20;
	}
	
	
	info_tag.style.position='absolute';
	info_tag.style.visibility = 'visible';
	info_tag.style.left = xOffset + x + 'px';
	info_tag.style.top = yOffset + y + 'px';
}


function hideLocDetailOrig() {
	for (i=1; i<12; i++) {
		document.getElementById('loc'+i).style.visibility = 'hidden';	
	}
	
}

function hideLocDetail() {
	//get all dl elements
	var allDL = document.getElementsByTagName('dl');
	for (i=0; i<allDL.length; i++) {
		allDL[i].style.visibility = 'hidden';
	}
	
}

function checkMusic() {
	musicOnOff=getCookie('musicOnOff')
	if (musicOnOff!=null) {
		if (musicOnOff=='on')	{document.getElementById('nav_music').className = 'on';}
	}
	else {
		playMusic();
	}
}


function playMusic() {
	musicOnOff=getCookie('musicOnOff');
	if (musicOnOff=='off'||musicOnOff==null||musicOnOff=='') {
		if (!window.screenLeft) {
			windowCoordinatesLeft = '400px';
			windowCoordinatesTop = '400px';
		}
		else {
			windowCoordinatesLeft = window.screenLeft;
			windowCoordinatesTop = window.screenTop;
		}
		mpwindow = window.open('music_player.asp', 'mpwindow', 'left='+windowCoordinatesLeft+', top='+windowCoordinatesTop+', width=180,height=60,toolbar=0,scrollbars=0');
		document.getElementById('nav_music').className = 'on';
		setCookie('musicOnOff','on');
		self.focus();
	}
	else {
		setCookie('musicOnOff','off');
		document.getElementById('nav_music').className = '';
		stopMusic();
		
	}

}

function stopMusic() {
	if (!window.screenLeft) {
		windowCoordinatesLeft = '200px';
		windowCoordinatesTop = '200px';
	}
	else {
		windowCoordinatesLeft = window.screenLeft;
		windowCoordinatesTop = window.screenTop;		
	}
	mpwindow = window.open('music_player.asp', 'mpwindow', 'left='+windowCoordinatesLeft+', top='+windowCoordinatesTop+', width=180,height=60,toolbar=0,scrollbars=0');
	mpwindow.close();
	mpwindow="";
	self.focus();
}

