//Header Navigation Functions
$(document).ready(function(){
	
	//Header Navigation Drop Down
	$("a.drop").append("<span></span>");
	
	$("li.drop").hover(function(){
		$(this).find("ul.dropdown").slideDown('fast').show();	
		$(this).hover(function() {
			}, function() { 
				$(this).find("ul.dropdown").slideUp('fast');
		});
		
		}).hover(function() { 
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
	});
	
	//International Selection
	$("a.change").click(function(){
		$("#locationChange").toggle();							 
	});

	//Search Box
	window.onload = function() {
	  applyDefaultValue(document.getElementById('ffQ'), 'Search...');
	}
	
	function applyDefaultValue(elem, val) {
	  elem.style.color = '#525252';
	  elem.value = val;
	  elem.onfocus = function() {
		if(this.value == val) {
		  this.style.color = '';
		  this.value = '';
		}
	  }
	  elem.onblur = function() {
		if(this.value == '') {
		  this.style.color = '#525252';
		  this.value = val;
		}
	  }
	};

});


/*
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");
	});
});



