var right;
var bigImage;
var thumbWrapper;
var isIphone;
window.onload=function(){

uagent=navigator.userAgent.toLowerCase();
if (uagent.indexOf("iphone") !=-1){
isIphone=true;
}



setDropdownLabel();
setTimeout(function() {
        window.scrollTo(0, 1);
    }, 0);
if (document.getElementById("select-wrapper")){
document.getElementById("select-wrapper").style.visibility="visible";
}

if (document.getElementById("section-select")){
var dropdown = document.getElementById("section-select");

dropdown.addEventListener('change', gotoSection, false);
}

if (document.getElementById("extra-images")){
	var allImages=document.getElementsByTagName("img");
	for (var x=0;x<allImages.length;x++){
	var parent=allImages[x].parentNode;
		if (parent.id=="right"){
			bigImage=allImages[x];		
		}
		if (allImages[x].parentNode.id=="extra-images"){
			//listeners:
			if(allImages[x].src==bigImage.src){
			allImages[x].className="active";
			}
			if (allImages[x].addEventListener){

				allImages[x].addEventListener('click', showThisPic, false);
			}
			if (allImages[x].attachEvent){
			
				allImages[x].attachEvent('onclick', showThisPic);
			}
		}
	}
	}
}


function setDropdownLabel(){
if (document.getElementById("select-text")){
label=document.getElementById("select-text");
str=document.getElementById("section-select").value;
//string.lastIndexOf(searchstring);
str=str.substring(str.lastIndexOf("=")+1).toUpperCase();
label.innerHTML=str;
}
}
function gotoSection(){
if (document.getElementById("section-select")){
window.location=document.getElementById("section-select").value;
}
}
function showThisPic(e){

	if (e.target){
	if (bigImage.src!=e.target.src){
	bigImage.src=e.target.src;
	if (!isIphone){
	initImage("big-image");
	}
	dimAllThumbs();
	e.target.className="active";
	}
	}
	else if (e.srcElement){
	if (bigImage.src!=e.srcElement.src){
	bigImage.src=e.srcElement.src;
	if (!isIphone){
	initImage("big-image");
	}
	dimAllThumbs();
	e.target.className="active";
	}
	}
	
}
function dimAllThumbs(){
	var allThumbs=document.getElementsByTagName("img");
	for (var x=0;x<allThumbs.length;x++){
	var parent=allThumbs[x].parentNode;
		
		if (parent.id=="extra-images"){
			allThumbs[x].className="";
		}
	}
}

//******image fade in functions by:******//
//******http://clagnut.com/sandbox/imagefades/*****//
function initImage(imageId) {
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}
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;
}
function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 5;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 20);
    }
  }
}

