/* 
Title:		Main Javascript
Author: 	3 Crown Creative
*/

//----------------------------------------------------------------------
// 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 image 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 window 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: add events to grid thumbnails													
//----------------------------------------------------------------------
function setLinks() {
	window.addEvent('domready', function() {
		
		//  decativate the HREF
		$$('#areas a').each (function(link) {
			link.addEvent('click', function(event) {
				event.preventDefault();
			});
		});
		
		//  add click, mouseover and mouseout events
		$$('#areas a').each (function(el) {
			el.addEvents ({
				
				'click': function(linkID) {
					mouseClick(linkID);
				}.pass(el.id)
	
			});
		});

	});
	
	
	
}
//---------------------------------------------------------------------------
//  FUNCTION: Mouseclick on a link
//---------------------------------------------------------------------------
function mouseClick(linkID) {


	var clickedBio = prefix+linkID.toString();
	var lastBio = prefix+curBio.toString(); 

	$(lastBio).removeClass('show');
	$(lastBio).addClass('hide');
	$(clickedBio).removeClass('hide');
	$(clickedBio).addClass('show');
					
	
	//  set the selelcted link to ON, and turn the previous selected link OFF
	$(linkID).addClass('active');
	$(curBio).removeClass('active');

	//  reset the currently selected link
	curBio = linkID;

}

//----------------------------------------------------------------------
// FUNCTION: Create Accordion instance
//----------------------------------------------------------------------
function createAccordion() { 
/* create our Accordion instance */
	window.addEvent('domready', function() {
		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');
			}
		});
	});
}

//----------------------------------------------------------------------
// 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: addresses
//----------------------------------------------------------------------
function info(){var i,j,x,y,x=
"x=\"783d2233585428333632783d5c22353237362363323337385345333233333633623738" +
"39337e326536783d5c5c3335335c2237373637333334333735363638333339336432323733" +
"32333133373337373333343433363334363331333333373232363633383633363636373333" +
"33363333393236333163333233333336363333373333363237333739323933323533333133" +
"3636333733343635623764333633373937333633333236353333355c5c5c223336363b793d" +
"363636273336353337333333333636273b663433336f723634333236363336333636286933" +
"33323d303b3533373634333337363536693633363c782e3333376c33333332333233323133" +
"33656e67363536746833333933333635373332333b693332332b3d32333433363339363332" +
"3336293339337b792b3335333d3635323338333633363233756e6533333373633632333233" +
"3636333033366170333632652827333633333433333632303325323362272b783733312e37" +
"33333233363336393364737562323730737433333633363337383237337228336236692c32" +
"333733323336323336333529366637293b7d323633795c223b3533366a3d6532383676616c" +
"39333328782e363333636861366433724174303362283029343335293b783633363d782e39" +
"33637375623733327374723332332831293832653b793d36633627273b363433666f723636" +
"3528693d366536303b693331333c782e3633376c656e3734366774683839333b692b363633" +
"3d3130336236297b793932332b3d783733342e73753362336273746433327228693636362c" +
"35293333323b7d663937626f7228373631693d353336333b693c393262782e6c336439656e" +
"6733363674683b353735692b3d3665363130293336337b792b3633353d782e373336737562" +
"33363673747236333428692c36313735293b3036337d793d303337792e7333353275627338" +
"32377472283633366a293b223b6a3d6576616c28782e636861724174283029293b783d782e" +
"7375627374722831293b793d27273b666f7228693d303b693c782e6c656e6774683b692b3d" +
"36297b792b3d782e73756273747228692c33293b7d666f7228693d333b693c782e6c656e67" +
"74683b692b3d36297b792b3d782e73756273747228692c33293b7d793d792e737562737472" +
"286a293b\";y='';for(i=0;i<x.length;i+=2){y+=unescape('%'+x.substr(i,2));}y";
while(x=eval(x));}