
//Hack for IE6 not supporting the first-child psuedo class
$(document).ready(function(){
	$('#top-nav ul > li:first').addClass('first-child'); //handles top nav
	$('ul.main-nav > li:first').addClass('first-child'); //handles main navigation
	$('ul.sub-navigation > li:first').addClass('first-child'); //handles sub-nav
	$('.drop-menu > div:first').addClass('first-child'); //handles drop down menu div
	$('.drop-menu ul').find(":first-child").addClass('first-child'); //handles drop down menu lists, using .find to find the first child of EVERY ul under drop menu
	$('#footer ul > li:first').addClass('first-child'); //handles footer nav
});

//Header Navigation Drop Down Menus - jQuery must be loaded before this script
$(document).ready(function() {
	$(".dropdown").append("<span></span>"); //This function will remove the dropdown arrow to the right of the drop down menu parent in the event that Javascript is disabled
	//Solutions Drop Down
	//This function displays the drop down menu once the user mouses over the list item in the main nav, it also adds the class of active present during mouseout
	$('#nav-solutions').hover(
		function(){
			$('#nav-solutions').addClass("active") //This adds the class of active to the li with the displayed ID on mouse over of its button in the header navigation
			$('#solutions-menu').fadeIn(200) //fadeIn is a property of jQuery and fades the menu in over the course of 300 miliseconds offering a subtle animation
		},
		function() {
			$('#nav-solutions').removeClass("active") //This removes the class of active to the li with the displayed ID on mouse out of its button in the header navigation
			$('#solutions-menu').hide() //This hides the corresponding solution on mouse out
		}
	);
	//This function keeps the menu open once the user mouses off of the list item in the main nav, it also keeps the class of active present during mouseout
	$('#solutions-menu').hover(
		function(){
			$('#nav-solutions').addClass("active") //This adds the class of active to the li with the displayed ID on mouse over of it its respective menu so that the active state stays present until the user is done with that buttons menu.
			$('#solutions-menu').show()
		},
		function(){
			$('#nav-solutions').removeClass("active") //This removes the class of active to the li with the displayed ID on mouse out of it its respective menu so that the active state disappears when the user is done with that buttons menu.
			$('#solutions-menu').hide()
		}
	);
	//Products Drop Down
	$('#nav-products').hover(
		function(){
			$('#nav-products').addClass("active")
			$('#products-menu').fadeIn(200)
		},
		function(){
			$('#nav-products').removeClass("active")
			$('#products-menu').hide()
		}
	);
	$('#products-menu').hover(
		function(){
			$('#nav-products').addClass("active")
			$('#products-menu').show()
		},
		function(){
			$('#nav-products').removeClass("active")
			$('#products-menu').hide()
		}
	);
	//Support Drop Down
	/*$('#nav-support').hover(
		function(){
			$('#nav-support').addClass("active")
			$('#support-menu').fadeIn(200)
		},
		function(){
			$('#nav-support').removeClass("active")
			$('#support-menu').hide()
		}
	);
	$('#support-menu').hover(
		function(){
			$('#nav-support').addClass("active")
			$('#support-menu').show()
		},
		function(){
			$('#nav-support').removeClass("active")
			$('#support-menu').hide()
		}
	);*/
	//Handle the active state for the rest of the navigation mouse overs
	$('.main-nav li').hover(
		function(){
			$(this).addClass("active") //when a user mouses over ANY of the list items under main nav add the class of active to the li. This does not affect the hover state of the list items in the drop down menus
		},
		function(){
			$(this).removeClass("active") //when a user mouses out of ANY of the list items under main nav remove the class of active to the li. This does not affect the hover state of the list items in the drop down menus
		}
	);
					
});

//International Location Selector 
$(document).ready(function() {
	$('#location-select').click(
		function(){
			$('#location').fadeIn(200) //On click fade in the location menu box #location
		}
	);
	$('#location').hover(
		function(){
			$('#location').show(); //On hover of #location keep showing
		},
		function(){
			$('#location').hide(); //On hover out hide #location
		}
	);
});

//Remove the term Search from the search box on click.  On focus if the search box contains the value 'Search' replace that value with blank
$(document).ready(function(){
	$('#ffQ').focus(function(){ 
		if(this.value=='Search') 
			{this.value=''}
	});
});



/*
addBodyClass:
adds 'js' class to <body> (for JavaScript dependent CSS)
*/
function addBodyClass(){
	var el = document.getElementsByTagName('body')[0];	
	el.className += ' js';
}

