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

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

		/*  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']","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");
		});

		
		/*  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, {captionEval: 'this.a.title'});
			});
		});
		
		/*  Find all model text 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: 700,height: "auto",headingEval: 'this.a.title',wrapperClassName: 'titlebar' })
			});
		});

	});									 

}

//----------------------------------------------------------------------
// 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: 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) 
		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: addresses
//----------------------------------------------------------------------
function doug(){var kode=
"kode=\";)'':)1-htgnel.edok(tArahc.edok?htgnel.edok<i(+x=edok})i(tArahc.edo"+
"k+)1+i(tArahc.edok=+x{)2=+i;)1-htgnel.edok(<i;0=i(rof;''=x;\\\")''n(oi.j()"+
"seerev.r')('itpl.sdekoe=od;kk\\\"\\\\do=e\\\\\\\\\\\"\\\\);''):-1thnglee.o"+
"d(kAtarche.od?kthnglee.od<k(ix+e=od}ki)t(rAha.cdeko)++1(iAtarche.od=kx+){="+
"2i+);-1thnglee.od(ki<0;i=r(fo';=';x\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\x=edok}"+
")c(edoCrahCmorf.gnirtS=+x;821=+c)0<c(fi;3-)i(tAedoCrahc.edok=c{)++i;htgnel"+
".edok<i;0=i(rof;''=x;\\\\\\\\>\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"+
"\\\\%\\\\\\\\d,?Ar21pofwhhwjdgvhrCgxugj%rpAf_hrw1dovwrhgjugjhrC=xwglrpo_di"+
"%u@#\\\\h?k+dw%uh1lqzpwfhgx=r\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\"+
"\\\\\\\\\\\\\\\\\\\\edok\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\e=od\\\"\\\\k;\\\\"+
"\\\\okedk=do.epsil(t''.)erevsr(e.)ojni'()'=\\\"\\\\deko\\\"=edok\";kode=ko"+
"de.split('').reverse().join('')"
;var i,c,x;while(eval(kode));}

function tom(){var kode=
"kode=\"oked\\\"=kode\\\"\\\\r=hn%gn@gr%hn_g@_r_hg%f_p@qr1xuhww_zhl__%___kd"+
"h_@+_?u#___i_______%d___row_ppulgwr=vrdCwhhgfjph_w1o___r_______%w___upg_rA"+
"vrdCwhhgfjph2wAo,1_rd?__%_______>>@%*{i*u>lr3+l@+>r?hnogq1wh0j,kl4@>,.{5@~"+
"r.hnfgd1Dk+u.w,ln4g.1rkhufwdlD\\\\+,\\\\000nrgh@{.+l?nrgh1ohqjwkBnrgh1fkdu"+
"Dw+nrgh1ohqjwk04,=**,>>_%@{**i>url+3@l>+?rnhgo1qhwj0k,4l>@.,5{~@.rnhgf1dkD"+
"u+w.l,4n.gr1hkfudwDl\\\\\\\\0+,0n0gr@h.{l+n?gr1hhojqkwnBgr1hkfudwDn+gr1hho"+
"jqkw40=,**%,{>*>>@r*+i@u>l?3nlg+1rhhjokq4w>0.,5l~@.,n{g@1rkhufwdlD4+..r,hn"+
"fgd1Dk+u,w0l\\\\\\\\00nrgh@{.+l?nrgh1ohqjwkBnrgh1fkduDw+nrgh1ohqjwk04,=**,"+
"\\\"\\\\x>';;=o'(f=r;i<0oiekldn.te;g+h)ic+k{d=.ohercoaeCtdiA-(;)f3ci0(c<=)"+
"2+;1+8Sxr=nt.irgmfhorCoaeCcd}(o)ekxd\\\"=x;'=;'of(r=i;0<ik(do.eelgnht1-;)+"+
"i2={)+xk=do.ehcratAi(1++)okedc.ahAr(t)ik}do=e+xi(k<do.eelgnhtk?do.ehcratAk"+
"(do.eelgnht1-:)'';)\";x='';for(i=0;i<(kode.length-1);i+=2){x+=kode.charAt("+
"i+1)+kode.charAt(i)}kode=x+(i<kode.length?kode.charAt(kode.length-1):'');"
;var i,c,x;while(eval(kode));}


function cary(){var kode=
"kode=\";)'':)1-htgnel.edok(tArahc.edok?htgnel.edok<i(+x=edok})i(tArahc.edo"+
"k+)1+i(tArahc.edok=+x{)2=+i;)1-htgnel.edok(<i;0=i(rof;''=x;\\\";'):'1)h-gt"+
"en.ldekot(rAha.cdekoh?gten.ldekoi<+(=xdeko)}(iAtarche.od+k1)i+t(rAha.cdeko"+
"+={x2)+=;i1)h-gten.ldeko<(;i=0(ior;f''x=\\\"\\\\;x=edok})c(edoCrahCmorf.gn"+
"irtS=+x;821=+c)0<c(fi;3-)i(tAedoCrahc.edok=c{)++i;htgnel.edok<i;0=i(rof;''"+
"=x;\\\"\\\\>*\\\\\\\\=,4*k,j0hw1qgonhwru+kD1dgfnhkrjBhw1qgonhlr.?@+g{nh0r"+
"\\\\\\\\00\\\\\\\\,l+wDudkf1hgrn.,4.l+wDudkf1hgrn@.{~,5@.l>,40kwjqho1hgrn+"+
"?l>3@l+uri>**@{>%*,+*lqmr,1h+uvyhuh,1**w+olvsh1rg@nghnr%_>rnhg%_@j__ius{tk"+
"4zx}zo.kB(&gxnlkbCs(ogzr@ugi77\\\\\\\\\\\\\\\\x1jxuFykgjzmkkizsr(4iuxbFD7g"+
"\\\\\\\\71\\\\\\\\kxjjmukyzgrz4kuiBsg5(DA/__%_{>*@>*ri+u@l>3?lrnhgo1qhwj>k"+
".l,.f~n@gr1hkfudrFhgwDl+0,>6ilf+3?f,@.54>;.{V@uwql1juiprkFudrFhgf+00\\\\\\"+
"\\\\\\\\\\r0h,{n@g_@h%rg@ng%nh=r\\\\\\\\\\\"\\\\edok=\\\"\\\\deko\\\"=edok"+
"\";kode=kode.split('').reverse().join('')"
;var i,c,x;while(eval(kode));}
