// IE7 z-index issues fix
$(function() {
	var zIndexNumber = 1000;
	$('#footer').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
});



function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}



$(document).ready(function(){
	$("a.external").attr('target','_blank');
});

//
//$(document).ready(function() {
//$(function() {  
//    $("#grey-bar h2").truncate( 85 ); //90  	
//});
//})

$(document).ready(function() {
$("a[href*=.pdf]").click(function(){
	window.open(this.href);
	return false;
});

})

function bookmark(title,url)
{

if (window.sidebar) // firefox
window.sidebar.addPanel(title, url, '');
else if(window.opera && window.print){ // opera
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.click();
}
else if(document.all)// ie
window.external.AddFavorite(url, title);

}

function slideExample2(elementId, headerElement)
{
   var element = document.getElementById(elementId);
   if(element.up == null || element.down)
   {
      animate(elementId, 20, 0, 0, 150, 250, null);
      element.up = true;
      element.down = false;
      headerElement.innerHTML = '';
   }
   else
   {
      animate(elementId, 20, 0, 130, 150, 250, null);
      element.down = true;
      element.up = false;
      headerElement.innerHTML = '';
   }
}

// hover effect for left nav menu
//  $(document).ready(function(){
//    $(".level-one a").hover(function() {
//    $(this).animate({ backgroundColor: "#e8e8e8" }, 1000);
//},function() {
//    $(this).animate({ backgroundColor: "#f8f8f6" }, 500);
//});
//
//  });
  
  
  
 
// Slide Effect on Publications  
$(document).ready(function(){
	$(".btn-slide").click(function(){
	  $("#panel").animate({
	  "width": "toggle", "opacity": 1
	}, { duration: "fast" }	
	);	
  });
});

// Remove Focus
$(document).ready(function(){
$("p.slide a").click(function() {
  $(this).blur();
});
 });




// Scroller on Publications
scrollStep=1

timerUp=""
timerDown=""

function toTop(id){
document.getElementById(id).scrollTop=0
}

function scrollDivDown(id){
clearTimeout(timerDown) 
document.getElementById(id).scrollTop+=scrollStep
timerDown=setTimeout("scrollDivDown('"+id+"')",15)
}

function scrollDivUp(id){
clearTimeout(timerUp)
document.getElementById(id).scrollTop-=scrollStep
timerUp=setTimeout("scrollDivUp('"+id+"')",15)
}

function toBottom(id){
document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
}

function stopMe(){
clearTimeout(timerDown) 
clearTimeout(timerUp)
}

/* Slide Tabs */

	  // When the document loads do everything inside here ...
	  $(document).ready(function(){
		
		// When a link is clicked
		$("a.tab").click(function () {
			
		
			// switch all tabs off
			$(".active").removeClass("active");
			
			// switch this tab on
			$(this).addClass("active");
			
			// slide all content up
			$(".tabs-content").slideUp();
			
			// slide this content up
			var content_show = $(this).attr("title");
			$("#"+content_show).slideDown();
		  
		});
	
	  });

function slidetabs(contenttab)
{

// When a link is clicked
		$(document).ready(function(){
		
		// When a link is clicked
		// switch all tabs off
			$(".active").removeClass("active");
			
			// switch this tab on
			$(document.getElementById(contenttab)).addClass("active");
						
			// slide all content up
			$(".tabs-content").slideUp();
			
			// slide this content up
			var content_show = $(document.getElementById(contenttab)).attr("title");
			$("#"+content_show).slideDown();


	  });

}	  
	  
	  /* Image Caption */

//Get Element by Class Name from: http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}


//Function for converting title tags on images into caption

function addCaption(xClass) {
	var allImages = getElementsByClassName(document, "img", xClass);
	for ( var i=0; i < allImages.length; i++) {
		var imageCaption = document.createTextNode(allImages[i].title);
		var imageContainer = document.createElement("div");
		var imagePara = document.createElement("p");
		var imageWidth = allImages[i].getAttribute("width");
		var spareSpan = document.createElement("span"); //This adds an extra span. Useful for curved corners
		imagePara.appendChild(imageCaption);
		allImages[i].parentNode.insertBefore(imageContainer, allImages[i]);
		imageContainer.appendChild(allImages[i]);
		if ( allImages[i].title != "" ) {
		imageContainer.appendChild(imagePara); 
		}
		imageContainer.appendChild(spareSpan);		
		imageContainer.className = xClass
		spareSpan.className = "spareSpan"
		allImages[i].className = "imgCaption"
		imageContainer.style.width = imageWidth + "px";
		
    }
}




// Runs all the listed functions on the loading of the window

window.onload=function(){
addCaption("imgLeft");
addCaption("imgRight");
}



/* Zebra Styling on Table class - general */
/*$(document).ready( function() {
      $("table.form").find("tr:nth-child(even)").each(
        function(i) {
          if( 0 == $(this).find("th").length ) {
            $(this).addClass("even");
          }
        }
      );
    } ); */


/*$(document).ready(function(){
$(".form tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
$(".form tr:even").addClass("alt");
});*/



/* Download documents style */
$(document).ready(function(){

	$("a[@href$=pdf]").addClass("pdf");
	
	$("a[@href$=xls]").addClass("xls");
	
	$("a[@href$=doc]").addClass("word");
	
	$("a[@href$=ppt]").addClass("ppt");

});

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	// repeat the same tests as above for selects
	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	// repeat the same tests as above for textarea
	var selects = document.getElementsByTagName("textarea");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}
addLoadEvent(prepareInputsForHints);
