$(document).ready(function(){ 
	searchText();
	setDropDownNav();
	setTopNav();
	if (document.getElementById('fadeEventsHome')){
		$('#fadeEventsHome').css('visibility', 'visible');
		fadeInOutHome('fadeEventsHome', 0, 'in');
		assignRollover();
	}
	if (document.getElementById("latestNews")){
	$(".newsList").jCarouselLite({
		vertical: true,
		hoverPause: true,
		visible: 1,
		btnNext: ".next",
		btnPrev: ".prev",
		auto:3400,
		speed:50
	});
	}


 
	
});
function setTopNav(){
	if(!$('#topNav')){
		return;
	}
	$('#topNav li').hover(  
		function () {  
			$(this).addClass('over') 
		},
		function (){
			$(this).removeClass('over');
		}
	);
}
function searchText(){
	if (!$('#ctl00_txtSearch')){
		return;
	}
	var $search = $('#ctl00_txtSearch');
	$search.bind('focus', function(){
		$(this).attr('value', '');
	});

}
function assignRollover(){
	var navLinksDiv = document.getElementById('bannerNav');
	var $linkList = $('.fadeLink');
	var heros = getElementsByClassName(document, "div","fadeEvent");
	
	
	for(var j=0; j<$linkList.length; j++){
		
		var thisHero = $linkList[j];
		thisHero.num = j + 1;
		thisHero.onclick = function(){
			$linkList.css('color', '#c2c4c5');
			$(this).css('color', '#000000');
			var thisFade = document.getElementById('fadeEvent'+this.num);
			//cancel the timed animation
			clearTimeout(tFader);
			// reset the zindexes
			resetZindex(heros);
			resetOpacity(heros, 100);
			// set this zindex to the top
			thisFade.style.zIndex = 1;
			// fade in
			thisFade.style.opacity = '1';
			thisFade.style.filter = "alpha(opacity=100)";
			//opacity(thisFade, 0, 100, 3, 120, 1);
			return false;
		}
		
	}
	
	var $next = $('#fadeLinkNext');
	var $previous = $('#fadeLinkPrevious');
		
	$('.bannerArrow').bind('click', function(){
		$linkList.css('color', '#c2c4c5');
		var $banners = $('.fadeEvent');
		$banners.each(function(index){
			if ($(this).css('z-index') == '1'){
				currentElementId = $(this).attr('id');
				currentElementIdNum = currentElementId.charAt(currentElementId.length-1);
			
				nextLink = '#fadeLink'+(parseInt(currentElementIdNum) + 1)
				previousLink = '#fadeLink'+(parseInt(currentElementIdNum) - 1);
				nextElement = '#fadeEvent'+(parseInt(currentElementIdNum) + 1);
				previousElement = '#fadeEvent'+(parseInt(currentElementIdNum) - 1);
				if (nextElement == '#fadeEvent7'){
					nextElement = '#fadeEvent1';
					nextLink = '#fadeLink1';
				}
				if (previousElement == '#fadeEvent0'){
					previousElement = '#fadeEvent6';
					previousLink = '#fadeLink6';
				}
				
			}
			
			
		});
		
	});
	$next.bind('click', function(){
			$(nextLink).css('color', '#000000');
			//alert($currentElement.next().attr('id'));
			clearTimeout(tFader);
			// reset the zindexes
			resetZindex(heros);
			// set this zindex to the top
			resetOpacity(heros, 199);
			$(nextElement).css('z-index', '1');
			// fade in
			$(nextElement).css('opacity', '1');
			$(nextElement).css('filter', 'alpha(opacity=100)');
			return false;
	});
		$previous.bind('click', function(){
			$(previousLink).css('color', '#000000');
			//alert($currentElement.next().attr('id'));
			clearTimeout(tFader);
			// reset the zindexes
			resetZindex(heros);
			// set this zindex to the top
			resetOpacity(heros, 199);
			$(previousElement).css('z-index', '1');
			// fade in
			$(previousElement).css('opacity', '1');
			$(previousElement).css('filter', 'alpha(opacity=100)');
			return false;
	});
	
	
}
//rests the opacity of elements in an array EXCEPT for notFadeID
function resetOpacity(elements, notFadeID){
	for (var i=0; i<elements.length; i++){
		if (elements[i].getAttribute('id') == notFadeID){
			continue;	
		}
		else{
			elements[i].style.opacity = 0;
			elements[i].style.filter = "alpha(opacity=0)";
		}
	}
}
function setNavWidth(){
	var uls = getElementsByClassName(document, "ul", "ulSubnav");
	var fontSize = 12;
	for (var i=0; i<uls.length; i++){
		var links = uls[i].getElementsByTagName('b');
		nums = Array();
		for (var j=0; j<links.length; j++){
			links[j].style.fontSize = fontSize+"px";
			nums[j] = links[j].innerHTML.length;
		}
		 uls[i].greatestNum = Math.max.apply( Math, nums );
		 var width = (fontSize - 5)* uls[i].greatestNum; 
		for (var k=0; k<links.length; k++){
		/*special for digital persona bottom curve */
			if (k == links.length -1){
				//links[k].style.width = (width-10)+"px";
				
				//alert(links[k].style.width);
				links[k].style.width = width+"px";
			}
			else{
			links[k].style.width = width+"px";
			//alert(links[k].style.width);
			}
			/* put this in b/c it made the 1st time around work for ie6 */
			if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1){
			uls[i].style.width = width+"px";
			}
		}
	}
}

