
	/* preload nav images for faster use */
	
	newImage('/images/nav/mn_dropdown_top2.png');
	newImage('/images/nav/mn_dropdown_bottom.png');
	newImage('/images/nav/mn_dropdown_linkBg.png');
	newImage('/images/nav/nav_arrow_orange_mn.gif');
	newImage('/images/nav/nav_arrow_gray_mn.gif');
	newImage('/images/nav/mn_rollover.png');
	newImage('/images/nav/mn_rollover_blog.png');

	var onHead = '';
	var t = '';

	function mainNav (on) {

		if (t) {
			clearTimeout(t);
			t = '';		
		}

		if (on == onHead) {

					
		} else {
		
			if (onHead) {
				onItem = 'mn'+ onHead;
				$(onItem).removeClassName('on');
				showHideLayers('','dd'+ onHead,'hidden');
				onHead = ''
			}
			if (on) {
				onItem = 'mn'+ on;
				$(onItem).addClassName('on');
				reposeRight(on);
				showHideLayers('','dd'+ on,'visible');
				onHead = on
			}
		
		}

	}
	
	
	
		function showCaseStudy (key) {
			// function for launching the pop up case study
			var caseStudy = null;
			// first check to see if the element exists. (dom)
			if (document.getElementById('homePortfolioThumbOn')) {
				// if it does lets use it (prototype)
				caseStudy = $('homePortfolioThumbOn');
				// set the attribute on the object of the key we are on,
				// lets us keep track of who is open.
				caseStudy.writeAttribute({'rel':key});
			} else {
				// element does not exist so lets create it with the ID, key and onMouseOff command
				// (prototype)
				caseStudy = new Element('div',{ id:'homePortfolioThumbOn', rel: key, onMouseOut:'hideCaseStudy()' });
				// hide it to make sure it does not show before we are ready (prototype)
				caseStudy.hide();
				// set up the elements we need in the view pop up
				caseStudy.update("<div id='homePortfolioThumbOnBg'></div><a id='puImgLink'><img border=0 id='puImg'></a><a class='portfolioGroup' id='puGroup'></a><a class='portfolioOutbound' id='puLink'></a><div id='puPlus'></div>");
				// add the new element at the end of the portfolio area (prototype)
				$('homePortfolioDisplay').insert(caseStudy);
			}

			// homePorfolioDisplay is the anchor for our pop up and all our thumbnails, so it will be
			// the basis for all our positions. so find its position. (prototype)			
			framePos  = $('homePortfolioDisplay').cumulativeOffset();
			// find the position of the thumbnail who called this 
			thumbPos = $('portThumb_'+ key).cumulativeOffset();
			
			var topPos = thumbPos[1] - framePos[1];
			var leftPos = thumbPos[0] - framePos[0];
			
			// now that we have the position lets set the styles.
			// this is slightly offset from the top left corner of the thumb
			caseStudy.setStyle({
				'left': (leftPos - 13) +'px',
				'top' : (topPos - 13) +'px',
				'zIndex' : 500
				});
	
			// read all the elements from the requesting object;
			var useLink = 'Link_'+ key;
			var useImage = 'Image_'+ key;
			$('puImgLink').writeAttribute({'href':$(useLink).readAttribute('href'),'target':$(useLink).readAttribute('target')});
			$('puImg').writeAttribute({'src':eval('bigThumb_'+ key +'.src')});
			$('puGroup').update($(useLink).readAttribute('rel'));
			$('puGroup').writeAttribute({'href':$(useLink).readAttribute('href'),'target':$(useLink).readAttribute('target')});
			$('puLink').update($(useLink).readAttribute('title'));
			$('puLink').writeAttribute({'href':$(useLink).readAttribute('href'),'target':$(useLink).readAttribute('target')});
			//show it
			caseStudy.show();
			
		}
		
		function hideCaseStudy() {
			$('homePortfolioThumbOn').hide();
		}

		// pre load case study bg.
		newImage('/images/bg/portfolio_home_bg_big.png');
	
	
	
	function pauseOut () {

		t = setTimeout('mainNav()',1000);

	}

	function reposeRight (id) {
	
		onItem = 'mn'+ id;
		ddItem = 'dd'+ id;
		if (self.document.getElementById(ddItem)) {
			anchor = $('outline').cumulativeOffset();
			onItemOffset = $(onItem).cumulativeOffset();
			
			elmLeft = (onItemOffset[0] - anchor[0]);
			elmTop = (onItemOffset[1] - anchor[1]) + $(onItem).getHeight();
			
			if (blog==true) {
			//	elmTop += 15;
			//	elmLeft += 33;
			}	
			
			$(ddItem).style.top = elmTop +'px';
			$(ddItem).style.left = elmLeft +'px';
		}
	//	ddTopPos = (document.getElementById('header').offsetHeight);
	//	headWidth = (document.getElementById('header').offsetWidth);
	
	//	obj = document.getElementById('dd'+ id)
		
	//	mn  = document.getElementById('mn'+ id)

	//	left = (document.getElementById('mainNav').offsetLeft + mn.offsetLeft + mn.offsetWidth);
		
	//	right = ((headWidth - left) - 42);
		
//		top.alert(right);
		
	//	obj.style.top = ddTopPos +'px';
	//	obj.style.right = right +'px';
		
	//	ddList = obj.getElementsByTagName('div')[1];
				
	//	ddList.style.height = ddList.offsetHeight;
	}

	function onLoadInit() {
		//return;
		var sizes = getWindowSize();
		if (sizes[1] > document.getElementById('outline').offsetHeight) {
			document.getElementById('backframe').style.height = sizes[1] +'px';
			document.getElementById('base').style.height = sizes[1] +'px';
			
		}
	
	}

	function getWindowSize () 
	{
		if (window.outerHeight && window.outerWidth) {// Firefox
			yWindow = window.innerHeight;
			xWindow = window.innerWidth;
	//	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	//		yWindow = document.body.scrollHeight;
	//		xWindow = document.body.scrollWidth;
		} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
			yWindow = document.body.offsetHeight;
			xWindow = document.body.offsetWidth;
		}
		arrayWindowSize = new Array(xWindow,yWindow);
		return arrayWindowSize;
	}

	function getPageSizeWithScroll()
	{
		if (window.innerHeight && window.scrollMaxY) {// Firefox
			yWithScroll = window.innerHeight + window.scrollMaxY;
			xWithScroll = window.innerWidth + window.scrollMaxX;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			yWithScroll = document.body.scrollHeight;
			xWithScroll = document.body.scrollWidth;
		} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
			yWithScroll = document.body.offsetHeight;
			xWithScroll = document.body.offsetWidth;
		}
		arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
		return arrayPageSizeWithScroll;
	}
		
		
	window.onresize = onLoadInit;
	

	function addOnLoadEvent(func) {

	  var oldonload = window.onload;
	  
	  if (typeof window.onload != 'function') {

		window.onload = func;

	  } else {

	//	top.alert(oldonload)
	//	top.alert(func)

		window.onload = function() {

		  if (oldonload) {
			oldonload();
		  }
		  eval (func +'()');

		}

	  }

	}
	

