$(document).ready(function(){

	swapValues = [];
    $(".swap").each(function(i){swapValues[i] = $(this).val();
        $(this).focus(function(){if ($(this).val() == swapValues[i]) {$(this).val("");}}).blur(function(){ if ($.trim($(this).val()) == "") {$(this).val(swapValues[i]);}});
	});
	
	//Handle offsite links
	$('#content a').filter(function() {
		var theHref = this;
		if (theHref.hostname && theHref.hostname !== location.hostname) {
			$(theHref).not(".noAutoIcon").addClass("offSite");
			$(theHref).not(".noAutoLink").bind('click keypress', function(event) {
				var code=event.charCode || event.keyCode;
				if (!code || (code && code == 13)) {
					if(pageTracker){
						var fixedLink = this.href;
						fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1");
						fixedLink = '/outgoing/' + fixedLink;
						pageTracker._trackPageview(fixedLink);
					};
				};
			});
		};
	});
	
	//Automatic PDF file handling
	$("a[@href$='.pdf']:not(.noAutoIcon)").addClass("pdf");
	$("a[@href$='.pdf']").bind('click keypress', function(event) {
		var code=event.charCode || event.keyCode;
		if (!code || (code && code == 13)) {
			if(pageTracker){
				var fixedLink = "/downloaded-files/pdf/" + this.pathname;
				pageTracker._trackPageview(fixedLink);
			};
		};
	});
	
	//Track Downloads
	$("a.download").bind('click keypress', function(event) {
		var code=event.charCode || event.keyCode;
		if (!code || (code && code == 13)) {
			if(pageTracker){
				var fixedLink = "/downloaded-files/misc/" + this.pathname;
				pageTracker._trackPageview(fixedLink);
			};
		};
	});
	
	//colored OL
	$('ol li').wrapInner('<span class="olcontent"></span>').addClass('olcolor');
	
	//Nav
	$('ul#main-nav li').hover(function(){
		$(this).addClass('active');	
	},function(){
		$(this).removeClass('active');
	});
	
	$("body#supportDownloads ul:not(:has(li))").append("<li>No downloads in this category.</li>");
	
	var limit = 2;//desired number - 1;
	$("ul",$("#portlets")).each(function(){
		if($(this).parent("div").attr("id") == "multimedia"){limit = limit - 1;}
		currClass = $(this).parent("div").attr("class");
		//if(currClass != "standard"){
			var totalLi = $(this).children("li");
			var childCount = totalLi.size();
			if(childCount <= limit){
				$(this).next("a.all").addClass("all-hide");
			}else{
				for(i=0; i<childCount; i++){
					if(i > limit){
						$(totalLi[i]).addClass("hide");
					}
				}
			}
		//}
		if($(this).parent("div").attr("id") == "multimedia"){limit = limit + 1;}
	});
	
	$("a.all", $("#portlets")).each(function(){
		if($(this).prev("ul").parent("div").attr("id") == "multimedia"){limit = limit - 1;}
		count = $(this).prev("ul").children().length;
		if(count <= (limit+1)){$(this).addClass("hide");}
		if($(this).prev("ul").parent("div").attr("id") == "multimedia"){limit = limit + 1; }	 
		$(this).toggle(function(){
			$(this).addClass("less");
			$(this).children("span.toggle").text("Less");
			$(this).prev("ul").children("li.hide").removeClass("hide");
			return false;
		},function(){
			if($(this).prev("ul").parent("div").attr("id") == "multimedia"){limit = limit - 1;}
			$(this).removeClass("less");
			$(this).children("span.toggle").text("All");
			var totalLi = $(this).prev("ul").children("li");
			var childCount = totalLi.size();
			for(i=0; i<childCount; i++){
				if(i > limit){
					$(totalLi[i]).addClass("hide");
				}
			}
			if($(this).prev("ul").parent("div").attr("id") == "multimedia"){limit = limit + 1; }
			return false;
		});
		
	});
	
	//add left border
	$("table.standard thead th:first").addClass("lb");
	
	whereitat = window.location + "";
	splitUrl = whereitat.split("/");
	if(splitUrl[3] == "About"){
		$("li#about-pbbi").addClass("current");
	}else if(splitUrl[3] == "Communities"){
		$("li#communities").addClass("current");
	}else if(splitUrl[3] == "Partners"){
		$("li#partners").addClass("current");
	}else if(splitUrl[3] == "Products"){
		$("li#products").addClass("current");
	}else if(splitUrl[3] == "Resources"){
		$("li#resources").addClass("current");
	}else if(splitUrl[3] == "Solutions"){
		$("li#solutions").addClass("current");
	}else if(splitUrl[3] == "Support"){
		$("li#support").addClass("current");
	}else if(splitUrl[3] == "index.html"){
		$("li#home").addClass("current");	
	}
	
	$("a.flash-pop").click(function(){
		var rel = $(this).attr("rel");
		$('#showFlash').css('display', 'block').flash({ swf: '/flash/Player.swf', height: 400, width:550, params: { wmode:'transparent'}, flashvars:{flv:rel}}); 
		return false;
	});
	
	
	$("#content a[href$='.flv']").each(function(){
		rel = $(this).attr("href");
		$(this).addClass("thickbox ").attr({"rel":rel,"href":"#TB_inline?height=420&width=550&inlineId=flashPlayer"});
		$(this).click(function(){
		$('#showFlash').css('display', 'block').flash({ swf: '/flash/Player.swf', height: 400, width:550, params: { wmode:'transparent'}, flashvars:{flv:rel}}); 
			return false;
		});
	});
			
		
	
	$('li.print a').click(function(){
		window.print();
		return false;
	});
	
	//add left border
	$("table.standard thead th:first").addClass("lb");
	
	//bios
	
	bioArray = $("div.col1 div.bio");
	var even = 1;
	for(i=0; i<bioArray.length; i++){
		if(i == 0){
			$(bioArray[0]).addClass("firstBio");
		}
		if(even == 1){
			$(bioArray[i]).addClass("nrm");
			even = 0;
		}else{
			even = 1;
		}
	}
	
	$("div#comments div.comment:odd").addClass("odd")	
	
	//Removes bottom-border from last item in secondary navigation
	$('div#secondary-nav li:last').addClass('last');
	
	$('div#secondary-nav ul').each(function(){
		if($(this).children("li").length == 0){
			$(this).remove();
		}
	});
	
	$('a.content-edit').parent("p").addClass("logged-in");
});