function initSlideShow(){
	doSlide = new Fx.Slide('slideshow_text', {duration: 500});
	doSlide.hide();
	// init slide array from xml file
	var xml_data_file = '/images/slideshow/slideshow.xml';
	default_page_load=true;
	cur_tab_id=10;
	cur_tab_img=new Image();
	cur_url='';	
	// keeps track of all intervals running if somebody gets click happy
	intQ = new Array();
	// global slide duration var (miliseconds)
	wait = 8000;
	// create xml request
	var httpObj = createRequestObject();	
	// open connection
	httpObj.open("GET",xml_data_file,true);	
	// set handler              
	httpObj.onreadystatechange = function() {					
		// check status for response
		if (httpObj.readyState == 4) {					
			if (httpObj.status == 200) {
				// parse xml rates returned (different for each browser)				
				if(window.ActiveXObject){ // If IE Windows
					var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
					xmldoc.loadXML(httpObj.responseText);
				} else {					
					var xmldoc = httpObj.responseXML;
				}
				// create array for all tab level nodes				
				tab_array = xmldoc.getElementsByTagName('tab');
				// invoke slideshow - default tab
				showTabSlides(0);			
			} else {
				alert('There was a problem with the request.');
			}
		} 
	}
	// send form values
	httpObj.send('');	
}

function fadeElem(target,action){	
	var el=$(target);
	if (action=='in'){
		var div = el.setStyles({
			display:'block',
			opacity: 0
		});		
		el.fade('in');
	} else {		
		el.fade('out');		
	}
}
	


function showTabSlides(id,img){
	if (id==0){
		cur_tab_img=new Image();
	} else {
		cur_tab_img=document.getElementById(img);
	}
	// no double selection, i.e. click the same tab twice
	if (id!=cur_tab_id){
		// this function set text and creates image queue
		setCurrentTabVals(id,img);		
		// default display (tab id = 0 in xml file)
		if (id==0 && default_page_load){
			// set indexes
			curImg=false;
			curIndx=1;
			// adjust page loaded flag
			default_page_load=false;	
			// begin transition
			startShow(wait);						
		} else {
			// just to be sure nuke all ss intervals
			for (var i=0; i < intQ.length; i++){
				clearInterval(intQ[i]);
			}
			// toggle mouseover functionality for default show
			if (id!=0){
				document.getElementById('slide_mo').onmouseover=function() {displayDefault()};
			} else {
				document.getElementById('slide_mo').onmouseover='';
			}
			//reset image index
			curIndx=0;
			if (id!=0){
				// manually set img src w/ no trans
				if (!curImg){					
					document.getElementById('img1').src=imgQ[curIndx];
					document.getElementById('img0').style.display='none';
				} else {	
					document.getElementById('img0').src=imgQ[curIndx];
					$('img0').setStyles({
						display:'block',
						opacity: 100,
						visibilty:'visible'
					});
				}
			} else {
				// manully invoke transition
				manageImgQ();
				// begin transition
				startShow(wait);
			}
		}
		// adjust selected tab val for double selection
		cur_tab_id=id;
	}		
}

function chgText(target){
	// set html within text box via global var
	if (target=='tab_text'){
		document.getElementById(target).innerHTML=cur_text+'<div align="right" class="tab_button"><a class="tab_button" href="'+cur_url+'">Launch > </a></div>';
	} else {
		document.getElementById(target).innerHTML=cur_text;
	}	
}

function chgTabText(){
	// set html within text box via global var
	document.getElementById('tab_text').innerHTML=cur_text;
}

function setCurrentTabVals(id){
	// loop over tabs and extract text and images for each node
	for (var i = 0; i < tab_array.length; i++){
		var tabNode = tab_array[i];
		// check against id of xml node
		if (tabNode.getAttribute('id')==id){
			// we now are dealing with the selected tab, init image queue for tab
			imgQ = new Array();			
			// loop over child nodes
			for (var ii=0; ii < tabNode.childNodes.length; ii++){
				/// url for tab
				if (tabNode.childNodes[ii].tagName=='url'){
					cur_url=tabNode.childNodes[ii].firstChild.data;
				}
				// text for tab
				if (tabNode.childNodes[ii].tagName=='text'){
					// set global text value
					cur_text=tabNode.childNodes[ii].firstChild.data;
					// default
					if (id==0 || default_page_load){						
						// here a tab text is displaying, so do graceful trans between the two
						if (	document.getElementById('tab_text_container').style.display!='none'){							
							// no trans option
							document.getElementById('tab_text_container').style.display='none';							
							chgText('text');							
							document.getElementById('slideshow_text').style.display='block';						
						} else {
							// change text
							chgText('text');
							// fade in text
							slideText('in');
						}							
					// everything else
					} else {													
						// ensure default text is hidden
						if (	document.getElementById('slideshow_text').style.display!='none'){							
							// setTimeout("slideText('in','tab_text_container')",1000);
							document.getElementById('slideshow_text').style.display='none';	
							setTabTextPos();								
						} else {						
							// hide text already showing
							document.getElementById('tab_text_container').style.display='none';							
							// no transition
							setTabTextPos();	
						}						
						// change text
						chgText('tab_text');	
						// hide tab text
						document.getElementById('tab_text_container').style.display='block';								
					}		
				}
				if (tabNode.childNodes[ii].tagName=='img'){
					// if image node, push to queue
					imgQ.push(tabNode.childNodes[ii].getAttribute('src'));
				}
			}
		}
	}
}