k = 0;
function fadeInOutHome(containerId, waitTime, direction){
	if (!document.getElementById(containerId)) return;
	var container = document.getElementById(containerId);
	var $heros = $('.fadeEvent');
	var $links = $('.fadeLink');
	$links.css('color','#c2c4c5');;
	resetZindex($heros);
	
	if (direction == 'in'){
		$heros[k].style.zIndex = 1;
		$links[k].style.color = '#000000';
		opacity($heros[k], 0, 100, 3, 120, 1);	
		tFader = setTimeout("fadeInOutHome('"+containerId+"','"+waitTime+"','out')", 5000);
	}
	else if (direction == 'out'){
		opacity($heros[k], 100, 0, 8, 140, 1);
		$heros[k].style.zIndex = 0;
		k = (k + 1) % $heros.length;
		tFader = setTimeout("fadeInOutHome('"+containerId+"','"+waitTime+"','in')", waitTime);	
	}
	
}
l = 0;
function fadeInOut(containerId, waitTime, direction){
	if (containerId == 'fadeEventsHome') return;
	if (!document.getElementById(containerId)) return;
	var container = document.getElementById(containerId);
	var $heros = $('.fadeEvent');
	resetZindex($heros);
	
	if (direction == 'in'){
		$heros[l].style.zIndex = 1;
		opacity($heros[l], 0, 100, 3, 120, 1);	
		tFader = setTimeout("fadeInOut('"+containerId+"','"+waitTime+"','out')", 3000);
	}
	else if (direction == 'out'){
		opacity($heros[l], 100, 0, 8, 140, 1);
		$heros[l].style.zIndex = 0;
		l = (l + 1) % $heros.length;
		tFader = setTimeout("fadeInOut('"+containerId+"','"+waitTime+"','in')", waitTime);	
	}
	
}
	
function resetZindex(elements){
	for (var l=0; l<elements.length; l++){
		elements[l].style.zIndex = 0;
	}
}
function opacity(image, opacStart, opacEnd, steps, intervals, powr){
    if (image.fading) window.clearInterval(image.fading);
    var thisStep = 0;
    image.fading = setInterval(fade, intervals);
     function fade(){
            image.currentOpacity =  easeInOut( opacStart, opacEnd, steps, thisStep, powr);
            image.style.opacity = (image.currentOpacity / 100);
            image.style.MozOpacity = (image.currentOpacity / 100);
            image.style.KhtmlOpacity = (image.currentOpacity / 100);
            image.style.filter = "alpha(opacity=" + image.currentOpacity + ")";
            thisStep++;
            if (thisStep > steps) window.clearInterval(image.fading);
     }
}

