var picList;
var currentPic;
var slideShowEnable;
var toID;
var startDelay;
var nextDelay;
var bScrollWin;
var preloadEnable;

function addPic(_href)
{
	picList[picList.length] = _href;
}

function initPicList()
{
	initPicList(true);
}

function init_PicList ( loadLinks )
{
	picList = [];
	currentPic = -1;
	slideShowEnable = false;
	preloadEnable = false;
	bScrollWin = true;
	startDelay = 1000;
	nextDelay = 5000;

	if (loadLinks == true)
   {
		var linkStr;
		var browser = new String(navigator.appName);

		//alert("Link 8: " + document.links[8].href);
		//alert("Browser: " + browser);
		for (var i=0; i<document.links.length; i++)
		{
			if (browser.indexOf("Explorer") > 0)
				linkStr = new String(document.links[i].href);
			else
				linkStr = new String(document.links[i].pathname);

			if (linkStr.indexOf(".jpg") > 0 || linkStr.indexOf(".JPG") > 0)
			{
				addPic(linkStr);
			}
		}

	// Start slideshow automatically
	//slideShowEnable = true;
	//showNextPicSlide ( )	;
	showNextPic( );
	}
}


function showPicHREF(_href)
{
	document.getElementById('placeholder').src = _href;
}

function setCurrentPic(_href)
{
	if (picList == null)
		return;
	for (var i=0; i<picList.length; i++) 
	{
		if (_href.indexOf(picList[i]) > 0 || _href == picList[i])
		{
			currentPic = i;
			break;
		}
	} 
}

function showPic (whichpic) 
{
	//alert(whichpic.href);
	stopSlideshow();
	if (bScrollWin == true)
		window.scrollTo(0,80);
	if (document.getElementById) 
	{
		showPicHREF(whichpic.href);
		setCurrentPic(whichpic.href);
  		//return false;
 	} 
	else 
	{
  		//return true;
 	}
	return false;
}

function showPicNum( picNum )
{
	if (picNum >= 0 && picNum < picList.length)
		showPicHREF(picList[currentPic]);
}

function showNextPic ( )
{
	stopSlideshow();
	if (currentPic < (picList.length-1))
		currentPic = currentPic + 1;
	else // wrap around
		currentPic = 0;

	showPicNum(currentPic);	
	return false;
}

function showPrevPic ( )
{
	stopSlideshow();
	if (currentPic > 0)
		currentPic = currentPic - 1;
	else
		currentPic = picList.length-1;
	
	showPicNum(currentPic);
	return false;
}


function showNextPicSlide ( )
{
	if (currentPic < (picList.length-1))
		currentPic = currentPic + 1;
	else // loop around
		currentPic = 0;

	showPicNum(currentPic);	

	// preload next picture
	if (preloadEnable == true)
	{
		imageObj = new Image();
		if ((currentPic + 1) < (picList.length-1))
			imageObj.src = picList[currentPic + 1]; 
		else
			imageObj.src = picList[0];  
	}

	if (slideShowEnable == true)
		toID = setTimeout('showNextPicSlide()', nextDelay);
	return false;
}

function startSlideshow( )
{
	if (slideShowEnable == false)
	{
		slideShowEnable = true;
		setTimeout('showNextPicSlide()', startDelay);
	}
	return false;
}

function stopSlideshow( )
{
	clearTimeout(toID);
	slideShowEnable = false;
}

function sizeupPic( img, ratio )
{
	alert("sizeup: " + img);
	img.width = img.width * ratio;
	img.height = img.height * ratio;
	return false;
}

function sizednPic( img, ratio )
{
	img.width = img.width / ratio;
	img.height = img.height / ratio;
	return false;
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function queryString(parameter) { 
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;
  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name == parameter) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {
      return param_value;
  }
  else {
      return ""; //Here determine return if no parameter is found
  }
}



