/// <summary>
/// Imported from paging.js
/// </summary>

/// <summary>
/// Check the current request to see if it has the needed requirements to run GallupPaging
/// </summary>
function hasPagingSupport() 
{
	if (typeof (hasPagingSupport.support) != "undefined")
	{
		return hasPagingSupport.support;
    }
	
	var ie55 = /msie 5\.[56789]/i.test( navigator.userAgent );
	
	hasPagingSupport.support = ( typeof (document.implementation) != "undefined" &&
			document.implementation.hasFeature( "html", "1.0" ) && 
			typeof (document.body.innerHTML) == "string" || ie55 )
			
	return hasPagingSupport.support;
	
};

function loadPagingPages ( el ) 
{
	if (( !hasPagingSupport() ) ||
	( el.pages.length != 0 )) return;
	
    var pageHash = document.location.hash;
    if ((pageHash == null) || (pageHash == ''))
        pageHash = "#1";
        
	var _pages = getElementsByClass("page", el.element, "div");
	
	if (_pages.length > 0)
	{
        for (i = 0; i < _pages.length; i++) 
        {
	        _pages[i].className = "pagehide";
    		
            el.pages[i] = _pages[i];
            
            if (pageHash == _pages[i].id.replace('page','#'))
            {
                el.selectedIndex = i;
            }
        }
        
        if (el.selectedIndex == null || el.pages[ el.selectedIndex ] == null )
	    {
           el.selectedIndex = 0;
	    }
	    
	    el.pages[ el.selectedIndex ].className = "pageshow";
	}
};

function setSelectedIndex ( el,  n ) 
{
	if (el.selectedIndex != n) 
	{
		if (el.selectedIndex != null && el.pages[ el.selectedIndex ] != null )
		{
	        el.pages[ el.selectedIndex ].className = "pagehide";
		}
        
	    var _activeLinks = getElementsByClass("pagingnavigationoption" + el.selectedIndex, el.element.parentNode, "a");
	    
	    if (_activeLinks.length > 0)
	    {
            for (i = 0; i < _activeLinks.length; i++) 
            {
		        _activeLinks[i].className = "pagingnavigationoption" + el.selectedIndex;
            }
	    }
		
	    el.pages[ n ].className = "pageshow";
		el.selectedIndex = n;
	    
	    if(_ff)		
	        document.getElementById('top').focus();
	    else
	        document.getElementById('pagingnavigationtop').focus();
	    
		
		highlightLinks ( el );
	}	
};

function highlightLinks ( el )
{
	    var _activeLinks = getElementsByClass("pagingnavigationoption" + el.selectedIndex, el.element.parentNode, "a");
	    
	    if (_activeLinks.length > 0)
	    {
            for (i = 0; i < _activeLinks.length; i++) 
            {
		        _activeLinks[i].className += " pagingnavigationoptionon";
            }
	    }
}

function createNavigation ( el ) 
{
    // Add Paging, if there are more then 1 page
    if (el.pages.length > 1)
	{
	    var text1 = document.createTextNode('<span>Page:</span>');
	   
	    var div1 = createNavigationBlock("pagingnavigationtop");
	    var div2 = createNavigationBlock("pagingnavigationbottom");
	
        for (i = 0; i < el.pages.length; i++) 
        {    
            div1.appendChild(createNavigationLink( el , i));
            div2.appendChild(createNavigationLink( el , i));
        }
	
		 var wrapper = document.getElementById( "pagingwrapper" );
		 var clearingDiv = document.createElement( "div" );
		 clearingDiv.className = "clearer";
		 clearingDiv.innerHTML = " ";
		 wrapper.insertBefore( clearingDiv, wrapper.firstChild );
		 wrapper.insertBefore( div1, clearingDiv );
	    el.element.appendChild(div2);
	    
	    highlightLinks (el);
	}
};



function createNavigationBlock(cssClass)
{
	var text = document.createTextNode('Page:');
	
	var span = document.createElement( "SPAN" );
	span.appendChild(text);
	
	var div = document.createElement( "DIV" );
	div.className = "pagingnavigation " + cssClass;
	div.id = cssClass;
	div.appendChild(span);
	
	return div;
};

function createNavigationLink( el , position)
{
    var _num = (position + 1);
            
	var a = document.createElement( "A" );
	a.href = "#" + _num;
	a.className = "pagingnavigationoption" + position;
	a.innerHTML = _num;
	
	a.onclick = function () { 
	
	setSelectedIndex ( el,  position);
	
	if (_ff == true)
	    return false;
	else
	    return true;
	
	};
	
	return a;
}

/// <summary>
/// 
/// </summary>
function startPaging( el ) 
{
    if ( !hasPagingSupport() || el == null ) return;
	
	this.element = el;
	this.selectedIndex = null;
	this.pages = [];
	
	// Load the Pages
    loadPagingPages ( this );
    
	createNavigation( this );
	
};

   
/// <summary>
/// 
/// </summary>
function initializationPaging() 
{ 
    // Grab the main node
    var _pages;
    var _continue = false;
    
    try
    {
        _pages = document.getElementById('pages');
    
        if (_pages.tagName.toLowerCase() == "div") 
        {
            _continue = true;
        }
    }
    catch(e)
    {}
    
    if (_continue == true)
    {
        startPaging(_pages);
    }
        
};

