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 MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_findObj(n, d) { //v3.0

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}



function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}



function MM_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}



function is_nav5_or_up()

// ----------------------------------------------------------------------------

// Based on:

// Ultimate client-side JavaScript client sniff.

// (C) Netscape Communications 1999. Permission granted to reuse and distribute.

// Revised 17 May 99 to add is_nav5up and is_ie5up (see below). //

// http://developer.netscape.com/docs/examples/javascript/browser_type.html

// ----------------------------------------------------------------------------

{

  var agt=navigator.userAgent.toLowerCase();

  var is_major = parseInt(navigator.appVersion);

  var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)

        && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)

        && (agt.indexOf('webtv')==-1));

  var is_nav5up = (is_nav && (is_major >= 5));

  return is_nav5up;

}



//this function sets the dom reference for the browser type

//and setting the way in which the layer will be referenced depending on the browser.

// document.all -- internet explorer

// document.layers -- ns4.x

// document.getElementById -- ns6 (can also be used by ie5)

function changeIt(layName)

{

  if(document.all)

    return document.all(layName).style; 

  else if(document.layers)

    return document.layers[layName];

  else if (is_nav5_or_up())

    return document.getElementById(layName);

}





/* 

WM_moveLayer() 

Moves an object from its current location to a new location and optionally fires a function when it's done. 

Original Source: Webmonkey Code Library 

(http://www.hotwired.com/webmonkey/javascript/code_library/) 

Has since been modified to incorporate the netscape 6 browser.

Usage: WM_moveLayer('layerIDName', endingLeft, endingTop, numberOfSteps, delayBetweenSteps, 'functionToFire()'); 

*/ 

function WM_moveTo (layerIdName, endLeft, endTop, numSteps, delay, endFunction) { 

  // Declare variables. 

  var leftInc, topInc, daObj = new Object; 

  // The first time through, create document.WM.WM_moveLayer 



  if (typeof document.WM == 'undefined'){ 

    document.WM = new Object; 

    document.WM.WM_moveLayer = new Object; 

  } else if (typeof document.WM.WM_moveLayer == 'undefined') { 

    document.WM.WM_moveLayer = new Object; 

  } 

  // Store endFunction to execute when the move is finished. 

  if(endFunction) document.WM.WM_moveLayer.endFunction = endFunction; 

  // Get a good object reference (call it daObj) from WM_checkIn(). 

  // But if we've already done so, don't check it in again. 

    if (layerIdName == "sameObj") { 

      daObj = document.WM.WM_moveLayer.daObj; 

    } else { 

      daObj = changeIt(layerIdName); 

      document.WM.WM_moveLayer.daObj = daObj; 

    } 

  // If this is the last step, go to the end point and run endFunction. 

  if (numSteps == 1) { 

    if (is_nav5_or_up()) { // For w3c compliant browsers 

      daObj.style.left = endLeft; 

      daObj.style.top = endTop; 

    } else { 

      daObj.left = endLeft; 

      daObj.top = endTop; 

    } 

    // If an endFunction was set, execute it and then delete it. 

    if(document.WM.WM_moveLayer.endFunction) { 

      daFunction = document.WM.WM_moveLayer.endFunction; 

      document.WM.WM_moveLayer.endFunction = ''; 

      eval(daFunction); 

    } 

  } else { 

    // Otherwise, figure out how far to move. 

    if (is_nav5_or_up()) { // For w3c compliant browsers 

      leftInc = (endLeft - parseInt(daObj.style.left)) / numSteps; 

      topInc = (endTop - parseInt(daObj.style.top)) / numSteps; 

    } else { 

      leftInc = (endLeft - parseInt(daObj.left)) / numSteps; 

      topInc = (endTop - parseInt(daObj.top)) / numSteps; 

    } 

    // Then move, decrement numSteps, and do it all again. 

    if (is_nav5_or_up()) { // For w3c compliant browsers 

      daObj.style.left = parseInt(daObj.style.left) + leftInc; 

      daObj.style.top = parseInt(daObj.style.top) + topInc; 

    } else { 

      daObj.left = parseInt(daObj.left) + leftInc; 

      daObj.top = parseInt(daObj.top) + topInc; 

    } 

    numSteps--; 

    setTimeout ('WM_moveLayer(\'sameObj\', ' + endLeft + ', ' + endTop + ', ' + numSteps + ', ' + delay + ')', delay); 

  } 

} 



/* begin toggle div tags  */

function toggleVisibility() {
  var inc, endInc=arguments.length;
  for (inc=0; inc<endInc; inc+=2) {
    var id = arguments[inc];
    if (arguments[inc+1] == 'hidden') param = "hidden";
    else if(arguments[inc+1]=='visible') param = "visible";
    if (document.layers) document.layers['container'].layers[id].visibility = param;
    else if (document.all) eval("document.all." + id + ".style.visibility = \"" + param + "\"");
    else if (document.getElementById) eval("document.getElementById(id).style.visibility = \"" + param + "\"");
  }
}



function toggledivs() {
  var inc, endInc=arguments.length;
  for (inc=0; inc<endInc; inc+=2) {
    var id = arguments[inc];
    if (arguments[inc+1] == 'none') param = "none";
    else if(arguments[inc+1]=='block') param = "block";
    if (document.layers) document.layers['container'].layers[id].visibility = param;
    else if (document.all) eval("document.all." + id + ".style.display = \"" + param + "\"");
    else if (document.getElementById) eval("document.getElementById(id).style.display = \"" + param + "\"");
  }
}