/*
overLabels:
emulates default form field value using <label>.
*/
function overLabels(){
  var labels, id, field, i;

  // Set focus and blur handlers to hide and show labels with 'overlabel' class names.
  labels = document.getElementsByTagName('label');
  for (i=0; i < labels.length; i++){

    if(labels[i].className == 'overlabel'){

      // Skip labels that do not have a named association with another field.
      id = labels[i].htmlFor || labels[i].getAttribute('for' );
      if(!id || !(field = document.getElementById(id)) ){
        continue;
      } 

      // Change the applied class to hover the label over the form field.
      labels[i].className = 'overlabel-on';

      // Hide any fields having an initial value.
      if(field.value !== ''){
        hideLabel(field.getAttribute('id'), true);
      }

      // Set handlers to show and hide labels.
      field.onfocus = function (){
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function (){
        if(this.value === ''){
          hideLabel(this.getAttribute('id'), false);
        }
      };

      // Handle clicks to label elements (for Safari).
      labels[i].onclick = function (){
        var id, field;
        id = this.getAttribute('for' );
        if(id && (field = document.getElementById(id)) ){
          field.focus();
        }
      };

    }
  }
}
function hideLabel(field_id, hide){
  var field_for, labels, i;
  labels = document.getElementsByTagName('label' );
  for (i=0; i < labels.length; i++){
    field_for = labels[i].htmlFor || labels[i].getAttribute('for' );
    if(field_for == field_id){
      labels[i].style.textIndent = (hide) ? '-1000px' : '0px';
      return true;
    }
  }
}


/* 
initCarousel:
sets up jQuery carousel
*/
function initCarousel(){
    $("#spotlight .items").jcarousel({
        scroll: 1,
        wrap: 'both',
        initCallback: spotlight_initCallback,
		itemVisibleInCallback:  spotlight_active,
		itemVisibleOutCallback: spotlight_inactive
    });
}
function spotlight_initCallback(carousel) {
    $('#spotlight .pager li a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        $('#spotlight .items li').removeClass('on');
        return false;
    });
    
    $('#spotlight .next').bind('click', function() {
        carousel.next();
        $('#spotlight .items li').removeClass('on');
        return false;
    });

    $('#spotlight .prev').bind('click', function() {
        carousel.prev();
        $('#spotlight .items li').removeClass('on');
        return false;
    });

}

// add active class
function spotlight_active(carousel, obejctli,index,listate){
	$('#spotlight .pager ol li:nth-child('+ index +')').addClass('on');
	$('#spotlight .items li:nth-child('+ index +')').addClass('on');
}

// remove active class
function spotlight_inactive(carousel, obejctli,index,listate){
	$('#spotlight .pager ol li:nth-child('+ index +')').removeClass('on');
}


/*
execute scripts on DOM load
*/
$(document).ready(function(){
	addBodyClass();
	initCarousel();
	overLabels();
});

/*
Product Tab Menus
*/
function set_tab_state (parent_div) {
		if($(parent_div +' .tab1').css("display")=="none")
		{
			$(parent_div +' .tab1link').removeClass('selected1');
			$(parent_div +' .tab2link').addClass('selected2');
		}else{
			$(parent_div +' .tab1link').addClass('selected1');
			$(parent_div +' .tab2link').removeClass('selected2');
		}
	}
	
	function show_tab1 (parent_div) {
		$(parent_div+" .tab1").show();
		$(parent_div+" .tab2").hide();
		set_tab_state(parent_div);
	}
	function show_tab2 (parent_div) {
		$(parent_div+" .tab1").hide();
		$(parent_div+" .tab2").show();
		set_tab_state(parent_div);
	}
	// $('#atca .tab1link').click(function(){show_tab1('#atca');})
		// 	$('#atca .tab2link').click(function(){show_tab2('#atca');})
			
	function switch_tab (link,parent_div) {
			t = jQuery.trim($(link).text());
		if(t=="Categories")
		{	
			show_tab1(parent_div);
		}else if(t=="Products"){
			show_tab2(parent_div);			
		}else{
			show_tab1(parent_div);
		}
	}
	

/*
Contact and Support Accordion
*/
$(document).ready(function(){
    $("#contact-accordion").accordion({ event: 'mouseover' });
 });

//Video Slider Done Locally On Product Category Front Pages

/*
execute scripts on DOM load

$(document).ready(function(){
	if(!window.opera) {
		initCarousel();
	}
});
*/

/*
Datahseet Tabs 
*/
function show_section(section)
{
	$('#orderinfo').hide();
	$('#description').hide();
	$('#specs').hide();
	$('#features').hide();
	$(section).show();
	
}
function set_active(link)
{
	$('#link_description').removeClass('selected');
	$('#link_features').removeClass('selected');
	$('#link_specifications').removeClass('selected');
	$('#link_orderinfo').removeClass('selected');
	$(link).addClass('selected');
}

$(document).ready(function(){
	show_section('#description');
	set_active('#link_description');
});



