//maked all added functions work onload. at the end of each function you want to work onload add addLoadEvent(function); to the end of the function.
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// The following two functions make it possible to have web standard popups
window.onload = function() {
  if (!document.getElementsByTagName) return false;
  var lnks = document.getElementsByTagName("a");
  for (var i=0; i<lnks.length; i++) {
    if (lnks[i].className == "popup") {
      lnks[i].onclick = function() {
        popUp(this.getAttribute("href"));
        return false;
      }
    }
  }
}

function popUp(winURL) {
  window.open(winURL,"popup");
}

//-- Create a :Hover psuedo attribute for IE for header -- //
hdrHover = function() {
	if (document.getElementById('headerNav') != null) {
		if((document.all)&&(document.getElementById)) {
			var hdrCat = document.getElementById("headerNav").getElementsByTagName("li");
			var form = document.getElementById("frmSearch");
			for (var i=0; i<hdrCat.length; i++) {
				hdrCat[i].onmouseover=function() {
					this.className+=" hdrhover";
				}
				hdrCat[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" hdrhover\\b"), "");
				}
			}
		}	
	}
}
addLoadEvent(hdrHover);

//add print link
function addPrintLink() {
  if(!document.getElementById) return false;
  if(!document.getElementById('ptplnk')) return false;
	var printButton = document.getElementById('ptplnk');
	printButton.onclick=function() {
		window.print(); return false;
	}
}
addLoadEvent(addPrintLink);


function slideshowControls(){
  //Build slideshow and nav if more than one slide
  if($('#slideshow li').length > 1){
    $('#slideshow-wrap').append('<ul id="slideshow-nav"></ul>');
    $('#slideshow li').each(function(index) {
      $('#slideshow-nav').append('<li><a href="" title="' + index + '">' + index + '</a></li>');
    });
  }
  
  if($('#slideshow li').length > 1){
    $('#slideshow').cycle({ 
      fx:     'fade', 
      speed:  'fast', 
      timeout: 8000, 
      pager:  '#slideshow-nav', 
      pagerAnchorBuilder: function(idx, slide) { 
          // return selector string for existing anchor 
          return '#slideshow-nav li:eq(' + idx + ') a'; 
      } 
    });
  }
}
$(document).ready(function() {
  slideshowControls();
	if($('div[data-video]')){
    $.getScript('/js/flowplayer-3.2.6.min.js',
      function(){
        $('div[data-video]').flowplayer('/swf/flowplayer.commercial-3.2.7-5.swf', { clip: { autoPlay: jQuery('div[data-video]').hasClass('autoplay'), url: $('div[data-video]').attr('data-video') } });
    });
  }
});
