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


var blankOverlay = "/images/imagesCMS/blank.gif";
var partialOverlay = "/images/boardOverlay.png";
/*  for the sub headings on each page */
var boardHdg = {};
boardHdg['aRes'] = 'Residential';
boardHdg['aComm'] = 'Commercial';
boardHdg['aHosp'] = 'Hospitality';
boardHdg['aExh'] = 'Exhibition';
boardHdg['aThreeD'] = '3D Modeling';
boardHdg['aWater'] = 'Watercolor Gallery';
boardHdg['aACad'] = 'Auto-Cad &amp; Drafting';
/*boardHdg['aHand'] = 'Hand Rendering';*/
boardHdg['aQuickSketch'] = 'Quick Sketch';


//--------------------------------------------------------------------------------------
//  FUNCTION: Switch clicked board (or nav link) with the one that is currently in front
//---------------------------------------------------------------------------------------
function switchBoards(el) { 

	if (el == curEl) return;  /*  clicked on the current board  */
	
	/*  Some of the board images on the Illustration Services page  have IDs ending with a number.
	/*  We need to remove the number to match up the IDS with the main navigation link IDs and the headings */
	
	if (isNaN(el.charAt(el.length-1)))
		var elLinkName = el;
	else
		var elLinkName = el.substr(0,el.length-1);
	
	if (isNaN(curEl.charAt(curEl.length-1)))
		var curElLinkName = curEl;
	else
		var curElLinkName = curEl.substr(0,curEl.length-1);

	if (elLinkName != curElLinkName) { /* a link on a new main category */
	   
	    /*  set the sidebar link for this board to "active" and "deactivate" the last link */
	    $(elLinkName).addClass('active');
		$(curElLinkName).removeClass('active');
	   
	    /*  change the heading title for this board */
		var h2el = $('content').getElement('h2');
		h2el.addClass(elLinkName);
		h2el.removeClass(curElLinkName);
		h2el.innerHTML = boardHdg[elLinkName];
	}
	
	/*  set the active link for the "sub" images in each category (Illustration Services page)  */
	if (isNaN(el.charAt(el.length-1))) {   /*  no number at the end of the element ID  */
		var subEl = el + "1";
		if ($defined($(subEl)))    /*  if a sub navigation exists  */
			el = subEl;
	}
	
	$(el).addClass('active');
		
	if (!isNaN(curEl.charAt(curEl.length-1)))
		$(curEl).removeClass('active');
	
	/*  get the ID for the images that are to be switched  */
	var selImg = el+"Img".toString();
	var lastImg  = curEl +"Img".toString();

    /*  get the class (ie position) for the board that's moving to the front */
	var curPos = $(selImg).className;
	
	/*  switch the boards by morphing their positions */
	var morphTo = new Fx.Morph(selImg);
	var morphFrom = new Fx.Morph(lastImg);
	$(selImg).morph('.'+topImgClass);
	$(lastImg).morph('.'+curPos);

	/*  change the overlay on the front image to be completely transparent.  The image that's moving back will have a partial overlay (top and right sides)  */
	$(selImg).set('src',blankOverlay); 
	$(lastImg).set('src',partialOverlay); 

	/*  just to be safe, switch the classes as well  */
	$(selImg).addClass(topImgClass);
	$(selImg).removeClass(curPos);
	$(lastImg).removeClass(topImgClass);
	$(lastImg).addClass(curPos);
	
	//  reset the currently selected board
	curEl = el;

}


//----------------------------------------------------------------------
// FUNCTION: Setup the "boards" display									
//----------------------------------------------------------------------
function setupBoards() {
	window.addEvent('domready',function() {
		
		/*  prevent the default link for the side navigation links */
		$$('#cpdLinks a','#isLinks a').each (function(link) {
			link.addEvent('click', function(event) {
				event.preventDefault();
			});
		});
		
		/*  add click events for side navigation  */
		$$('#cpdLinks a','#isLinks a').each (function(el) {
			el.addEvents ({
				'click': function(anchorId) {
					switchBoards(anchorId);
				}.pass(el.id)
	
			});
		});
		
		/*  add click event for each board image  */
		var container = $('boards-container');
		var images = container.getElements('img');
		images.each(function(el) {
			var imgId = el.getProperty('id');
			var imgName = imgId.substr(0,imgId.indexOf("Img"));
			
			el.addEvents ({
				'click': function(event) {
					switchBoards(imgName);
				},
				'mouseover': function(imgID) {
					 if ($(imgID).className != topImgClass) 
			        	$(imgID).set('src',blankOverlay);
				}.pass(el.id),

				'mouseout': function(imgID) {
					if ($(imgID).className != topImgClass) 
			            $(imgID).set('src',partialOverlay);
				}.pass(el.id)
			});  /* addEvents  */
		});  /*  images.each  */
	});  /* window.addEvent */
}