//generic value churner by Hesido (wwww.hesido.com)
function easeInOut( opacStart, opacEnd, steps, thisStep, powr ){
     var NumDifference = opacEnd - opacStart;
     var increaseStepAmt = opacStart + (Math.pow((( 1 / steps ) * thisStep), powr ) * NumDifference );
     return Math.ceil(increaseStepAmt);
}

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 setDropDownNav(){
	dropDownNav("level1");
}
/*
function dropDownNav(level){
	if ( !document.getElementById('nav') && !document.getElementById('upperNav') ){
		return false;
		
	}
	
	
	var li_list_level1 = getElementsByClassName(document, 'li', level);
	setNavWidth();
	for (var i=0; i<li_list_level1.length; i++){
		li_list_level1[i].onmouseover = function(){
			this.className += ' on';
			for (var n=0; n<this.childNodes.length; n++){
				node = this.childNodes[n];
				if (node.nodeName == 'UL' || node.nodeName == 'DIV'){
				
					node.className += ' over';
				}
			}
		}
		
		li_list_level1[i].onmouseout = function(){
?		var li = this;
			
					this.className = this.className.replace(/on/gi, '');
			
				for (var n=0; n<li.childNodes.length; n++){
					node = li.childNodes[n];
					if (node.nodeName == 'UL' || node.nodeName == 'DIV'){
						node.className = node.className.replace(/over/gi, '');
					}
				}
			
			
		}
		

	}

}
*/
function setDropDownNav(){
	dropDownNav("level1");
}
t = Array();
function dropDownNav(level){
	 if ( document.getElementById('nav') ){
		
		setNavWidth();
		var li_list_level1 = getElementsByClassName(document, 'li', level);
		
		for (var i=0; i<li_list_level1.length; i++){
			li_list_level1[i].onmouseover = function(){
				$(this).addClass('on');
				clearTimeout(t[level]);
				resetSubmenus(level);
				for (var n=0; n<this.childNodes.length; n++){
					node = this.childNodes[n];
					if (node.nodeName == 'UL' || node.nodeName == 'DIV'){
						node.className += ' over';
					}
				}
			}
			
			li_list_level1[i].onmouseout = function(){
				var li = this;
				$(this).removeClass('on');
				function submenuTimeout(){
					for (var n=0; n<li.childNodes.length; n++){
						node = li.childNodes[n];
						if (node.nodeName == 'UL' || node.nodeName == 'DIV'){
							node.className = node.className.replace(/over/gi, '');
						}
					}
				}
				t[level] = setTimeout(submenuTimeout, 1500);
			}
			

		}
	}
	else if ( document.getElementById('upperNav') ){
	
		/*
		var $li_list = $('#upperNav li.level1');
		for (var i=0; i<$li_list.length; i++){
			$li_list[i].onmouseover = function(){
				//$(this).addClass('on');
				for (var n=0; n<$(this).children('div.subnav').length; n++){
					var $node =$($(this).children('div.subnav')[n]);
					$node.addClass('over');
					
				}
			}
			
			$li_list[i].onmouseout = function(){
				var $li = $(this);
				//$li.removeClass('on');
				
					for (var n=0; n<$li.children('div.subnav').length; n++){
						$node = $($li.children('div.subnav')[n]);
						
						$node.removeClass('over');
					}
				
				
			}
	
	
		}
		*/
		
	 $('#upperNav li.level1').hover(  
       function () {  

			$(this).addClass('on');
             //show its submenu  
             $('div.subnav', this).addClass('over') 
   
         },   
        function () {  
			$(this).removeClass('on');
           //hide its submenu  
             $('div.subnav', this).removeClass('over');
         }  
     );  

	}
	else{
		return;
	}
}

function resetSubmenus(className){
	var list = getElementsByClassName(document,"li", className);
	for (var j=0; j<list.length; j++){
		var li = list[j];
		for (var k=0; k<li.childNodes.length; k++){
			node = li.childNodes[k];
			if (node.nodeName == 'UL' || node.nodeName == 'DIV'){
				node.className = node.className.replace(/over/gi, '');
			}

		}
	}

}




/*PWR #4747*/
var objXmlReq;
var WPfile;
function Downloadwindow(sFile){		
    var sPathandfile;
    var sUserEmail = readCookie("DP_DL_WP");
	//alert(sUserEmail);
	if (sUserEmail != '' && sUserEmail != null) //if has whitepaper cookie open the file directly
	{
		var AjaxServerPageName = "/DownloadWPAjax.aspx";
		var requestUrl = AjaxServerPageName + '?wpfile=' + sFile + '&useremail='+sUserEmail
		WPfile = sFile;	
	    //CreateobjXmlReq();		
	    objXmlReq = ajaxRequest();
	    //alert(requestUrl);
	    if(objXmlReq)
	    {
    	
		    objXmlReq.onreadystatechange = HandleResponse;			
		    objXmlReq.open("GET", requestUrl,  true);		
		    objXmlReq.send("");		
	    }
		//
		//request.open("GET", url, true);
		//request.send(null);
	}
	else
	{
		sPathandfile = '/downloadwp.aspx?wp='+ sFile;
        newwindow = window.open(sPathandfile,'windownload', 'resizable=1, scrollbars=0,toolbar=0,menubar=0,width=500,height=450');
		return false;	
	}
	
    //alert(readCookie('DP_DL_WP'));
    //if(readCookie('DP_DL_WP') != null){ 
        //window.location = sFile;
    //    sPathandfile = sFile;
    //}
    //else
    //{
	//sPathandfile = '/downloadwp.aspx?wp='+ sFile;
    //}
    //newwindow = window.open(sPathandfile,'windownload', 'resizable=1, scrollbars=0,toolbar=0,menubar=0,width=500,height=425');
    //return false;	    
}

function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
    //suppress error
   }
  }
 }
 else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  return new XMLHttpRequest()
 else
  return false
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
/*function CreateobjXmlReq()
{
 
	try
	{
		objXmlReq = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			objXmlReq = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			objXmlReq = null;
		}
	}
	if(!objXmlReq && typeof XMLHttpRequest != "undefined") 
	{
		objXmlReq = new XMLHttpRequest();
	}
	
}*/

function HandleResponse()
{
	if(objXmlReq.readyState == 4)
	{
		if(objXmlReq.status == 200 || objXmlReq.status == 404)
		{		
		    
		    
			// Fill the cleared div with new XML Reponse
			//alert(WPfile);
			window.location.href = WPfile;
			// Hides the Process Image Table after displaying the contents
			//imgtbl.style.visibility = 'hidden';
			
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}
/*PWR #4747 END */






