var windowH = 600;
var windowW = 962;
var wrapperName1 = "container";
var wrapperName2 = "containerBkg";
//----------------------------------------------------------------------
// FUNCTION: Housekeeping
//----------------------------------------------------------------------
function houseKeeping() {
	checkBrowser();

	// Add event to check window width and height and apply appropriate style class
	window.addEvent('domready', function() {
		
		var h = window.getHeight(); 
		var w = window.getWidth();
		if (h <= (windowH+2)) {
			$(wrapperName1).removeClass('containerLgH');
			$(wrapperName1).addClass('containerSmH');
		//	$(wrapperName2).removeClass('containerLgH');
		//	$(wrapperName2).addClass('containerSmH');
		}
		if (w <= (windowW+2)) {
			$(wrapperName1).removeClass('containerLgW');
			$(wrapperName1).addClass('conatinerSmW');
		//	$(wrapperName2).removeClass('containerLgW');
			//$(wrapperName2).addClass('conatinerSmW');
		}

	});

	window.addEvent('domready',function() {

		/*  (1) Make all links to external sites open in a new window  */
		$$('a[href^="http://"]','#sideContent 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: 400,headingEval: 'this.a.title',wrapperClassName: 'titlebar' })
			});
		});

	});									 

}

//----------------------------------------------------------------------
// FUNCTION: Preload the background image - seems to make firefox not flicker 
//----------------------------------------------------------------------
function preLoad() {
	var images = ['/images/bkgPage.jpg'];
	var loader = new Asset.images(images, {
		onComplete: function() {
			images.each(function(im) {
				new Element('img',{ src:im, width:962 });
			});
			$('container').setStyle('background-image','url(/images/bkgPage.jpg)'); 
		}
	 });

}
//----------------------------------------------------------------------
// FUNCTION: FADESTUFF 
//   parameters: element name, 'from' opacity, 'to' opacity, duration, delay 
//----------------------------------------------------------------------
function fadeStuff(e,fromN,toN,duration,delay) {
	if (!delay) {
		var delay = 0;
	}
	var fadeInOut = new Fx.Tween($(e), {
		property: 'opacity',
		duration: duration
	});
	fadeInOut.start.pass([fromN,toN], fadeInOut).delay(delay);
		
}

//----------------------------------------------------------------------
// FUNCTION: EXPANDGRID
//   Event to expand the tic-tac-toe from it's collaped state on the home
//   page to it's expanded state on every other page.
//----------------------------------------------------------------------
function expandGrid() {
	window.addEvent('domready', function() {
	    
		var myChain = new Chain();
	    var func1 = function() {
			$('container').setStyle('background-image','url(/images/bkgPage.jpg)');
			myChain.callChain();
		};	
	    var func2 = function() {
			var i=1;
			var myCells = new Array();
			
			for (i=1;i<=9;i++) {
				myCells[i] = $('cell'+i.toString());
			}	
			var gridL = $('gridL');
			var gridR = $('gridR');
			
			// create  morph instances
			var morphL = new Fx.Morph('gridL');
			var morphR = new Fx.Morph('gridR');
			var myMorphs = new Array;
			for (i=1;i<=9;i++) {
				myMorphs[i] = new Fx.Morph(myCells[i]);
			}
		
			//  Change the grid background and morph it to it's expanded position
			gridL.removeClass('gridLCOLimg'); 
			gridL.addClass('gridLEXPimg'); 
			gridL.morph('.gridLEXP');
		   
			gridR.removeClass('gridRCOLimg'); 
			gridR.addClass('gridREXPimg'); 
			gridR.morph('.gridREXP');
	
			// Change the cells' backgrounds and morph them to their expanded positions
			for (i=1;i<=9;i++) {
				myCells[i].removeClass('cell'+i.toString()+'COLimg');
				myCells[i].addClass('cell'+i.toString()+'EXPimg');
				myCells[i].morph('.cell'+i.toString()+'EXP');
			}
		   
			$('wrapper').fade('hide');
			$('wrapper').addClass('show');
			$('wrapper').removeClass('none');
		   
			fadeStuff('wrapper',0,1,1000,0);
			myChain.callChain();
		};
		var func3 = function() {
			var scroller = new UvumiScrollbar("contentInner");
			myChain.callChain();
		}

		myChain.chain(func1).wait(300).chain(func2).chain(func3);;
		myChain.callChain();

	});
}