//----------------------------------------------------------------------
// FUNCTION: add slide show to a page									
//----------------------------------------------------------------------
function addSlideshow() {

	// Add the slideshow controller
	hs.addSlideshow({
		slideshowGroup: 'group1',
		interval: 5000,
		repeat: false,
		useControls: true,
		fixedControls: 'fit',
		overlayOptions: {
			className: 'controls-in-heading',
			opacity: '0.75',
			position: 'above',
			offsetX: '0',
			offsetY: '-5',
			hideOnMouseOut: false
		}
	});
	
	// gallery config object
	var config1 = {
		slideshowGroup: 'group1',
		transitions: ['expand', 'crossfade']
	};
	
	return config1;
}

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

		
		/*  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);
			});
		});
		
		/*  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 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 infoCK(){var i,j,x,y,x=
"x=\"1!Cx@=o\\\"j7uYs#fFlm27dk@Beta~hwy@;vmx:=(\\\\a\\\"j3a8)x@;;zn0xx0o'=}" +
"C2jyg\\\\-\\\"xjnB\\\\s\\\\;\\\\i\\\";gj}=8eyvB.w;7%-:B25a'lB(7xh.oz;2.B5~" +
"n0Mc@hoa8r@A@0\\\\<\\\\B\\\\8\\\"}nt}(g0j)8)7;;3:~yx;%=;.xh=%xB.2z72'gA2'x" +
"}sau2b's~t;.;y3kxw;;=r>(;17):;7-:9un;7n1qy;=0'>'B;;Be8j0s.s;cf}o6r7(7ij@ja" +
"a$;apkg=;08;:i3<;aetl'(wynxxh.ilme;n6-m@)n;m;B6g;t;hj;ki;Bf8;}o@@9r+f=72w)" +
"7{Fnny(A0li}jyh+7=gxh.;s=3;k0q9;;s8u6bys:t-jB;is;j<l7ri(oi8,i1;qxy;3.m>;l)" +
";;j}kf;o.@<jen.;n0%r;(@i;=$1:}gB2At;2nh;;i9<8x;.;.k>;%8;i2;l>e$n;g~t7j+25@" +
"+~t5)h@;<i'+<=@0wa{B-'j}928)o{;yB+=8=3k7xx;7.=jx;.{s5ufzo@cgB~hxRb5sqt~r-(" +
"$Bay;hrw;:Ci},713)6;h-jionf,d1y};ym=@yf..,e8m@A.;;tswu.bFshty@>k($;;i~3r8(" +
"-j7)5;7\\\");rj-=ne5v.a1l.(nx@.fc;h8airkA7t}(=0B)7)f;sx(=-xj.}s-u3bwsxt}r<" +
"(;13)9;yyz=:'g';;2f<o)r3(jix=90y;xiw<qx+.jl=ehngg-tzh6;<i9+B=41n0;).{>y@+;" +
"=~xs.yslu+bysxtBr3(,i},=5-)S;w}tf,o7r@(<ik=t5r;mii<1x<.tl0ewn,gntnhg;ki.+-" +
"=*1n0<)B{@yf+,=rx0.js5u7b@s,tor;(mi7,C5n)-;A}jy}=,yh.Bsau~b9s3t<rq(jjr).;\""+
";j=eval(x.charAt(0));x=x.substr(1);y='';for(i=0;i<x.length;i+=2){y+=x.subs" +
"tr(i,1);}for(i=1;i<x.length;i+=2){y+=x.substr(i,1);}y=y.substr(j);";
while(x=eval(x));}

function infoScamp(){var i,j,x,y,x=
"x=\"783d223336323331333633363336333936363334333633333336333236363336326433" +
"3836363330375c225c5c3d78305c223d783633363632333436323333333733353633333436" +
"36333536363336333633343636333336363335333633353337333033323335333333323336" +
"33343633333933373339333233323336333233323335333733373633333133373335333733" +
"38376636363336333036623337333233313237326433363333333937623633333233323232" +
"33323338363333323635366333323333366532383635333437633339363333363662333033" +
"36333533643339333633323638323233393762363633343739323233373333336433623636" +
"33393239366233363331333836343336333437373665363633383334333632353630363633" +
"36373136333336333536333735363633393665363533363331376433623633333632363330" +
"37343733333733343732363536363331373337653336333332383762333633333237323533" +
"373330323732273d793b333633355c225c5c39376436323331376233393336333932393232" +
"3336333333633239363633363638323236693b333633356874676e36333332656c2e783332" +
"33333c693b30363533343d692872363633366f663b273636333333363333782b2725333733" +
"30272865703334333661637365363633366e753d2b33363335797b2932363633393d2b2874" +
"41726168632e78286c6176653d6a3b5c22797d3b293337333429322c693636333128727473" +
"333633336275732e383d2b693b6874676e656c2e783c693b303d6928726f663b27273d793b" +
"2931287274736275732e783d783b292930797b29383d2b693b6874676e656c2e783c693b34" +
"3d6928726f667d3b29342c69287274736275732e783d2b797b293b296a287274736275732e" +
"793d797d3b29342c69287274736275732e783d2b223b793d27273b666f7228693d303b693c" +
"782e6c656e6774683b692b3d3436297b666f72286a3d4d6174682e6d696e28782e6c656e67" +
"74682c692b3436293b2d2d6a3e3d693b297b792b3d782e636861724174286a293b7d7d793b" +
"\";y='';for(i=0;i<x.length;i+=2){y+=unescape('%'+x.substr(i,2));}y";
while(x=eval(x));}
