//Title: 	Global Javascript Functions for LegionMagazine.com 
//Author:	jay.west
//Contact:	creative@jaywest.com
//Updated:	January 5, 2008  


// Opens a link in a new window when class = external

function doPopups() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("external")) {
      links[i].onclick = function() {
        window.open(this.href);
        return false;
      }
    }
  }
}


// Sets the class of an input field to "fieldFocus" on focus or removes the className on blur.
// Will also clear the default field contents

function findField() {
  if (!document.getElementsByTagName) return false;
  var fieldList = document.getElementsByName("s");
  for ( var i=0; i < fieldList.length; i++) {
    fieldList[i].onfocus = function() {
      this.className ="txtKeywords fieldFocus";
	  this.value = "";
    }
	fieldList[i].onblur = function() {
      this.className ="txtKeywords";
    }
  }
}

function setupCaptions()
{
	
	var featured_image = document.getElementById("featured_image");
	var caption = document.getElementById("featured_source_text");
	
	if(caption != null)
	{
		caption.style.display = "none";
		featured_image.onmouseover = function() { showCaption() };
		featured_image.onmouseout = function() { hideCaption() };
	}
}

function showCaption()
{
	var caption = document.getElementById("featured_source_text");
	if(caption != null)
	{
		caption.style.display = "block";
	}
}

function hideCaption()
{
	var caption = document.getElementById("featured_source_text");
	if(caption != null)
	{
		caption.style.display = "none";
	}
}

// Run the functions once the page has loaded: 

window.onload=function(){
	doPopups();
	findField();
	setupCaptions();	
}