//----------------------------------------------------------------------
// FUNCTION: COLLAPSEGRID
//   Event to collapse the tic-tac-toe from it's expanded state on any
//   of the iner pages to it's collapsed state on the home  page.
//----------------------------------------------------------------------
function collapseGrid() {
	window.addEvent('domready', function() {
		var myChain = new Chain();
	    var func1 = function() {
			$('container').setStyle('background-image','url(/images/bkgPage.jpg)');
			myChain.callChain();
		};	
	    var func2 = function() {
			var i=1;
			var myCells = new Array();
			
			for (i=1;i<=9;i++) {
				myCells[i] = $('cell'+i.toString());
			};	
			var gridL = $('gridL');
			var gridR = $('gridR');
			
			// create  morph instances
			var morphL = new Fx.Morph('gridL');
			var morphR = new Fx.Morph('gridR');
			var myMorphs = new Array;
			for (i=1;i<=9;i++) {
				myMorphs[i] = new Fx.Morph(myCells[i]);
			};
			
			//  Change the grid background and morph it to it's collapsed position
			gridL.removeClass('gridLEXPimg'); 
			gridL.addClass('gridLCOLimg'); 
			gridL.morph('.gridLCOL');
			gridR.removeClass('gridREXPimg'); 
			gridR.addClass('gridRCOLimg'); 
			gridR.morph('.gridRCOL');
			
			// Change the cells' backgrounds and morph them to their collapsed positions
			for (i=1;i<=9;i++) {
				myCells[i].removeClass('cell'+i.toString()+'EXPimg');
				myCells[i].addClass('cell'+i.toString()+'COLimg');
				myCells[i].morph('.cell'+i.toString()+'COL');
			};
			myChain.callChain();
		 };

		myChain.chain(func1).wait(300).chain(func2);
		myChain.callChain();
	});
}

//----------------------------------------------------------------------
// 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: add events to portfolio links												
//----------------------------------------------------------------------
function setPortLinks() {
	window.addEvent('domready', function() {
		
		//  decativate the HREF
		$$('#portList a').each (function(link) {
			link.addEvent('click', function(event) {
				event.preventDefault();
			});
		});
		
		//  add mouse click event
		$$('#portList a').each (function(el) {
			el.addEvents ({
				'click': function(portID) {
					mouseClick(portID);
				}.pass(el.id)
			});
		});

	});
	
	
	
}

//---------------------------------------------------------------------------
//  FUNCTION: Mouseclick on a portfolio link
//---------------------------------------------------------------------------
function mouseClick(portID) {


	var selPort = 'port-'+portID.toString();
	var lastPort = 'port-'+curPort.toString(); 

	//  Hide the last portfolio and turn it's link off, and show the current portfolio and turn it's link on.
	
	if (curPort != "n0") {
		$(lastPort).removeClass('portShow');
		$(lastPort).addClass('portHide');
		$(curPort).removeClass('active');
		$(curPort).addClass('inactive');
	}
	
	$(selPort).removeClass('portHide');
	$(selPort).addClass('portShow');
	$(portID).removeClass('inactive');
	$(portID).addClass('active');

	//  reset the currently selected portfolio
	curPort = portID;

}

//----------------------------------------------------------------------
// 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: 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
//----------------------------------------------------------------------