function DL_GetElementLeft(eElement)
{
    var nLeftPos = eElement.offsetLeft;          // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nLeftPos;                             // return the number calculated
}

function DL_GetElementTop(eElement)
{
    var nTopPos = eElement.offsetTop;            // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nTopPos += eParElement.offsetTop;        // appending top offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nTopPos;                              // return the number calculated
}

function setTabTextPos(){

	if (BrowserDetect.browser=="Explorer"){	
		var y = 0;
		document.getElementById('tab_text_container').style.top=y + cur_tab_img.height;
		document.getElementById('tab_text_container').style.left=cur_tab_img.offsetLeft;		
	} else {
		document.getElementById('tab_text_container').style.top=cur_tab_img.y + cur_tab_img.height + 'px';
		document.getElementById('tab_text_container').style.left=cur_tab_img.x + 'px';		
	}
}

function slideText(action){	
	if (action=='out'){
		doSlide.slideOut();
	} else {
		doSlide.slideIn();
	}
}

function gracefulTextTrans(){
	// invoke timer on when to fade text back in (i.e. after fade ut is complete)
	setTimeout("fadeText('in')",1500);
	// go on and fade it out
	fadeText('out');
}

function fadeText(action){
	if (action=='in'){
		Effect.Fade('text', { duration:.50, from:0.1, to:1.0 });	
	}
	if (action=='out'){
		Effect.Fade('text', { duration:.50, from:1.0, to:0.1 });
	}
}

function manageImgQ(){
	// load img into hidden placeholder dictated by current img's position
	if (!curImg){		
		// fade in hidden image
		document.getElementById('img1').src=imgQ[curIndx];
		// fade or change out current img, trans faster for toher tabs
		fadeElem('img0','out');//Effect.Fade('img0', { duration:.75, from:1.0, to:0.0 });		
	} else {
		// fade in hidden image
		document.getElementById('img0').src=imgQ[curIndx];		
		//should appear here, trans faster for toher tabs
		fadeElem('img0','in');//Effect.Appear('img0', { duration:.75, from:0.0, to:1.0 });			
	}
	// adjust global varibles for position and index
	if (curImg) {
		curImg=false;
	} else {
		curImg=true;
	}	
	curIndx++;		
	// need to reset the index if current is the length of the image queue		
	if (curIndx==imgQ.length){
		curIndx=0;
	}
	// if there's only one image in the queue, stop show
	if (imgQ.length==1){
		stopShow();
	}
}

// fade handler
function startShow(dur) {
	// make sure only one timer is running at a given time - then reset array
	for (var i=0; i < intQ.length; i++){
		clearInterval(intQ[i]);
	}
	intQ.length=0;
	// now set timer for current request
	intId = setInterval('manageImgQ()',dur);
	// add to interval queue to keep track of multiple timers running at once
	intQ.push(intId);
}

function stopShow() {
	clearInterval(intId);            			
}

// advance to next slide manually
function nextSlide(){
	// manually stop
	stopShow();
	// transition
	manageImgQ();
}

function lastSlide(){

	// manually stop
	stopShow();
	// go back one, unless zero
	if (curIndx==1 || curIndx == 0){
		if (curIndx == 1){
			curIndx=imgQ.length-1;
		}
		if (curIndx == 0){
			curIndx=imgQ.length-2;
		}
	} else {
		curIndx=curIndx-2;
	}

	// transition
	manageImgQ();
}

// immage rollovers
function ImgChange(imgNum,imgSrc){
	document.images[imgNum].src = imgSrc;
}

function displayDefault(){
	// user mousing off tab?
	if (	document.getElementById('tab_text_container').style.display!='none'){
		showTabSlides(0);
	}
}