//	addOnLoadEvent(onLoadInit);
	

onImage = false

function changeImage (key) {

	if (onImage == key) {
	
	} else {
	
		if (onImage) {
			$('img'+ onImage).style.visibility = 'hidden';
			// document.getElementById('img'+ onImage).style.display = 'none';
			setClass('img'+ onImage +'btn','imgSwitchBox');
		} 

		img = 'img'+ key;
		if ($(img).getWidth() > $('imageDisplay').getWidth()) {
			$(img).style.width = $('imageDisplay').getWidth() +'px';
		}
		$('imageDisplay').style.height = ($(img).getHeight() + 30) +'px';
		
		$(img).style.visibility = 'visible';
		// img.style.display = 'inline';

		// Caption change
		imgTitle = $(img).readAttribute('title'); 
	 	
		if (imgTitle) { 	
			$('captionField').update(imgTitle);
		}	
	
		setClass('img'+ key +'btn','imgSwitchBoxOn');
		
		
		onImage = key

	}

}

function loadGallery () {

//	imageStack = document.getElementById('imageStack');
//	imageNav = document.getElementById('imageNav');
//	imageDisplay = document.getElementById('imageDisplay');
	//captionField = document.getElementById('captionField');
	$('imageNav').update('');
	$('imageDisplay').update('');
	
	//text = document.createTextNode('caption');
	//captionField.appendChild(text);
	
	images = $('imageStack').getElementsByTagName('img');


	for (i =0; i < images.length; i+=1) {
		if (i > 0) {		
			newImgDiv = Element('div',{'class':'imgSwitchDiv'}); //document.createElement('div');
			//newImgDiv.setAttribute('class','imgSwitchDiv');
			$('imageNav').appendChild(newImgDiv);	
		}
		
		newImgBtn = Element('a',{'class':'imgSwitchBox','id':'img'+ (i + 1) +'btn','href':'javascript:changeImage('+ (i + 1) +')'}); //document.createElement('div');
//		newImgBtn = document.createElement('a');
//		newImgBtn.setAttribute('class','imgSwitchBox');
//		newImgBtn.setAttribute('id','img'+ (i + 1) +'btn');
//		newImgBtn.setAttribute('href','javascript:changeImage('+ (i + 1) +')');
		$('imageNav').appendChild(newImgBtn);

		newImg = document.createElement('img');
		newImg.setAttribute('src',$(images[i]).readAttribute('src'));
		newImg.setAttribute('title',$(images[i]).readAttribute('title'));
		newImg.setAttribute('id','img'+ (i + 1) +'');
//		newImg.setAttribute('style','display:none');
		
		$('imageDisplay').appendChild(newImg);

		newImgDiv = '';
		newImgDiv = '';
		newImg = '';

	}

	changeImage(1);

}
