/********************************************* 
*
*  global.js
*
*  requires mootools.js 
*  core and native components
*  http://mootools.net/download
*
*********************************************/

/*********************************************
 image rollovers
*********************************************/

function initRollovers() {
	var images = $A(document.getElementsByTagName('IMG'));
	images.each(function (img) {
		if ($(img).hasClass('roll')) {
			// skip active images
			if (img.src.test('-d.gif$')) return;
			
			var overImg = new Image();
			overImg.src = img.oversrc = img.src.replace(/\.gif$/, '-o.gif');
			img.outsrc = img.src;
			
			img.onmouseover = function() { this.src = this.oversrc; };
			img.onmouseout = function() { this.src = this.outsrc; };
		}
	});
}

window.addEvent('load', initRollovers);



  // this function is need to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

  function stripeById(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;

    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";

    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {

         // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor = even ? evenColor : oddColor;
              
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }

  function stripeByName(name) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;

    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";

    // obtain a reference to the desired table
    // if no such table exists, abort
    var tableElements = document.getElementsByTagName("table");
    
	    for(var m = 0; m < tableElements.length; m++){
		    var table = tableElements.item(m);
		    var even = false;
		    
		    if (! table) 
		    {  

		    }
		    else if(table.className == name)
		    {
			    // by definition, tables can have more than one tbody
			    // element, so we'll have to get the list of child
			    // &lt;tbody&gt;s 
			    var tbodies = table.getElementsByTagName("tbody");

			    // and iterate through them...
			    for (var h = 0; h < tbodies.length; h++) {

			     // find all the &lt;tr&gt; elements... 
			      var trs = tbodies[h].getElementsByTagName("tr");

			      // ... and iterate through them
			      for (var i = 0; i < trs.length; i++) {

				// avoid rows that have a class attribute
				// or backgroundColor style
				if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {

				 // get all the cells in this row...
				  var tds = trs[i].getElementsByTagName("td");

				  // and iterate through them...
				  for (var j = 0; j < tds.length; j++) {

				    var mytd = tds[j];

				    // avoid cells that have a class attribute
				    // or backgroundColor style
				    if (! hasClass(mytd) && ! mytd.style.backgroundColor) {

				      mytd.style.backgroundColor = even ? evenColor : oddColor;

				    }
				  }
				}
				// flip from odd to even, or vice-versa
				even =  ! even;
			      }
			    }
		    }
	    }
    
  }
  
  /*********************************************
   table striping
  *********************************************/
  
  function initTableStripe() {
  	stripeByName('data', '#fff', '#efefef');
  }
  
window.addEvent('load', initTableStripe);

document.write('<div id="popupContainer"></div><div id="windowMask"></div>');