function getElementsByClass(searchClass,node,tag) {
  // This function gets the elements that all share a class name
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function an_toggleDisplay(theid) {
	// This function toggles between the tabs and the corresponding content for the tabs.  The tabs <li> must correspond 1-1 with the order of the content UL content elements.
	// if your 3rd tab is "tab for content z" then ensure that your UL for the content is placed as the 3rd element.
	// we could give the tabs an id in order to match the id of the actual content, but it was kept this way in order to save on logic processing time and added code to the HTML (yet more id's to keep track of).
  
	var contentelmt = getElementsByClass('hide');
	var tabelmt = getElementsByClass('litab');
	var match = false;
		for (i = 0; i < contentelmt.length; i++) {
			if (theid == contentelmt[i].id) {
				match = true;
				contentelmt[i].style.display = "block";
				tabelmt[i].className ="litab active";
			}
			else {
				contentelmt[i].style.display = "none";
				tabelmt[i].className = "litab";			
			}		
		}
		if (!match) {
			contentelmt[0].style.display = "block";
			tabelmt[0].className="litab active";
		}
}


/* end toggle div tags */


try {
	siteurl = siteurl;
	}
	catch(e) {
			siteurl = "../";
	}
function returnOnOff(thesection,menunumber) {
	var sectionMatch = "";
	myString = new String(location.href);
	myRE = new RegExp(thesection + ".html", "i");
	results = myString.match(myRE);
	if (results != null) {
		sectionMatch = "-on";
	}
	document.write ('<li class="img-pad' + sectionMatch + '">');

}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var trackFromFlash = function(url) {
	pageTracker._trackPageview(url);
};

// var openGallery = function (href) {
//   if ($.cookie && href)
//   {
//     // Handle case where sometimes browsers don't include the leading /
//     var pathname = ( href.pathname.substr(0, 1) == '/' ) ? href.pathname : '/' + href.pathname;
//     $.cookie('gallery_state', pathname, { path: '/' });
//   }
//   $('#ToolBar a.thickbox').click();
//   return false;
// };

// $(function() {
//   if ($.cookie)
//   {
//     if ($.cookie('gallery_reopen'))
//     {
//       var href = $.cookie('gallery_reopen');
//       $('a').each(
//         function() {
//           if (this.href == href)
//             $(this).click(function () { $.cookie('gallery_reopen', '', { path: '/' }); });
//         }
//       );
//       if (window.location.href == $.cookie('gallery_reopen'))
//       {
//         $.cookie('gallery_reopen', null, { path: '/' });
//         $('#ToolBar a.thickbox').click();
//       }
//     }
//   }
//   if (window.location.href.indexOf("?show-gallery") != -1)
//     $('#ToolBar a.thickbox').click();
// });

// Tabs - hide tabs before initialization to avoid flash of content
// Add styles via JavaScript for graceful degradation...
document.write('<style type="text/css" media="projection, screen">.fragment { display: none; }</style>');

$(function() {
	$("#container-1 ul.anchors").tabs(); // Activate tabs
});	

// Convert un-tabbed display into tabbed display and activate tabs
$(document).ready(function() {
	var $tabs = $('div.tabsPreSetup');
	var $tabnav = $tabs.prepend('<ul class="tabNav anchors selfClear"></li>').find('> ul');
	$tabs	.find('> div')
				.each( function(i) {
					var id = this.id;
					var $h2 = $(this).find('h3');
					var title = $h2.html();
					$tabnav.append('<li><a href="#' + id + '" class="noPopup"><span>' + title + '</span></a></li>');
					$h2.remove();
				});
	// Need delay for browsers to get their DOM in order
	setTimeout(function() { $tabs.tabs(); }, 500);

	// Only move to the top of the page when the tabs are present so not to affect real anchor links.
	var tabsPresent = $('div.tabsPreSetup').size(this);
	if (tabsPresent > 0)
	{
		// Move to the top of the page
		window.scrollTo(0,0);
	}

	$tabs.removeClass('tabsPreSetup');
});

var $dialog;
var swfobject;

$('.ui-widget-overlay').live('click', function(event) {
	if ($dialog) {
		$dialog.dialog('close');
	}
});

var Gallery = {
	id: 'GalleryContainer',
	init: function() {
		$('a.gallery,area.gallery').click(Gallery.click);
	},
	click: function(event) {
		event.preventDefault();
		$div = $('#' + Gallery.id);
		if ($div.length == 0) {
				$div = $('<div id="' + Gallery.id + '" style="display: none;"></div>').appendTo('body');
		}
		$div.load(this.href + ' div.modalContent', Gallery.showDialog);		
	},
	showDialog: function() {
		$div = $('#' + Gallery.id);
		if ($div.length == 0)
			return;
		
		var flashVars = {
			initialURL: escape(document.location),
			xmlfile: '/gallery_v2/images.xml'
		};
		var flashParams = {
			quality: "high",
			wmode: "transparent",
			menu: "false",
			allowScriptAccess: "sameDomain",
			allowFullScreen: "true"
		};
		var flashAttributes = {}
		if (swfobject) {
			swfobject.embedSWF('/gallery_v2/slideshow.swf', 'Gallery', 960, 800, '9.0.0.0', '/gallery_v2/expressinstall.swf', flashVars, flashParams, flashAttributes);
		}
		$dialog = $div.dialog({
				draggable: false,
				modal: true,
				bgiframe: true,
				width: 960,
				height: 830,
				closeText: 'Return to AtreNet Site',
				resizable: true,
				title: 'AtreNet Gallery',
		   	open: function(event, ui) { }
		}).dialog('open');		
	}
}

$(function() { 
	Gallery.init(); 
	// Check if 'launchGallery' is in the query string
	var launchGallery = $.query.get("launchGallery"); 
	if (launchGallery)
	{
		// Launch the gallery if 'launchGallery' is found in the query string
		$('#ToolBar a.gallery').click();
	}
});
