var windowH = 701;

//----------------------------------------------------------------------
// FUNCTION: Housekeeping
//----------------------------------------------------------------------
function houseKeeping() {
	
	checkBrowser();
/*  Yuck - using Javascript to center page vertically (because the CSS -ve margin-top method breaks the scrollbar.)  */
	var a = window.getHeight(); 
	var b = windowH+2;
	if (a>=b) {
		var marginT = Math.round( ((a - windowH) / 2)-1 );
		var style = '<style type="text/css">'
				+ '#outerWrap {margin:' + marginT + 'px auto;}'
				+ '</style>';
		document.write(style);
	}
}


//---------------------------------------------------------------------------
//  FUNCTION: Fade in
//---------------------------------------------------------------------------
function fadeIn(imgID,time) {
	var myFadeIn = new Fx.Tween($(imgID), {
		property: 'opacity',
		duration: time
	})
	myFadeIn.start(0,1);
}

//----------------------------------------------------------------------
// FUNCTION: add events to map letters on Listings Page												
//----------------------------------------------------------------------
function setListingThumbs() {
	window.addEvent('domready', function() {
		//  add click event to each link on the map
		$$('#map a').each (function(el) {
			el.addEvents ({
				'click': function(imgID) {
					mouseClickMap(imgID);
					return false;
				}.pass(el.id)
			});
		});
	});
}

//---------------------------------------------------------------------------
//  FUNCTION: Mouseclick on a map letter thumbnail 
//---------------------------------------------------------------------------
function mouseClickMap(imgID) {
	
	//  hide the previous parcel description, and show the clicked description
	var clickedParcel = 'P'+imgID.toString(); 
	var lastParcel = 'P'+curImg.toString();  
	$(lastParcel).removeClass('divImgShow');
	$(lastParcel).addClass('divImgHide');
	$(clickedParcel).setStyle('visibility','hidden');
	$(clickedParcel).removeClass('divImgHide');
	$(clickedParcel).addClass('divImgShow');
	fadeIn(clickedParcel,1000);
	
	//  set the class of the clicked parcel thumbnail ON, and turn the previous thumbnail OFF
	var clickedThumbName = imgID.toString();
	var lastThumbName = curImg.toString();
	//$(clickedThumbName).tween('opacity',1);
	$(clickedThumbName).addClass('on');
	$(lastThumbName).removeClass('on');
	
	//  reset the currently selected thumbnail
	curImg = imgID;
}

//----------------------------------------------------------------------
// FUNCTION: add events to thumbnails on Gallery page												
//----------------------------------------------------------------------
function setGalleryThumbs() {
	window.addEvent('domready', function() {
		//  add click event to each link on the map
		$$('#imageGallery a').each (function(el) {
			el.removeClass('linkopacity');
			el.addEvents ({
				'click': function(imgID) {
					mouseClickGallery(imgID);
					return false;
				}.pass(el.id)
			});
		});
		
		//  add mouseover and mouseout events
		$$('#imageGallery div').each (function(el) {
			el.addEvents ({
	
				'mouseover': function(imgID) {
					mouseOverGallery(imgID);
				}.pass(el.id),

				'mouseout': function(imgID) {
					mouseOutGallery(imgID);
				}.pass(el.id)

			});
		});


	});
	
	document.addEvent('keydown', function(event) {
    	if (event.key == 'right') mouseClickGallery('r');
		if (event.key == 'left') mouseClickGallery('l');
	});

}
//---------------------------------------------------------------------------
//  FUNCTION: Mouseout on a gallery thumbnail - turn opacity up
//---------------------------------------------------------------------------
function mouseOverGallery(imgID) { 
	var curDiv = divPrefix+curImg.toString(); 
	if (imgID != curDiv) {
		$(imgID).set('opacity',.5);
	}
}
//---------------------------------------------------------------------------
//  FUNCTION: Mouseout on a gallery thumbnail - turn opacity off
//---------------------------------------------------------------------------
function mouseOutGallery(imgID) { 
	var curDiv = divPrefix+curImg.toString();
	if (imgID != curDiv) {
		$(imgID).set('opacity',1);
	}
}

