// JavaScript Document

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function preLoad(){
	MM_preloadImages('images/btn_corp_f2.jpg','images/btn_prod_f2.jpg','images/btn_how_f2.jpg','images/btn_client_f2.jpg','images/rtNav_airForce_f2.jpg','images/rtNam_hunterDouglas_f2.jpg','images/rtNav_marineCorp_f2.jpg');
//	setupDate();
	makeShadows(document);
	makeHeaders(document);
}

var day=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var month=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	
function calcTime(){
	var now=new Date();
	var seconds=now.getSeconds()<10?'0'+now.getSeconds():now.getSeconds();
	var minutes=now.getMinutes()<10?'0'+now.getMinutes():now.getMinutes();
//	var timeStr=now.getHours()>12?(now.getHours()-12)+':'+minutes+':'+seconds+' PM':now.getHours()+':'+minutes+':'+seconds+' AM';
	var timeStr=now.getHours()>12?(now.getHours()-12)+':'+minutes+' PM':now.getHours()+':'+minutes+':'+seconds+' AM';
	var dayStr=day[now.getDay()]+', '+month[now.getMonth()]+' '+now.getDate()+', '+now.getFullYear()+'&nbsp;&nbsp;-&nbsp;&nbsp;'+timeStr;
	return dayStr;
}
function updateTime(){
	document.getElementById('currentTime').innerHTML=calcTime();
}
	
function setupDate(){
	if (document.getElementById) setInterval('updateTime()',60000);
}

var opac=99; imgIdx=1; frmNum=4; prvIdx=new Array(1,1,2,3,4); //numPics=4;

function startCycle(){
	setTimeout('cycle()',2000)
	preLoad();
 }
 
function cycle(){
	while (imgIdx==prvIdx[1]||imgIdx==prvIdx[2]||imgIdx==prvIdx[3]||imgIdx==prvIdx[4]){
		imgIdx=Math.round(Math.random()*(numPics-1))+1;
	}
	timr2=setInterval('imgFadeDown('+ prvIdx[frmNum] +','+ imgIdx+')',5);
	prvIdx[frmNum]=imgIdx;
}

function imgFadeDown(prev,next){
	if (opac==99){
		prevObj=eval('document.images.img' + frmNum + prev).style;
		nextObj=eval('document.images.img' + frmNum + next).style;
		nextObj.visibility='visible';
	}
	if (opac>0){
		opac-=3;
		opacOther=opac/100;
		prevObj.filter='alpha(opacity='+opac+')';
		nextObj.filter='alpha(opacity='+(99-opac)+')';
		prevObj.MozOpacity=opacOther;
		nextObj.MozOpacity=(.99-opacOther);
		prevObj.opacity=opacOther;
		nextObj.opacity=(.99-opacOther);
		prevObj.KhtmlOpacity=opacOther;
		nextObj.KhtmlOpacity=(.99-opacOther);
	} else {
		prevObj.visibility='hidden';
		opac=99;
		frmNum=frmNum==1?4:frmNum-1;
		clearInterval(timr2);
		setTimeout('cycle()',1000)
	}
}

var dx, timr, timr2, prevIdx=1; nextOK=true; opac2=0;

function smoothUp(sz){
	with (document.getElementById('scroller').style){
		if (parseInt(top)>-(sz-379)){
			top=(parseInt(top)-5) + 'px';
		} else {
			clearInterval(timr);
		}
	}	
}

function smoothDown(){
	with (document.getElementById('scroller').style){
		if (parseInt(top)<0){
			top=(parseInt(top)+5) + 'px';
		} else {
			clearInterval(timr);
		}
	}	
}

function slideUp(sz){
	with (document.getElementById('scroller').style){
		if (parseInt(top)>=-sz){
			timr=setInterval('smoothUp('+sz+')',5);
		}
	}
}

function slideDown(){
	with (document.getElementById('scroller').style){
		if (parseInt(top)<0){
			timr=setInterval('smoothDown()',5);
		}
	}
}

var opac2=0, fadeTimr

function reveal(objID){
	with (document.getElementById(objID).style) {
	  if (opac2<99) {
		visibility='visible';
		opac2+=33;
		opacOther=opac2/100;
		filter='alpha(opacity='+opac2+')';
		MozOpacity=opacOther;
		opacity=opacOther;
		KhtmlOpacity=opacOther;
	  } else {
	  	clearInterval(fadeTimr);
	  }
	}
}

