//adding a class "first" to every first li element and "last" to every last li element
$(document).ready(function(){
	$("body").removeClass("noJavaScript");
	$("li:first-child").addClass("first");
	$("li:last-child").addClass("last");
	/*centerWrappedImages()*/
	subCatMenus();
	longInfoTabs();
	/*hiliteFocus();*/
});//END (document).ready



function longInfoTabs(){
  $( '#longInfo div:not(:first) p' ).hide();
  $('#longInfoNav li').click(function(e) {
		$('#longInfo div p').hide();
		$('#longInfoNav .current').removeClass("current");
		$(this).addClass('current');
		var clicked = $(this).find('a:first').attr('href');
		$('#longInfo ' + clicked + ' p').fadeIn('fast');
		e.preventDefault();
  }).eq(0).addClass('current');
}

function subCatMenus(){
	if ($('#categoryNav .subList').length){
		widthSubCatMenus();
		$('#categoryNav .subList').css({display: "none",left: "25px"});
		$('#categoryNav .subList li a').css({height: "0px"});
		$('#categoryNav .mainList > li > a').click(function(e) {e.preventDefault();});
		$('#categoryNav .subList a').click(function(e){e.stopPropagation();});
		$('#categoryNav .mainList > li').hoverIntent(function() {
			var current = $(this), currentSub = $(current).find('ul');
			$(current).children('a').addClass('hovered');
			$('#categoryNav .subList').css({display: "none",left: "25px"});
			$('#categoryNav .subList li a').css({height: "0px"});
			$(currentSub).show().find('li a').animate({height: '26px'}, {duration: 'fast', queue: false});
		}, function() {
			var current = $(this), currentSub = $(current).find('ul');
			if ( $.browser.msie ) {
				$(currentSub).hide().find('li a').css('height', '0px');
			 } else {
				$(currentSub).fadeOut('fast', function(){$(currentSub).find('li a').css('height', '0px');});
			 }
			$(current).children('a').removeClass('hovered');
		});
	}
}

function widthSubCatMenus(){
	var mainCategories = $('#categoryNav .mainList > li');
	for (i=0;i<mainCategories.length;i++){
		var current = mainCategories[i],
			widestLi = 0,
			currentSubCats = $(current).find('li a');
		for (j=0;j<currentSubCats.length;j++){
			var currentLiWidth = $(currentSubCats[j]).width();
			if(currentLiWidth > widestLi){widestLi = currentLiWidth;};
		$(currentSubCats).css('width', widestLi);
		};
	};
}

function centerWrappedImages(){
	$('.imgWrap').each(function(){
		var $this = $(this),
			wrapHeight = $this.height(),
			imgHeight = $this.find('img').height(),
			verPadding = (wrapHeight - imgHeight)/2;
		$($this).css({'height':imgHeight, 'padding-top':verPadding, 'padding-bottom':verPadding});
	});
}

function hiliteFocus(){
	var editcells = document.getElementsByTagName('input');
	for (var i = 0; i < editcells.length; i++) {
		editcells[i].onfocus = function() {
			this.className += ' hilite';
		}
		editcells[i].onblur = function() {
			this.className = this.className.replace('hilite', '');
		}
	}
}

//JavaScript Document
function ExpandItem(item1,item2,label)
{

 obj = document.getElementById(item1);
 
 obj2 = document.getElementById(item2);

 visible = (obj.style.display != 'none');


 if (visible)

 {

 obj.style.display = 'none';
 obj2.src="pages/media/plus.gif";
 }

 else

 {

 obj.style.display = 'block';
 obj2.src="pages/media/minus.gif";
 }

}


var cur_lyr = "features";
function swapLayers(id, selected) {
document.getElementById('current').id='';
selected.parentNode.id='current';
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "block";
}

function hideLayer(id) {
var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "none";
}


function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();