// Products Drop Down Menu

	var popupnav = null;
	function hide_menu()
	{
		if(popupnav==true)
		{
		$('#menu-container').hide();
		$('#menu-on-products').hide();
		popupnav = null;		
		}else{
			popunav=null;
		}
	}
	function show_menu()
	{
		if(popupnav==null)
		{
		$('#menu-container').show();
		$('#menu-on-products').show();
		popupnav=true;
		}else{
			popupnav=true;	
		}
	}

$(document).ready(function() {

/*
	$('.productshover').hover(
		function(){
			setTimeout("show_menu(popupnav)",100);
		},
		function(){
			setTimeout("hide_menu(popupnav)",200);
		});	
*/
	
	$('.nav-products').hover(
		function(){
			show_menu();
		});
	$('#menu-container').hover(
		function(){
			show_menu();
		},
		function(){
			setTimeout("hide_menu()",200);
		});	
	$('.nav-who').hover(
		function(){
			setTimeout("hide_menu()",200);
		}
	);

	$('.nav-news').hover(
		function(){
			setTimeout("hide_menu()",200);
		}
	);
	$('#logo').hover(
		function(){
			setTimeout("hide_menu()",200);
		}
	);


});	


//Platform Partners Slider
$(document).ready(function(){
	$(".tab-content h3:first").addClass("active");
	$(".tab-content ul:not(:first)").hide();

	$(".tab-content h3").click(function(){
		$(this).next("ul").slideToggle("slow")
		.siblings("ul:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});

});

//Gerneralized Tabs - this will replace the partner code above
$(function () {
	var tabContainers = $('div#tab-box > ul'); //Grab all of the ordered lists in div tab-box 
    tabContainers.hide().filter(':first').show(); //Hide all of the ordered lists in div tab-box except the first which will serve as the default
                        
    $('div#tabs ul.selectTabs a').click(function () { //On click of the anchor tags under unordered list of patner-tabs perform the following functions
    	tabContainers.hide(); //trigger our variable to hide and show
        tabContainers.filter(this.hash).show(); //show the ordered list with the correpsonding id
        	$('div#tabs ul.selectTabs a').removeClass('active'); //remove the active class on the achor tag under the partner-tabs list
        	$(this).addClass('active'); //add the active class to the corresponding anchor tag
            return false;
     }).filter(':first').click(); //default first tab is active until interaction
});



//Solutions Widget
$(document).ready(function(){
	$("#contact-accordion").accordion({ event: 'mouseover', fillSpace:true }); //REMEMBER TO SET FILLSPACE TO TRUE
});
$(document).ready(function(){
	//This setting is for 3 library sections wih scroll bars. Does not automatically fit content.
	$("#solutions-accordion").accordion({ event: 'mouseover', fillspace: true, autoHeight: false, clearStyle: true}); 
}); 

		

//Old JS - depricate soon

var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function obfuscate_email(first,second,last)
{
  prefix ="mailto:";
  
  document.write('<a href="'+prefix+first+second+'@'+last+'">'+first+second+'@'+last+'</a>');
}

/* hide and show div stuff. */
function showDiv(id,style)
{
	var style = (style == null) ? "inline" : style;
	document.getElementById(id).style.display=style; 
}
function closeDiv(id)
{
	document.getElementById(id).style.display="none"; 
}

/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com

	Examples of how to call the function:
	
	To get all a elements in the document with a "info-links" class:
    getElementsByClassName(document, "a", "info-links");
    
	To get all div elements within the element named "container", with a "col" and a "left" class:
    getElementsByClassName(document.getElementById("container"), "div", ["col", "left"]);
*/

function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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 eraseCookie(name) {
	createCookie(name,"",-1);
}

function setSearchBG(state)
{
	d= document.getElementById('navSearchbox');
	q= document.getElementById('q');
	if(state =="blur")
	{
			q.value == "SEARCH";
			d.style.backgroundImage="url('images/icons/search/search_box.gif')";
	}else{
		if(q.value.length>1 && q.value != "SEARCH")
		{
			d.style.backgroundImage="url('images/icons/search/search_box_active.gif')";
			q.style.color="#e96419";
		}else{
			d.style.backgroundImage="url('images/icons/search/search_box.gif')";
			q.style.color="#C7D3DC";
		}	
	}
}
function clearSearchForm()
{
	q = document.getElementById('q');
	if(q.value=="SEARCH")
	{
		q.value ="";
	}
}		

function select_redirect(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/* DOCUMENT LIBRARY sliders */
$(document).ready(function(){
	$("#documents h3:first").addClass("active");
	$("#documents ul:not(:first)").hide();
	$("#documents h3").click(function(){
		$(this).next("ul").slideToggle("slow").siblings("ul:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});
});

