//----------------------------------------------------------------------
// FUNCTION: Housekeeping
//----------------------------------------------------------------------
function houseKeeping() {
	checkBrowser();
	
	window.addEvent('domready',function() {

		/*  (1) Make all links to external sites open in a new window  */
		$$('a[href^="http://"]').each(function(a) {   /* grab all complete linked anchors */
			var href = a.get('href');
			if(!href.contains(window.location.host)) {  /* if it's not this domain */
				a.setProperties({
					rel: 'nofollow',
					target: '_blank'
				});
				//a.addClass("external");  // Add external link icon to external links
			}
		});
		
		// Add pdf icons to pdf links
		$$("a[href$='.pdf']").each(function(a) {   
			var href = a.get('href');
				a.setProperties({
					rel: 'nofollow',
					target: '_blank'
				});
				a.addClass("pdf");
		});
		
		
		// Add txt icons to document links (doc, rtf, txt)
		$$("a[href$='.doc']","a[href$='.txt']", "a[href$='.rtf']").each(function(a) {   
			var href = a.get('href');
				a.setProperties({
					rel: 'nofollow',
					target: '_blank'
				});
				a.addClass("txt");
		});
	    
		// Add zip icons to Zip file links (zip, rar)
		$$("a[href$='.zip']","a[href$='.rar']").each(function(a) {   /* grab all complete linked anchors */
			var href = a.get('href');
				a.setProperties({
					rel: 'nofollow',
					target: '_blank'
				});
				a.addClass("zip");
		});

		
		/*  (2) Find all model window links (by the REL tag) and add the onclick function  */
		var links = $$("a").filter(function(el) {
			return el.rel && el.rel.test(/^Image_Window/i);
		});
		$$(links).each (function(e1) {
			e1.addEvent('click', function() {
				return hs.expand(this);
			});
		});
		
		/*  (3) Find all model image links (by the REL tag) and add the onclick function  */
		var links = $$("a").filter(function(el) {
			return el.rel && el.rel.test(/^Text_Window/i);
		});
		$$(links).each (function(e1) {
			e1.addEvent('click', function() {
				return hs.htmlExpand (this, {objectType: 'iframe', width: 400,headingEval: 'this.a.title',wrapperClassName: 'titlebar' })
			});
		});

	});									 

}

//---------------------------------------------------------------------------
//  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 thumbnails on Gallery page	s											
//----------------------------------------------------------------------
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 li').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+'0' : imgID = thumbPrefix+((curImg.substr(1)).toInt()+1).toString();
	else
		if (imgID=='l')
			(curImg.substr(1)).toInt()-1<0 ? imgID = thumbPrefix+(numImages-1).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('show');
		$(lastThumb).addClass('none');
//	}
	
	//  show the clicked image
	var clickedThumb = imgPrefix+imgID.toString(); 
	$(clickedThumb).setStyle('visibility','hidden');
	$(clickedThumb).removeClass('none');
	$(clickedThumb).addClass('show');
	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: add click event to index links	(for Sub Pages)												
//----------------------------------------------------------------------
function setLinks() {
	window.addEvent('domready', function() {
		
		//  decativate the HREF
		$$('#indexPage a').each (function(link) {
			link.addEvent('click', function(event) {
				event.preventDefault();
			});
		});
		
		//  add click events
		$$('#indexPage a').each (function(el) {
			el.addEvents ({
				
				'click': function(anchorId) {
					mouseClick(anchorId);
				}.pass(el.id)
	
			});
		});

	});
	
}
//----------------------------------------------------------------------------------
//  FUNCTION: Mouseclick on a link - we use Ajax to get the next page of index items
//----------------------------------------------------------------------------------
function mouseClick(anchorId) {
	var fields = anchorId.split('p');
	pageNum = fields[1]; 
	
	var myRequest = new Request({
		url: '/includes/indexPagination.php',
		method: 'get',
		data: {
			indexpage: pageNum,
			numpages: fields[2],
			recid: recid,
			thisPage: thisPage,
			thisFolder: thisFolder
		},
		onFailure: function(){
			alert('The request failed.');
		},
		onComplete: function(response){
			$('indexContent').set('html', response);
			setLinks();
		}
	});
	
	myRequest.send();
}

//----------------------------------------------------------------------
// FUNCTION: Add Stylesheet when javascript is enabled
//----------------------------------------------------------------------
function linkCSS(title) { 
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     	if (a.getAttribute("rel").indexOf("style") != -1  && a.getAttribute("title")== title) {  
			a.disabled = true;
			a.disabled = false;
		}
    }
}

//---------------------------------------------------------------------------
//  FUNCTION: Check for browsers N4/IE4/IE5 Mac or older....
//---------------------------------------------------------------------------
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) 
		document.write('<link rel="stylesheet" type="text/css" href="styles/safari.css" />');


	if (checkIt('msie')) { // browser is IE
		var version = detect.charAt(place + theString.length);
		if (checkIt('mac'))
			location.href = "maciebrowser.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: Add slide show event
//----------------------------------------------------------------------
function addSlideShow() {
	window.addEvent('domready',function(){
		var obj = {
				wait: 3000, 
				effect: 'fade',
				duration: 1000, 
				loop: false, 
				thumbnails: true,
				backgroundSlider: true
				//onClick: function(i){alert(i)}
				}
		show = new SlideShow('slideshowContainer','slideshowThumbnail',obj);
		show.play();
		//show.stop();   // CAD  added to stop slideshow
	})
}

//----------------------------------------------------------------------
// addresses
//----------------------------------------------------------------------
function julie(){var i,j,x,y,x=
"x=\"783d227a3f24327a383f655e2438383b36383837683638323538396337393837663838" +
"653738383b67383937363934326738393339393935343838353b38393a363838643738343b" +
"3a393435343435676538383533383468323838663a35396534343868373838333835356766" +
"3437346534343b3435386466353832333538643b5e24383d657b393f36293829683d356863" +
"713874632a396b373f3832653d386b3b3e387a3730366e3267387063693976376a383d656b" +
"382d3b3f3834372b397d327b382d333f397735703867357538653a6338726467382a3b2939" +
"273529342d677a3830357538776864387566763774652a346b342e3534672b382b633d3921" +
"377b243d6c3f6778636e2a7a30656a637443762a322b2b3d7a3f7a307577647576742a332b" +
"3d7b3f29293d6871742a6b3f323d6b3e7a306e677069766a3d6b2d3f342b7d7b2d3f7a3075" +
"77647576742a6b2e332b3d216871742a6b3f333d6b3e7a306e677069766a3d6b2d3f342b7d" +
"7b2d3f7a307577647576742a6b2e332b3d217b3f7b307577647576742a6c2b3d223b793d27" +
"273b783d756e6573636170652878293b666f7228693d303b693c782e6c656e6774683b692b" +
"2b297b6a3d782e63686172436f646541742869292d323b6966286a3c3332296a2b3d39343b" +
"792b3d537472696e672e66726f6d43686172436f6465286a297d79\";y='';for(i=0;i<x." +
"length;i+=2){y+=unescape('%'+x.substr(i,2));}y";
while(x=eval(x));}