$(document).ready(function(){
	//Custom Tabs code
	var tabli = $("ul.tabs li");
	var divs = $("#inner-tab div");
	$(tabli).click(function(){
			$(tabli).each(function(){
				$(this).removeClass("active");	
			});
			var whattab = $(this).attr("class");
			$(this).addClass("active");
			$(divs).each(function(){
				$(this).removeClass("show");
			});
			$("div#"+whattab).addClass("show");
	});
	
	//Evens the heights of the paragraphs in the product columns
	var pHeight = $("#product-categories div p");	
	if(pHeight.length == 3){
		var ph1 = $(pHeight[0]).height();
		var ph2 = $(pHeight[1]).height();
		var ph3 = $(pHeight[2]).height();
		if(ph1 >= ph2 && ph1 >= ph3){
			$(pHeight).each(function(){
				$(this).css("height", ph1); 						 
			});
		}else if(ph2 >= ph1 && ph2 >= ph3){
			$(pHeight).each(function(){
				$(this).css("height", ph2); 						 
			});
		}else if(ph3 >= ph1 && ph3 >= ph2){
			$(pHeight).each(function(){
				$(this).css("height", ph3); 						 
			});
		}
	}
	
	//
	$("img.clear").click(function(){
		$(this).parent().parent().clearForm();							  
	});
	
	//Clear form funciton
	$.fn.clearForm = function() {
	  return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
		  return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
		  this.value = '';
		else if (type == 'checkbox' || type == 'radio')
		  this.checked = false;
		else if (tag == 'select')
		  this.selectedIndex = -1;
	  });
	};
	
	var change;
	var changeText;
	$(".releases .view-all").toggle(function(){
			change = $(this).parent().parent().children(".view").children(".view-all");
			changeText = $(this).parent().parent().children(".view").children(".view-all").children(".view-what");
				$(change).removeClass("view-all").addClass("view-five");	
				$(changeText).text("Top 5");
				$(".releases dl").each(function(){
					showAll = $(this).children();
					for(i=0; i<showAll.length; i++){
						$(showAll[i]).slideDown("fast");
					}
				});	
			},function(){
				$(change).removeClass("view-five").addClass("view-all");
				$(changeText).text("All");
				$(".releases dl").each(function(){
					hideAll = $(this).children();
					for(i=0; i<hideAll.length; i++){
						if(i > 9){ // 9 in the array will show 10 children 5 dt and 5 dd
							$(hideAll[i]).slideUp("fast");
						}
					}
				});	
	});
	
	var change2;
	var changeText2;
	$(".in-the .view-all").toggle(function(){
			change2 = $(this).parent().parent().children(".view").children(".view-all");
			changeText2 = $(this).parent().parent().children(".view").children(".view-all").children(".view-what");
				$(change2).removeClass("view-all").addClass("view-five");	
				$(changeText2).text("Top 5");
				$(".in-the dl").each(function(){
					showAll = $(this).children();
					for(i=0; i<showAll.length; i++){
						$(showAll[i]).slideDown("fast");
					}
				});	
			},function(){
				$(change2).removeClass("view-five").addClass("view-all");
				$(changeText2).text("All");
				$(".in-the dl").each(function(){
					hideAll = $(this).children();
					for(i=0; i<hideAll.length; i++){
						if(i > 9){ // 9 in the array will show 10 children 5 dt and 5 dd
							$(hideAll[i]).slideUp("fast");
						}
					}
				});	
	});
	
	//Show dd and dt on load
	
	$(".press dl").each(function(){
		firstFive = $(this).children();
		for(i=0; i < 10; i++){
			$(firstFive[i]).css("display", "block");	
		}
	});	

	//Zebra striping for table
	$('table.careers tr:even').addClass('stripe');
	$('table.careers td:odd').addClass('lb');
	$('table.careers th:odd').addClass('lb');
	
	$('dl.down-notes:last').css('background', 'none');
});	