// initialization hook up

// DOM2
if ( typeof window.addEventListener != "undefined" )
	window.addEventListener( "load", initializationPaging, false );

// IE 
else if ( typeof window.attachEvent != "undefined" ) {
	window.attachEvent( "onload", initializationPaging );
	//window.attachEvent( "onunload", disposeAllTabs );
}

else {
	if ( window.onload != null ) {
		var oldOnload = window.onload;
		window.onload = function ( e ) {
			oldOnload( e );
			initializationPaging();
		};
	}
	else 
		window.onload = initializationPaging;
}

/// <summary>
/// Imported from subnavigation.js
/// </summary>

activesubmenuhover = function() 
{
	var menuSelector = getElementsByClass("moredropdownmenu", document, "li");

	if ( (null != menuSelector) && (menuSelector.length > 0) )
    {
        //alert(menuSelector + '\n' + menuSelector.length);
        
        for (i = 0; i < menuSelector.length; i++) 
        {
            // Attach New Event
            menuSelector[i].onmouseover = function() {
                this.className = this.className + " activemenu";
            }
            
            var children = menuSelector[i].getElementsByTagName( "a" );
            children[0].onclick = function() {
                this.blur();
                return false;
            }
            
            // Attach New Event
            var menu = menuSelector[i].getElementsByTagName( "ul");
            menu[0].onmouseout = function() 
            {
                this.parentNode.className = this.parentNode.className.substring( 0, this.parentNode.className.indexOf(" activemenu","") );
            }
            
            // Attach New Event
            
            for (x = 0; x < menuSelector[i].childNodes.length; x++) 
            {
                if (menuSelector[i].childNodes[x].tagName == "UL")
                {
                    //This next line keeps the list lined up correctly on the right side.
							//170 should be changed to equal the difference between the a.width and the ul.width.
							//162 should be changed to equal the difference between the a.width and the ul.width + 8 (??? safari).
							//250 should be changed to equal the ul.width.
                    var _leftPosition = getElementLeft( menuSelector[i].childNodes[x] );
                    
                    //alert(_leftPosition);
						  if ( _ff ) {
                    	menuSelector[i].childNodes[x].style.left = (( _leftPosition ) - 100 ) + 'px';
                    } else if ( _safari ) {
                    	menuSelector[i].childNodes[x].style.left = (( _leftPosition ) - 100 ) + 'px';
                    } else {
                    	menuSelector[i].childNodes[x].style.left = (( _leftPosition ) - 180 ) + 'px';

                    }
                
                }
            }
            
        } //for
    } //if
} //function

function getElementLeft(elem) {
        xPos = elem.offsetLeft;
        tempEl = elem.offsetParent;
        while (tempEl != null) {
                xPos += tempEl.offsetLeft;
                tempEl = tempEl.offsetParent;
        }
        xPos -= elem.parentNode.scrollLeft;
        return xPos;
}

// initialization hook up

// DOM2
if ( typeof window.addEventListener != "undefined" )
	window.addEventListener( "load", activesubmenuhover, false );

// IE 
else if ( typeof window.attachEvent != "undefined" ) {
	window.attachEvent( "onload", activesubmenuhover );
}

else {
	if ( window.onload != null ) {
		var oldOnload = window.onload;
		window.onload = function ( e ) {
			oldOnload( e );
			activesubmenuhover();
		};
	}
	else 
		window.onload = activesubmenuhover;
}


/// <summary>
/// Imported from sitemap.js
/// </summary>

activemenuhover = function() 
{
	var menus = getElementsByClass("title" , document.getElementById("sitemap"), "DIV");
	
	for (var i = 0; i < menus.length; i++) 
	{	
		menus[i].firstChild.onmouseover = function() {
				this.parentNode.parentNode.className += " activemenu";
				var titles = getElementsByClass("title" , this.parentNode.parentNode, "DIV");
				titles[0].className += " activeTitle";
			}
		menus[i].firstChild.onmouseout = function() {
				this.parentNode.parentNode.className = this.parentNode.parentNode.className.substring( 0, this.parentNode.parentNode.className.indexOf(" activemenu","") );
				var titles = getElementsByClass("title" , this.parentNode.parentNode, "DIV");
				titles[0].className = titles[0].className.substring( 0, titles[0].className.indexOf(" activeTitle","") );
			}
		menus[i].firstChild.onclick = function() {
			this.blur();
			return false;
		}
		var columns = getElementsByClass("columns" , menus[i].parentNode, "DIV");
		columns[0].onmouseout = function() 
		{
			this.parentNode.className = this.parentNode.className.substring( 0, this.parentNode.className.indexOf(" activemenu","") );
			var titles = getElementsByClass("title" , this.parentNode, "DIV");
			titles[0].className = titles[0].className.substring( 0, titles[0].className.indexOf(" activeTitle","") );
		}	
		columns[0].onmouseover = function() 
		{
			this.parentNode.className += " activemenu";
			var titles = getElementsByClass("title" , this.parentNode, "DIV");
			titles[0].className += " activeTitle";
		}	
	}
}

