
$(document).ready(function() {
	
	var activeItem
	var activeAncestor
	var currentTab
	var finished = true
 	
	hideTabs() 
 
	activeItem = $(".current_page_item")  	//save the active tab
	activeAncestor = $(".current_page_ancestor")  	//save the active tab
	showActive() 		//show the active tab

	$('ul#sub_nav').children().each(function(i)
	{
		$(this).find("a").addClass("pagelink")
			
	});

	
	$('ul#sub_nav li').mouseenter(function (event)
	{	
		
		if (finished)
		{
			currentTab = $(this).find("ul.children")
		     
			
			if ($(this).children().find("a").attr('class') == 'pagelink')
			{
	 
				$('ul#sub_nav').children().each(function(i){
					var name = $(this).find("ul.children").attr('class')
					if (name != 'children active_page')
					{
						$(this).find("ul.children").slideUp('slow', function() {});
						finished = false
					}
				 }); 
			}
			
		}
		$(currentTab).slideDown('slow', function() { finished=true}); //this only wants to file when u rerst over an item
 
	})
 
	
	$('.box_206_inside').mouseleave(function () {

	 	$('ul#sub_nav').children().each(function(i){
 
				var name = $(this).find("ul.children").attr('class')
				
				if (name != 'children active_page')
				{
					$(this).find("ul.children").slideUp('slow', function() {});					
				}
				
			});
	 finished=true
	});
 
	
	function hideTabs()
	{
		$('ul.children').hide();
		showActive()
	}
	
	function showActive()
	{
		$(activeItem).children().show(); 
		$(activeAncestor).children().show(); 
		$(activeItem).find("ul.children") .addClass("active_page")
		$(activeAncestor).find("ul.children").addClass("active_page")
	}
 
		

	$('#home_plastics_title').hide();							
	setTimeout( function() {
		$('#home_plastics_content').slideUp('slow', function() {});
		$('#home_plastics_title').fadeIn('slow', function() {});
	}, 5000 );	
	
	$('#home_nonplastics_title').hide();							
	setTimeout( function() {
		$('#home_nonplastics_content').slideUp('slow', function() {});
		$('#home_nonplastics_title').fadeIn('slow', function() {});
	}, 5000 );							
								
	


	$("#home_plastics").hover(
	  function () {
		$('#home_plastics_content').slideDown('slow', function() {});
		$('#home_plastics_title').fadeOut('slow', function() {});
	  },
	  function () {
		$('#home_plastics_content').slideUp('slow', function() {});
		$('#home_plastics_title').fadeIn('slow', function() {});
	  }
	);


	$("#home_nonplastics").hover(
	  function () {
		$('#home_nonplastics_content').slideDown('slow', function() {});
		$('#home_nonplastics_title').fadeOut('slow', function() {});
	  },
	  function () {
		$('#home_nonplastics_content').slideUp('slow', function() {});
		$('#home_nonplastics_title').fadeIn('slow', function() {});
	  }
	);
	
	
	
	
	
	
	// Main navigation big drop downs
	//hide all the menus
	var finishedAbout = false;
	var finishedCareer = false;
	var finishedProduct = false;
	
	$('#main_nav_about').hide();
	$('#main_nav_careers').hide();
	$('#main_nav_products').hide();
	
	
	$("#mn_about_link").parent().mouseenter(function() {
		if (!finishedAbout){
			$('#main_nav_about').slideDown('slow', function() {});
			finishedAbout=true
		}
	}).mouseleave(function() {
		if (finishedAbout){
			$('#main_nav_about').slideUp('slow', function() {finishedAbout=false});
		}
	 });
	 //////////----------------------------------------------------------------------------------------
	  $("#mn_career_link").parent().mouseenter(function() {
		if (!finishedCareer){
			$('#main_nav_careers').slideDown('slow', function() {});
			finishedCareer=true
		}
	}).mouseleave(function() {
		if (finishedCareer){
			$('#main_nav_careers').slideUp('slow', function() {finishedCareer=false});
		}
	 });
	 //////////----------------------------------------------------------------------------------------
	 $("#mn_products_link").parent().mouseenter(function() {
		if (!finishedProduct){
			$('#main_nav_products').slideDown('slow', function() {});
			finishedProduct=true
		}
	}).mouseleave(function() {
		if (finishedProduct){
			$('#main_nav_products').slideUp('slow', function() {finishedProduct=false});
		}
	 });
	 
	 
	 $("#main_nav_container").mouseleave(function() {
	 
			$('#main_nav_about').slideUp('slow', function() {finishedAbout=false});
			$('#main_nav_careers').slideUp('slow', function() {finishedCareer=false});
			$('#main_nav_products').slideUp('slow', function() {finishedProduct=false});
	 
	 });
	 
	 
	 /*$("#mn_products_link").parent().mouseenter(function() {
		$('#main_nav_products').slideDown('slow', function() {});
	}).mouseleave(function() {
		$('#main_nav_products').hide();
	 });*/
	
 
	
	
	
	
	
	// subnavigation
	$( ".accordion" ).accordion({
		event: "mouseover",
		autoHeight: false,
		navigation: true
	});
	

	
	

});	