function fade(objID){
	with (document.getElementById(objID).style) {
	  if (opac2>0) {
		opac2-=33;
		opacOther=opac2/100;
		filter='alpha(opacity='+opac2+')';
		MozOpacity=opacOther;
		opacity=opacOther;
		KhtmlOpacity=opacOther;
	  } else {
	  	clearInterval(fadeTimr);
		visibility='hidden';
	  }
	}
}

function showWin(){
  with (document.getElementById('framePhoto').style){
	top=(document.all?document.body.scrollTop+00:window.pageYOffset+00) + 'px';
	//top=(screen.availHeight/2-164) + (document.all?document.body.scrollTop:window.pageYOffset) + 'px';
	//left=(screen.availWidth/2-275) + 'px';
	visibility='visible';
  }
}

function hideWin(){
	document.getElementById('framePhoto').style.visibility='hidden';
}

function hideAll(num){
	for (i=1;i<=num;i++){
		document.getElementById('big' + i).style.display='none';
	}
}

function expand(imgsOnPage, imgID){
	hideAll(imgsOnPage); 	
	showWin(); 
	document.getElementById(imgID).style.display='block'; 
}

/*-----------------------------------DROP SHADOW CODE------------------------------------------------------------*/

	var colors=new Array('#f5f5f5','#e1e1e1','#c2c2c2','#999999','#666666','#3e3e3e','#1f1f1f','#0b0b0b')
	
	function makeShadows(node){
		  if (node.hasChildNodes) {
				var iteration;
				for (iteration=0;iteration<node.childNodes.length;iteration++) {
					makeShadows(node.childNodes[iteration]);
				}
		  }
		  
		  if (node.getAttribute&&(sty=node.getAttribute('dropshadow'))){

				var n=node;
				n.style.position='relative';
				
				if (parseInt(n.offsetWidth)!=0){  
				
					elWidth=n.offsetWidth;
					elHeight=n.offsetHeight;
					
				} else {  //ROUTINE TO DETERMINE SIZE OF display:none ELEMENTS
				
					var elTemp=document.createElement('div');
					elTemp.style.position='absolute';
					elTemp.style.visibility='hidden';
					document.body.insertBefore(elTemp,document.body.firstChild);
					nodeTemp=n.cloneNode(true);
					elTemp.appendChild(nodeTemp);
					elWidth=nodeTemp.offsetWidth;
					elHeight=nodeTemp.offsetHeight;
					elTemp.parentNode.removeChild(elTemp);
				
				}
					
				if (sty=='text'){  // INDIVIDUAL DROP SHADOWS FOR TEXT 
				
					var b2=document.createElement('div');
						b2=n.cloneNode(true);
						b2.style.position='absolute';
						b2.className='shadow';
						
					if (!document.all || window.opera){
					
						b2.style.top='4px';
						b2.style.left='4px';
						
					} else {
					
						b2.style.top='-2px';
						b2.style.left='-2px';
						
					}
						
					n.insertBefore(b2,n.firstChild);
					
					if (window.opera){  // OPERA FIX
					
						b2.style.color='#dedede';
						opFix=document.createElement('span');
						opFix.style.position='relative';
						opFix.appendChild(b2.nextSibling);
						opFix.style.zIndex='10';
						n.appendChild(opFix);
						
					}
				
				} else if (sty=='box') {   // DROP SHADOWS FOR BLOCK ELEMENTS
					
					var b=document.createElement('div');
						b.style.width=elWidth+'px';
						b.style.position='relative';
					var b1=document.createElement('div');
						b1.className='dropHolder';
						b1.style.width=(elWidth+6)+'px';
						b1.style.height=(elHeight+6)+'px';
						
					n.parentNode.replaceChild(b,n);
					b.appendChild(b1);
					b.appendChild(n);
					n.style.zIndex='20';
	
					if (document.all && !window.opera){
	
							a=document.createElement('div');
							a.style.width=(elWidth-6)+'px'
							a.style.height=(elHeight-6)+'px'
							b1.appendChild(a);
							a.className='shadow';
							a.style.border='1px solid  black';
							a.style.backgroundColor='black';
						
					}else{
					
						for (j=0;j<8;j++){
							a=document.createElement('div');
							a.style.width=(elWidth-8+j*2)+'px'
							a.style.height=(elHeight-8+j*2)+'px'
							a.style.top=(7-j)+'px'
							a.style.left=(7-j)+'px'							
							a.className='shadow2';
							if (window.opera &&parseInt(window.opera.version())<9) 	a.style.borderColor=colors[6-j];
							a.style['opacity']=((7-j)/10-j/100);
							a.style['-moz-opacity']=(7-j)/10-j/100;
							a.style['-khtml-opacity']=(7-j)/10-j/100;

							b.insertBefore(a,b.firstChild);
							
						}
					 }
				 }
		    }	
		}