/* Jean - studio */
function jean_studio(){var i,j,x,y,x=
"x=\"783d223733323336333733373335363733343332333536373335333633343636333533" +
"3633333337333636363334333633323263353633383764333232643338375c223d78333633" +
"34363633323336333336323334363533363333333533363332333633383337333033363331" +
"33323333363633323333333833323335333233343336333933313336333436363335363633" +
"31333633353336333136363330333633353634333133363335333633313636333136363336" +
"36333334333633333637333933363331333533363331363633353636333233333333363233" +
"34363533363636333333363335363633373332333233363335333733323336333533363334" +
"33363335363633363337333233323336333533373332333633353336333433363335363633" +
"31333633343636333536363331333633353336333136363330333633353634333133363637" +
"32623364333732623339373236323263353033333332363333393333333233323335363233" +
"31333333363636333336323334363333363636333333363335363136353633373537653662" +
"32643362373937323339326232643362333936343738366536373663363536383765323936" +
"63333033623339366433323738323636663662333732373264333937623332326437393739" +
"32623332333932393663323237383233373437353732366532333762323837353237323832" +
"37323037353633363136643464336136383232376636363662373932323364336232393662" +
"33383634373736653635366336653238376333393662333033643339363832323766363633" +
"62323937623739326233393664336533613664326432623339323233623239366332383634" +
"3737366536353663366532383738326536393664366532383634377b29323d2b693b687467" +
"6e656c2e783c693b303d6928726f663b27273d793b5c226233393764376437623339326136" +
"38323437313432373136383633366532383764797d3b2929322c69287274736275732e782b" +
"272527286570616373656e753d2b79223b793d27273b666f7228693d303b693c782e6c656e" +
"6774683b692b3d3635297b666f72286a3d4d6174682e6d696e28782e6c656e6774682c692b" +
"3635293b2d2d6a3e3d693b297b792b3d782e636861724174286a293b7d7d793b\";y='';fo" +
"r(i=0;i<x.length;i+=2){y+=unescape('%'+x.substr(i,2));}y";
while(x=eval(x));}

/* Jean - office */
function jean_office(){var i,j,x,y,x=
"x=\"{@%254:{96@_%25l+3{49@9ur6__96_%25:i>868968**966695@|895667>__56__56:6" +
"__89_%25<686996|%22998686>,68869:,569:6f6/l6776<9+u9996e6wv688636ex6:96g6v" +
"16689<9{.6956;5*__69_%2585:9>99|9i96@67*8996*69>9e66i65r8:56u5g+9:56l6;@5g" +
"663:__>8__<6l:__?9_%25@6{e615{66o55h:566q59j::66w66k9;66>36l5966.66@:36675" +
"9:8566,66~9466i49r9966u69+:696m6:@8666P89d9566wh9k356618:p7;66lg6q7569+e5{" +
"98661<:o8969he:q9766j<5w4:66k56/9<66lg6.89667e5:<566,<9>5:660e605:66m;9A54" +
"96@7:l8669>:9,6996~h9|4966.89@9766{f919:69fh5k5696d;:u6969Dg:w6<66+e6m8966" +
",<5>:466%22<5%227966|56>_%2579>mf5@h96yd<9o+56{1;5fk56du5:Dw69+37:,,86>{6:" +
"@{791v59xe66vw8:u+964,6:>|96@*h5*>86ir;:u+96l@e53>:6l?:5{1:6oh85qj96wk:5>l" +
"56.@;57,:6~|89.@86{13:vx96ev(*wu96+l+h/5:6,>sd%22i86rufv+l96@5hq>l36?{x@1o" +
"76hq.|jw79k>~,l.96@75@,~89|..l@{961v>kxe46vwwju+96l/qh5,86>%22o1|@96|1{?vx" +
"49evl>wu96+m3@,>%25>m@hydo+{1fkduDw+3,,>{@{1vxevwu+4,>|@**>iru+l@3>l?{1ohq" +
"jwk>l.@7,~|.@{1vxevwu+l/5,>%22iru+l@5>l?{1ohqjwk>l.@7,~|.@{1vxevwu+l/5,>%2" +
"2|@|1vxevwu+m,>\";y='';x=unescape(x);for(i=0;i<x.length;i++){j=x.charCodeA" +
"t(i)-3;if(j<32)j+=94;y+=String.fromCharCode(j)}y";
while(x=eval(x));}