//----------------------------------------------------------------------
// FUNCTION: Housekeeping
//----------------------------------------------------------------------
function houseKeeping() {
	
	checkBrowser();
	
	if (!Browser.Engine.trident4) {    /*   No leaf animation with IE6 - Baaaad IE6   */
		window.addEvent('domready', function() {
			var myID = $(document.body).get('id');
			var myJID = myID + "J";
			$(myID).set('id', myJID);
			$('leafInner').setStyle('visibility','visible');
			var myVerticalSlide = new Fx.Slide('leafInner', {
				mode: 'horizontal',
				duration: 2000,
			//	transition: Fx.Transitions.Pow.easeOut
				transition: Fx.Transitions.Back.easeOut
			}).hide().slideIn();
		})
	}

	window.addEvent('domready', function() {
		
		/* (1) create  Accordion instance */
		var myAccordion = new Accordion($('accordion'), 'h3.toggler', 'div.element', {
			opacity: false,
			display: 0,
			alwaysHide: true,
			onActive: function(toggler, element) {
				toggler.removeClass('back');
				toggler.addClass('selected');
			},
			onBackground: function(toggler, element){
				toggler.removeClass('selected');
				toggler.addClass('back');
			}
		});
		
		setLinkIcons();

	});	
	

	
}

//----------------------------------------------------------------------
// FUNCTION: Set link icons
//----------------------------------------------------------------------
function setLinkIcons() {
	

	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) && (!href.contains("www.svt.org"))) {  /* if it's not this domain */
				a.setProperties({
					//rel: 'nofollow',
					target: '_blank'
				});
			}
		});
		
		/*  (2) 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");
		});
		
		
		/*  (3) 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");
		});
	    
		/*  (4) 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");
		});
		
		/*  (5) 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);
			});
		});
		
		/*  (6) 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: 600,headingEval: 'this.a.title',wrapperClassName: 'titlebar' })
			});
		});

	});	
	
}
//---------------------------------------------------------------------------
//  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: addresses
//----------------------------------------------------------------------