/*-----------------------------------GALLERY SCRIPT----------------------------------*/

	function showBig(bigImg){
		with (document.getElementById('curtain').style){
			width=document.body.scrollWidth+'px';
			height=document.getElementById('htTest').offsetHeight+'px';
			display='block';
		}
		document.getElementById('progressIndicator').src='images/progress-indicator.gif';
		var yPos=document.body.offsetHeight/2-document.getElementById('indHolder').offsetHeight/2+(window.pageYOffset ? window.pageYOffset : (document.documentElement.scrollTop!=0?document.documentElement.scrollTop:document.body.scrollTop));
		document.getElementById('indHolder').style.top=yPos+'px';
		document.getElementById('indHolder').style.visibility='visible'
		setTimeout(function(){loadImage(bigImg)},10);
		
	}
		
	function loadImage(bigImg){
		var imgHolder=document.createElement('div');
			imgHolder.style.position='absolute';
			imgHolder.style.left='0px';
			imgHolder.style.zIndex='12';
			imgHolder.style.width='100%';
			imgHolder.style.visibility='hidden';
			imgHolder.style.textAlign='center';
			imgHolder.style.color='#FFFFFF';
			imgHolder.style.fontFamily='arial';
			imgHolder.style.fontSize='9pt';
			imgHolder.id='imgHolder';
			imgHolder.onclick=function (){release()};
			document.body.appendChild(imgHolder);
		var newImg=document.createElement('img');
			newImg.onload=function() {placePicture(newImg)};
			newImg.src='userimages/' + bigImg;
	}
	
	function placePicture(newImg2){
		newImg2.onload='';
		document.getElementById('indHolder').style.visibility='hidden';
		document.getElementById('imgHolder').appendChild(newImg2);
		newImg2.setAttribute('dropshadow','box');
		var closer1=document.createElement('div');
		var closer=document.createTextNode('[ CLOSE ]');
		closer1.appendChild(closer);
		closer1.style.marginTop='2px';
		closer1.style.cursor='default';
		document.getElementById('imgHolder').appendChild(closer1);
		var yPos=document.body.offsetHeight/2-document.getElementById('imgHolder').offsetHeight/2+(window.pageYOffset ? window.pageYOffset : (document.documentElement.scrollTop!=0?document.documentElement.scrollTop:document.body.scrollTop));
		document.getElementById('imgHolder').style.top=yPos + 'px';
		newImg2.style.border='20px solid white';
		document.getElementById('imgHolder').style.visibility='visible';
		if (document.all && !window.opera) makeShadows(document.getElementById('imgHolder'));
	}
	
	function release(){
		document.getElementById('curtain').style.display='none';
		document.getElementById('indHolder').style.visibility='hidden';
		document.body.removeChild(document.getElementById('imgHolder'));
	}

/*-------------------------HEADLINE GLOW-------------------------*/

	function makeHeaders(node){

		  if (node.hasChildNodes) {
				var iteration;
				for (iteration=0;iteration<node.childNodes.length;iteration++) {
					makeHeaders(node.childNodes[iteration]);
				}
		  }
		  
		  if (node.tagName=='H1'){
		  		var nodeText=node.innerHTML;
				node.innerHTML='';
				var x=document.createElement('div');
				x.innerHTML=nodeText;
				x.style.filter='none';
				x.style.opacity='1';
				x.style.left='0px';
				x.style.top='0px';
				x.style.color='white';
				node.insertBefore(x,node.firstChild);
				var x=document.createElement('div');
				x.innerHTML=nodeText;
				x.style.filter='none';
				x.style.opacity='1';
				x.style.left='2px';
				x.style.top='2px';
				x.style.color='black';
				node.insertBefore(x,node.firstChild);
				for (i=0;i<360;i=i+20){
					var x=document.createElement('div');
					x.style.top=Math.sin(i)*5+'px';
					x.style.left=Math.cos(i)*5+'px';
					x.innerHTML=nodeText;
					node.insertBefore(x,node.firstChild);
				}
		  }

	}

window.onload=preLoad;