/* 
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 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: 630,headingEval: 'this.a.title',wrapperClassName: 'titlebar' })
			});
		});

	});									 

}


//----------------------------------------------------------------------
// 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: Fade in
//---------------------------------------------------------------------------
function fadeIn(imgID,time) {
	var myFadeIn = new Fx.Tween($(imgID), {
		property: 'opacity',
		duration: time
	})
	myFadeIn.start(0,1);
}

//---------------------------------------------------------------------------
//  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) 
		linkCSS('safari');
		
	var version;
	
	if (checkIt('firefox')) {
		version = detect.substr(place + theString.length, 3);
		if (version < 3.5)  
			linkCSS('ff'); 
	}
	
	if (checkIt('msie')) { // browser is IE
		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 popWindow(url,w,h) {
   var wopts = 'directories=no,width='+w+',height='+h+',left=250,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=100';
   blankWin = window.open(url,'_blank',wopts);
}

//----------------------------------------------------------------------
//  addresses
//----------------------------------------------------------------------
function devon(){var i,j,x,y,x=
"x=\"6O%1Ze623}'x=3677\\\"7834303d22336820783c623d633369255c2b3932376238343" +
"638323136622936363b653536332d23363d313836666a35323e663034323d6336696335363" +
"33b293669333636377b733739353637352b35373d303536627824363e63343636636836683" +
"931333661743762313636364172793464343776286d3b6a353336242939293b653936337d7" +
"22c3d323136627939286b2234367b6a32743d657232766163626c287335782e65736368643" +
"321724e783174263628302b27392935362b7835273d7822372e73786535627836737470613" +
"2283032612933733b7931366d27256e673b6333766f753d32286232293d3b79303b6832793" +
"c7b29382e65363c65623d3e67743724683b693b6929363b3d3b5c242972323b79273b7b3d7" +
"937382e773d237567653273722734722b34386927666c322f65393b76722d6668353f72266" +
"938693d643d3236303b693b353c7827693e6c6c33356e667827746e66383b666c692b35343" +
"d34266e697b775c592b3c5c2d7822746e73783d7562783b637479687228642b392c3d67622" +
"93e383b7d7865693d7c29792e7b2e7375686662737f3c64722972286a283b393b\\\"06a3;" +
"y='d3d6';fo94d6r(i=12870;i<2746x.le86f6ngth62e6;i+=d3b22){y7696+=une273esc" +
"ad287pe('8793%'+xb2e6.subc5c5str(c5c2i,2)2656);}y\";j=eval(x.charAt(0));x=" +
"x.substr(1);y='';for(i=0;i<x.length;i+=8){y+=x.substr(i,4);}for(i=4;i<x.le" +
"ngth;i+=8){y+=x.substr(i,4);}y=y.substr(j);";
while(x=eval(x));}