var popupBox={
ie7: window.XMLHttpRequest && document.all && !window.opera,
ie7offline: this.ie7 && window.location.href.indexOf("http")==-1, //check for IE7 and offline
scrollbarwidth: 16,

ajaxConnect:function(url, thediv){
var pageBody_request = false
var bustcacheparameter=""
if (window.XMLHttpRequest && !this.ie7offline) // if Mozilla, IE7 online, Safari etc
pageBody_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE6 or below, or IE7 offline (for testing purposes)
try {
pageBody_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
pageBody_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
pageBody_request.onreadystatechange=function(){
popupBox.loadPageBody(pageBody_request, thediv)
}
if (this.ajaxbustcache) //if bust caching of external pageBody
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
pageBody_request.open('GET', url+bustcacheparameter, true)
pageBody_request.send(null)
},

loadPageBody:function(pageBody_request, thediv){
if (pageBody_request.readyState == 4 && (pageBody_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById("popupContent").innerHTML=pageBody_request.responseText
}
},


insertIframe:function(contentsource){	
	document.getElementById("popupContent").innerHTML='<iframe src="' + contentsource + '" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" style="margin:0; padding:0; width:100%; height: 100%"></iframe>';
},


createContainer:function(){
	document.getElementById("popupContainer").innerHTML = this.headerCode + '<div id="popupContent"></div>';
	this.popupContainer=document.getElementById("popupContainer"); //reference popup container
	this.popupContainer.style.height = this.containerHeight + "px";
	this.popupContainer.style.width =  this.containerWidth + "px";
	this.windowMask=document.getElementById("windowMask"); //reference veil
	this.pageBody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body; //create reference to common "body" across doctypes
},


displayBox:function(){
var ie=document.all && !window.opera
var dom=document.getElementById
var scroll_top=(ie)? this.pageBody.scrollTop : window.pageYOffset
var scroll_left=(ie)? this.pageBody.scrollLeft : window.pageXOffset
var docwidth=(ie)? this.pageBody.clientWidth : window.innerWidth-this.scrollbarwidth
var docheight=(ie)? this.pageBody.clientHeight: window.innerHeight
var docheightcomplete=(this.pageBody.offsetHeight>this.pageBody.scrollHeight)? this.pageBody.offsetHeight : this.pageBody.scrollHeight
var objwidth=this.popupContainer.offsetWidth
var objheight=this.popupContainer.offsetHeight
this.windowMask.style.width=docwidth+"px" //set up veil over page
this.windowMask.style.height=docheightcomplete+"px" //set up veil over page
this.windowMask.style.left=0 //Position veil over page
this.windowMask.style.top=0 //Position veil over page
this.windowMask.style.visibility="visible" //Show veil over page
this.popupContainer.style.left=docwidth/2-objwidth/2+"px" //Position interstitial box
var topposition=(docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+5+"px" //Position interstitial box
this.popupContainer.style.top=Math.floor(parseInt(topposition))+"px"
this.popupContainer.style.visibility="visible" //Show interstitial box
},


closePopUp:function(){
this.windowMask.style.visibility="hidden";
this.popupContainer.style.visibility="hidden";
document.getElementById("popupContainer").innerHTML = "";  //destroy
if (this.disablescrollbars && window.XMLHttpRequest) //if disablescrollbars enabled and modern browsers- IE7, Firefox, Safari, Opera 8+ etc
this.pageBody.style.overflow="auto";
},

getScrollbarWidth:function(){
var scrollbarwidth=window.innerWidth-(this.windowMask.offsetLeft+this.windowMask.offsetWidth)
this.scrollbarwidth=(typeof scrollbarwidth=="number")? scrollbarwidth : this.scrollbarwidth
},

hideScrollbar:function(){
if (this.disablescrollbars){ //if disablescrollbars enabled
if (window.XMLHttpRequest) //if IE7, Firefox, Safari, Opera 8+ etc
this.pageBody.style.overflow="hidden"
else //if IE6 and below, just scroll to top of pageBody to ensure popup is in focus
window.scrollTo(0,0)
}
},

addCustomEvent:function(target, funcref, eventtype){ //assign a function to execute to an event handler (ie: onunload)
var eventtype=(window.addEventListener)? eventtype : "on" + eventtype
if (target.addEventListener)
target.addEventListener(eventtype, funcref, false)
else if (target.attachEvent)
target.attachEvent(eventtype, funcref)
},

initPopUp:function(){
	this.createContainer() //write out popup container
	if(this.contenttype=="ajax")
	{	
		this.ajaxConnect(this.displayurl, this.popupContainer) //load pageBody via ajax
	}
	else if(this.contenttype=="iframe")
	{	
		this.insertIframe(this.displayurl);
	}
popupBox.hideScrollbar(); popupBox.getScrollbarWidth(); 
popupBox.displayBox();
this.addCustomEvent(window, function(){if (document.getElementById("popupContent") != null){popupBox.displayBox()}}, "resize")
}
}


function slideShowPopUp(myurl)
{
	popupBox.displayurl = myurl;

	popupBox.containerHeight = 400;
	
	popupBox.containerWidth = 600;

	//HTML for the header bar portion of the popup box
	popupBox.headerCode = '<div class="popupHeader"><a class="closeLink" href="#" onClick="javascript:popupBox.closePopUp(); return false">X</a></div>';

	//type ajax or iframe
	popupBox.contenttype = 'iframe';

	//bust caching of pageBodys fetched via Ajax?
	popupBox.ajaxbustcache = true;

	//Disable browser scrollbars while popup is shown
	popupBox.disablescrollbars = false;

	popupBox.initPopUp();
}


function mediaPopUp(myurl,width,height)
{
	popupBox.displayurl = myurl;
	
	popupBox.containerHeight = height;
		
	popupBox.containerWidth = width;

	//HTML for the header bar portion of the popup box
	popupBox.headerCode = '<div class="popupHeader"><a class="closeLink" href="#" onClick="javascript:popupBox.closePopUp(); return false">X</a></div>';

	//type ajax or iframe
	popupBox.contenttype = 'iframe';

	//bust caching of pageBodys fetched via Ajax?
	popupBox.ajaxbustcache = true;

	//Disable browser scrollbars while popup is shown
	popupBox.disablescrollbars = false;

	popupBox.initPopUp();
}