// initialization hook up

// DOM2
if ( typeof window.addEventListener != "undefined" )
	window.addEventListener( "load", activemenuhover, false );

// IE 
else if ( typeof window.attachEvent != "undefined" ) {
	window.attachEvent( "onload", activemenuhover );
}

else {
	if ( window.onload != null ) {
		var oldOnload = window.onload;
		window.onload = function ( e ) {
			oldOnload( e );
			activemenuhover();
		};
	}
	else 
		window.onload = activemenuhover;
}

/// <summary>
/// Imported from common.js
/// </summary>


var _ff = false;
var _safari = false;

if(navigator.userAgent.indexOf("Firefox")!=-1)
{
    var versionindex=navigator.userAgent.indexOf("Firefox");
    
    if (versionindex > 1)
    {
        _ff = true;
     }
}

if(navigator.userAgent.indexOf("Safari")!=-1)
{
    var versionindex=navigator.userAgent.indexOf("Safari");
    
    if (versionindex > 1)
    {
        _safari = true;
     }
}

function getElementsByClass(searchClass,node,tag) 
{
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
};

function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function getElementAbsPosX(el)
{
    var dx = 0;
    if (el.offsetParent) {
        dx = el.offsetLeft + 8;
        while (el = el.offsetParent) {
            dx += el.offsetLeft;
        }
    }
    return dx;
}

function findPosY(obj)
{
var curtop = 0;
if(obj.offsetParent)
    while(1)
    {
      curtop += obj.offsetTop;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;
    }
else if(obj.y)
    curtop += obj.y;
return curtop;
}

function getLeft(element) {
	var left = 0, absoluteAncestor = false, computedStyle = (document.defaultView && document.defaultView.getComputedStyle), currentStyle = (element.currentStyle);
//	so long as the element has an positioning context...
	while (element.offsetParent) {
//		add the left offset of the element
		left += element.offsetLeft
//		set the element to the element which provided the positioning context
		element = element.offsetParent;
//		if the element hasLayout (IE-only property)
		if (currentStyle && element.currentStyle.hasLayout && element.nodeName.toLowerCase() != 'html') {
//			add the width of the left border
			left += element.clientLeft;
//			and if it's absolutely positioned, flag that we've got an absolutely positioned ancestor
			if (element.currentStyle['position'] == 'absolute') absoluteAncestor = true;
//		otherwise, if it's a browser that supports computedStyle & the element is absolutely positioned
		} else if (computedStyle && document.defaultView.getComputedStyle(element, "").getPropertyValue('position') == 'absolute') {
//			add the left border of the element
			left += parseInt(document.defaultView.getComputedStyle(element, "").getPropertyValue('border-left-width'));
//			and flag that we've got an absolutely positioned ancestor
			absoluteAncestor = true;
		}
	}
//	if the browser supports currentStyle (i.e. is IE) and we found an absolutely positioned ancestor, add any left margin on the BODY
	if (!absoluteAncestor && currentStyle) return left += document.getElementsByTagName('BODY')[0].offsetLeft;
//	otherwise, if we found an absolutely positioned ancestor and the browser supports computed style add any left border from the BODY
	else if (!absoluteAncestor && computedStyle) return left += parseInt(document.defaultView.getComputedStyle(document.getElementsByTagName('BODY')[0], "").getPropertyValue('border-left-width'));
}

/*	GET STYLE
	Based on Ryber Nyman's script at:
	http://www.robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
	
	gets the current style (computed style in Moz/Safari/etc.) of an element
	
	PARAMETERS
	element - object, element node reference
	rule - string, CSS rule
	
	KNOWN BUGS
	- if a property is set in percentages, ems, etc., IE will return the
	  value in the same unit in which the property was set, where Firefox,
	  Safari, et al will return the value in pixels (that's the difference
	  between computed style & current style)
	
*/
function getStyle(element, rule){
	var value, dashIndex;
	if (document.defaultView && document.defaultView.getComputedStyle) {
		value = document.defaultView.getComputedStyle(element, "").getPropertyValue(rule);
	} else if (element.currentStyle) {
		while(-1 != (dashIndex = rule.indexOf('-'))) {
			rule = rule.substring(0,dashIndex) + rule.substring(dashIndex + 1, dashIndex + 2).toUpperCase() + rule.substring(dashIndex + 2);
		}
		value = element.currentStyle[rule];
    }
    return value;
}

function popfplayer(identKey)
{
    testwindow= window.open ("/fvideo.aspx?i=" + identKey, "mywindow", "location=0,status=0,scrollbars=0,resizable=0,width=800,height=490");
}
