/*******************************************************************************
 variable declarations 
 *******************************************************************************/

// Array declerations image and text holder for use in by mutator methods
var pictures = new Array();
var text = new Array();


// misc. vars
var index_cnt = 0;
var current_picture = new Image();
var _slide = 'SLIDESIMG';
var _slide_text = 'SLIDESTEXT';

/*******************************************************************************
	IE work around for CSS;  adcloumn needs to float:right as well as a little nudge 
	the right.
*******************************************************************************/
function browser_sniffer(){

	if(navigator.userAgent.indexOf("MSIE") != -1)
	{
		document.write(" <style  type='text/css'  media='all'>");
		document.write(" #adColumn{ float:right; margin-right:20px; }" );
		document.write(" </style> ");
	}
}

/*******************************************************************************
	
	initialization function, 
	2. _imgsrc; path for image, sql results
	3. _imgtxt; caption text, sql results

		==>> needs a recursive call from outside _slideshow.js
			done with in slidehow object -> slideshow.php
*******************************************************************************/
function init(_imgSrc, _imgText){
		var path_default = '/i/slides/'
		var img_path;

		
		img_path = path_default + _imgSrc;
		
		load_Array(img_path,_imgText);
		index_cnt++;

} // end init()


/*******************************************************************************
	basic array load method
	called from init() 
*******************************************************************************/
function load_Array( _imgSrc, _imgText){
	pictures[index_cnt] = _imgSrc;
	text[index_cnt] = _imgText;
	
} // end load_Array()


/*******************************************************************************
 slide show mediator between array and slide_show()
 
 call fade Initialization method initImage() for display of seeded image
 sets timeout interval and 
 
 *******************************************************************************/

function start_show() 
{
	var temp = Math.floor(Math.random() * pictures.length);
	
	document[_slide].src = pictures[temp];
	display_text(text[temp]);
	
	initImage();
	
	setInterval("slide_show()", 8000);
} // end start_show()

/*******************************************************************************
	sets image in html to image from array.
	call initImage for fade on new image displayed.
	increments count to reset slide show loop.
	calls displaytext(); for caption display.
 *******************************************************************************/

function slide_show() 
{
		var current_text ;
		
		//image  sets
		var pic_num = Math.floor(Math.random() * pictures.length);
		
		current_picture.src =pictures[pic_num] ;
		
		// text set
		current_text = text[pic_num];

		// display image and text
		document[_slide].src = current_picture.src;
		initImage();
		display_text(current_text);
}// end slide_show()



/*******************************************************************************
	function to display text, 
	passed var text ref to text[element]
 *******************************************************************************/

function display_text(text) {
    tag =  document.getElementById(_slide_text);
   	tag.innerHTML = text;
    
  } //end display_Text()



/*******************************************************************************
	what follows is a fade effect; not so functional with IE/mac right now
	The  function still needs to find it's home in slide_show();
*******************************************************************************
*******************************************************************************
 initalizes images id for faster loading
*******************************************************************************/
function initImage() 
{
	
  imageId = _slide;
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
  
}


/*******************************************************************************
 opacity mutator per browser 

******************************************************************************/
function setOpacity(obj, opacity) 
{
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

/*******************************************************************************
 fade in function sets document.element time out and display's new Opaque image
	speed of fade is adjusted with settimeout 
*******************************************************************************/

function fadeIn(objId,opacity) 
{
  if (document.getElementById) 
  {
    obj = document.getElementById(objId);
    if (opacity <= 100) 
    {
      setOpacity(obj, opacity);
      opacity += 4;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }//end nested if
  }//end if
}

/*******************************************************************************/


	
