/* Javascript file for Dyna Contracting */


/* some default constructs */
{

  document.pageloaded = false;

  // determine the month and year
  mydate = new Date();
	year = mydate.getYear();
	if (year < 2000)
    year = year + 1900;
	armonth = new Array("January ","February ","March ","April ","May ","June ","July ","August ","September ", "October ","November ","December ")
	var pagemonth = (armonth[mydate.getMonth()]);
  var pageyear = year;

}


/* this function is triggered by the onload handler
   on the body tag. it will perform after the page
   has loaded. this is called only from interior pages,
   the splash has its own pageloadedSplash function, below  */
function pageloaded(){

  // invoke the "equal column" script to even up the left and right columns
  setTall();

  // these are the nav active states
  preLoadImages('../images/nav/about_active.gif','../images/nav/testimonials_active.gif','../images/nav/work_active.gif','../images/nav/dynametal_active.gif','../images/nav/gettingstarted_active.gif','../images/nav/contact_active.gif','../images/nav/home_active.gif');

  document.pageloaded = true;
}


/* this function is triggered by the onload handler
   on the body tag for only the splash page. it will
   perform after the pagehas loaded.  */
function pageloadedSplash(){

  // these are the nav active states
  preLoadImages('images/nav/home/about_active.gif','images/nav/home/testimonials_active.gif','images/nav/home/work_active.gif','../images/nav/dynametal_active.gif','../images/nav/home/gettingstarted_active.gif','images/nav/home/contact_active.gif');
  document.pageloaded = true;
}

/* a utility function to dynamically swap out
   one image for another */
function switchImage(image_name,url) {

	// get the width and height of url, and apply to d
	// works in IE, not in FF
	if(!document.images) return;
	d		= document[image_name];
	if(!d) return;
	e		= new Image();
	e.src	= url;

		//var picHeight = e.getAttribute("height") // Added this line
		//var picWidth = e.getAttribute("width") // Added this line

	d.src	= url;
	//d.width = 400;
	//d.name = 'test';
	//alert(picHeight);
	// alert(d.src);
}

/* a utility function to preload images */
function preLoadImages()
{
  // preload images: pass in as many as you wish
  var images = new Array();
  for(i = 0; i<preLoadImages.arguments.length;i++)
  {
    images[i] = new Image();
    images[i].src = preLoadImages.arguments[i];
	  //alert(images[i].src);
  }
}


/* this function controls the show/hide of images
   in the featured work galleries */
window.next_image='';
function showProjectImage(url){

  /* UPDATE: client doesn't want the fade-in fade-out system Apr/07 */
  switchImage('FeaturedImage',url);
  return;

  /* the following will produce a pleasing fade-in/fade-out effect */

  if(!document.images) return;
  d=document['FeaturedImage'];
  if(!d) return;

  // if we are on the same image, don't bother with the effects
  if(window.next_image==url) return;

  // do a quick preload of the next image in preparation
  // this will help a little, as it begins loading the next image while the
  // current image fades out.
  im = new Image(); im.src=url;

  // this window variable is set because it is needed in showImage_next()
  window.next_image=url;

  // fade out current and trigger next show
  Spry.Effect.AppearFade('FeaturedImage', {duration: 700, from: 100, to: 0, toggle: false, finish: showImage_next});

}

/* helper function works in concert with showImage() to reveal the "next" image
   in the gallery */
function showImage_next(element,effect){
  element.src=window.next_image; // sets the next image
  Spry.Effect.AppearFade('FeaturedImage', {duration: 1000, from: 0, to: 100, toggle: false});
}



/* the team page has a feature where the bios "pop open" into a new "window"
   you send in the id of the div containing the team member's pop-up.
   notice that you dynamically set the background image, so that a single
   visit to team.html doesn't pull down all 20 background images at once.  */
function TeamShow(which){
  if(!(d=document.getElementById(which))) return;
  d.style.display='block';
	// allow this function to be called from other pages
	// all pages except home are one level down
	var imgdir = 'images/team/';
	if (!(document.getElementById('TeamCollage'))) {
		imgdir = '../about/images/team/';
	}
	//alert('urldir: ' + urldir);
  d.style.backgroundImage='url(' + imgdir + which + '-bg.jpg)';
 // d.style.backgroundImage='url(images/team/' + which + '-bg.jpg)';

  // IE has a precious behavior that requires we hide the
  // underlying collage, so the it won't show under the
  // team member popup. thanks ie.
  if(dd=document['TeamCollage']){
     document['TeamCollage'].src='../images/inv.gif';
  }
}
function TeamHide(which){
  if(!(d=document.getElementById(which))) return;
  d.style.display='none';
  //and restore the underlying collage image
  if(dd=document['TeamCollage']){
     document['TeamCollage'].src='images/team.gif';
  }
}


/* the testimonial page has a feature where the bios "pop open" into a new "window"
   you send in the id of the div containing the testimonial's pop-up. */
function TestimonialShow(which){
  if(!(d=document.getElementById(which))) return;
  d.style.display='block';
  //d.style.backgroundImage='url(images/team/' + which + '-bg.jpg)';
}
function TestimonialHide(which){
  if(!(d=document.getElementById(which))) return;
  d.style.display='none';
}


/* navigation system uses a common javascript function to flip the
   nav panels onmouseover and onmouseout. type=0 means go back to normal,
   type=1 means flip to active. which is the id of the nav panel */
function flipNav(which,type){
   if(!document.images) return;
   if(!(d=document['nav'+which])) return;
   if(type!=0)
     d.src='../images/nav/'+which+'_active.gif';
   else
     d.src='../images/nav/'+which+'.gif';
}
/* splash is very similar, just a little different image path */
function flipNavHome(which,type){
   if(!document.images) return;
   if(!(d=document['nav'+which])) return;
   if(type!=0)
     d.src='images/nav/home/'+which+'_active.gif';
   else
     d.src='images/nav/home/'+which+'.gif';
}


/* splash page uses JS to write the flash object, to avoid the pleasant
   IE "click me to activate" issue */
function writeUpperRedLine(){
   buf='';
   buf+="<div id='UpperRedLine'><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='899' height='4' id='SliceLtoR' align='middle'>";
   buf+="   <param name='allowScriptAccess' value='sameDomain' />";
   buf+="   <param name='movie' value='images/flash/SliceLtoR.swf' />";
   buf+="   <param name='loop' value='false' />";
   buf+="   <param name='quality' value='high' />";
   buf+="   <!--<param name='bgcolor' value='#d4d0c8' />-->";
   buf+="   <param name='wmode' value='transparent' /> ";
   buf+="   <embed src='images/flash/SliceLtoR.swf' loop='false' quality='high' wmode='transparent' x-bgcolor='#d4d0c8' width='899' height='4' name='SliceLtoR' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
   buf+="   </object></div>";

   document.writeln(buf);
}