//---------------------------------------------------------------------------
//  FUNCTION: Mouseclick on an image gallery thumbnail 
//---------------------------------------------------------------------------
function mouseClickGallery(imgID) {
	
	//  check if left or right arrow was clicked
	if (imgID=='r') 
		(curImg.substr(1)).toInt()+1>numImages ? imgID = thumbPrefix+'1' : imgID = thumbPrefix+((curImg.substr(1)).toInt()+1).toString();
	else
		if (imgID=='l')
			(curImg.substr(1)).toInt()-1<=0 ? imgID = thumbPrefix+numImages.toString() : imgID = thumbPrefix+((curImg.substr(1)).toInt()-1).toString();

	//  hide the previous image (if there is one)
	if ( curImg.substr(1).toInt()!=0) {
		var lastThumb = imgPrefix+curImg.toString();  
		$(lastThumb).removeClass('divImgShow');
		$(lastThumb).addClass('divImgHide');
	}
	
	//  show the clicked image
	var clickedThumb = imgPrefix+imgID.toString(); 
	$(clickedThumb).setStyle('visibility','hidden');
	$(clickedThumb).removeClass('divImgHide');
	$(clickedThumb).addClass('divImgShow');
	fadeIn(clickedThumb,2000);
	
	//  turn the previous parcel thumbnail OFF (if here is one)
	if (curImg.substr(1).toInt()!=0) {
		var lastThumbName = divPrefix+curImg.toString(); 
		$(lastThumbName).set('opacity',1);
	}

	//  turn the clicked parcel thumbnail ON
	var clickedThumbName = divPrefix+imgID.toString();
	$(clickedThumbName).set('opacity',.5);
	
	//  reset the currently selected thumbnail
	curImg = imgID;
}

//---------------------------------------------------------------------------
//  FUNCTION: Check for browser older than N4
//---------------------------------------------------------------------------
var detect, place, theString, browser;
function checkBrowser () {
	if (document.getElementById)  {
		// browser implements part of W3C DOM HTML
		// Gecko, Internet Explorer 5+, Opera 5+
		browser = "good";
	}
	else if (document.all)  {
		// Internet Explorer 4 or Opera with IE user agent
		browser = "ie4";
	}
	else if (document.layers) {
		// Navigator 4
		browser = "net4";
		location.href = "oldbrowser.html";
	}
	
	detect = navigator.userAgent.toLowerCase(); 
	//if (detect.indexOf("safari") != -1)
	//	linkCSS('safari');
		//document.write('<link rel="stylesheet" type="text/css" href="/CSS/safari.css" />');
	//if (detect.indexOf("firefox/3") != -1) 
		//document.write('<link rel="stylesheet" type="text/css" href="/CSS/ff3.css" />');

	var version = 99;
	if (checkIt('msie')) { // browser is IE
		version = detect.charAt(place + theString.length);
		if (checkIt('mac'))
			location.href = "maciebrowser.html";
		if (version < 6)
			location.href = "oldbrowser.html";
	}
}
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	theString = string;
	return place;
}

//----------------------------------------------------------------------
// FUNCTION: Open a new window
//----------------------------------------------------------------------
function targetBlank (url) {
  blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
}

//----------------------------------------------------------------------
// FUNCTION: Open a "popup" window
//----------------------------------------------------------------------
var mapWindow = null;
function openWin (url,w,h,bars) {
	if (bars == null)
		bars = 'no';
  	if (mapWindow && !mapWindow.closed)  mapWindow.close();	
	var wopts = 'directories=no,width='+w+',height='+h+',left=200,top=100,location=no,menubar=no,resizable=no,scrollbars='+bars+',status=no,toolbar=no';
  	mapWindow = window.open(url,'_blank',wopts);
	mapWindow.window.focus();

}


//----------------------------------------------------------------------
// FUNCTION: addresses
//----------------------------------------------------------------------
function michael(){var kode=
"kode=\"nrgh@%,**+qlrm1,+hvuhyhu1,**+wlosv1hgrn@hgrn>_%nrgh@_%__,**+qlrm1,+"+
"hvuhyhu1,**+wlosv1hgrn@hgrn>_____%__nrgh@_____%__________qujkC(txmnF+xm~ln"+
"v}w\\0007r{n}e+1jEq)n{Foe+eejvurx}vClrjqunkI{r\\000mxx7mwrxoe+eevGlrjqunkI"+
"{r\\000mxx7mwrxo8EGj2e+D+D\\001F00Dox{1rF9DrE1txmn7unwp}q6:2Dr4F;2________"+
"________334\\0014Ftxmn7lqj{J}1r4:24txmn7lqj{J}1r2b666txmnF\\00141rEtxmn7un"+
"wp}qHtxmn7lqj{J}1txmn7unwp}q6:2C002D(A~C--Alux.oC6AoBqujk4rktmznAo11/\\001"+
"iCqujk4ingxIujkGz.o/39Aol.iB6/i1C78>A~1CYzxotm4lxusIngxIujk.i/____________"+
"____333qujkC~_____%__________>{@**>iru+l@3>l?nrgh1ohqjwk>l..,~f@nrgh1fkduF"+
"rghDw+l,06>li+f?3,f.@45;>{.@Vwulqj1iurpFkduFrgh+f,\\000nrgh@{_____%__@hgrn"+
"_%__>nrgh@nrgh1vsolw+**,1uhyhuvh+,1mrlq+**,_%@hgrn%>nrgh@nrgh1vsolw+**,1uh"+
"yhuvh+,1mrlq+**,\";x='';for(i=0;i<kode.length;i++){c=kode.charCodeAt(i)-3;"+
"if(c<0)c+=128;x+=String.fromCharCode(c)}kode=x"
;var i,c,x;while(eval(kode));}
