	$(function() { 
	
		// This is for the feedback tab that lives on every page.
		
		$('#feedback-tab').click(function(){
			if($(this).hasClass('clicked')){
				closeFeedback()
			} else {
				$(this).addClass('clicked').css('right',623);
				$('#feedback-container').fadeIn(100);
				var totalHeight = $(window).height();
				$('#feedback-overlay').css('height',totalHeight).fadeIn(100);
			}
		});
		
		function closeFeedback(){ 
			$('#feedback-tab').removeClass('clicked').css('right',0);
			$('#feedback-container').fadeOut(100);
			$('#feedback-overlay').fadeOut(100);
		}
	
		$('#feedback-close').click(function(){ closeFeedback() });
		$('#feedback-overlay').click(function(){ closeFeedback() });
		
		
		// Main nav drop downs
	
		function dropShow() {
			$(this).children('.main-category').addClass('hover'); //Keeps the main category pink while navigating the subs
			$(this).children('.subcategories').slideDown();
		}
		
		function dropHide() {
			$(this).children('.main-category').removeClass('hover');
			$(this).children('.subcategories').slideUp();
		}
		
		$('#main-nav li').hoverIntent({
			interval: 50, // milliseconds delay before onMouseOver
			over: dropShow, 
			timeout: 100, // milliseconds delay before onMouseOut
			out: dropHide
		});
			
		/* Cycle on the homepage if Flash is not present */
		if($('html').is('.iphone, .ipod, .ipad, .noflash')){
			$('#branding-slides').cycle({  
				timeout: 9000
			});
		}
		
		// News Section Height and Hovers
		
			var newsHeight;
			$('.news-text').each(function() { 
				newsHeight = $(this).height();
				$(this).parent('li').css('height',newsHeight+16);
			});
			
			function newsExpand() {
				$(this).children('img').hide();
				if($(this).height() <= 16) {
					$(this).animate({ paddingTop: "12px", paddingBottom: "12px" }, 200);
				} else {
					$(this).animate({ paddingTop: "8px", paddingBottom: "8px" }, 200);
				}
			}
			
			function newsContract() {
				$(this).children('img').show();
				$(this).animate({ paddingTop: "2px", paddingBottom: "2px" }, 200);
			}
			
			$('.news-text').hoverIntent({
				interval: 100,
				over: newsExpand,
				timeout: 100,
				out: newsContract
			});
			
		// Following section is for the homepage teasers

			// This part gets the tallest teaser height
			var teaserHeight = 0;
			var currentHeight = 0;
			$('.teaser').each(function() { 
				currentHeight = $(this).height();
				if(teaserHeight < currentHeight) { teaserHeight = currentHeight };
			});
			
			// Equal teaser heights
			$('.teaser a').css('height',teaserHeight); 
			$('#hpb-right').css('height',teaserHeight+40);

			// HoverIntent Functions
			function teaserExpand() {
				$(this).animate({ paddingBottom: "20px" }, 200);
			}
			
			function teaserContract() {
				$(this).animate({ paddingBottom: "10px" }, 200);
			}
			
			$('.teaser a').hoverIntent({
				interval: 100,
				over: teaserExpand,
				timeout: 100,
				out: teaserContract
			});
		
		// Sets up the variety of tabs on the site
		
			//$('#property-tabs, #processing-tabs, #grades-tabs').tabs();
			
		// Slider on Processing Page 
		
			$('#processing-tabs ul li a').click(function(){  
				$('#slideshow01, #slideshow02, #slideshow03, #slideshow04, #slideshow05').cycle(0);
			});

			var element;
			function showCaption(num) {
				element = '';
				if($('#slideshow0'+num+' img:visible').size()) {
					element = $('#slideshow0'+num+' img:visible');
				} else {
					element = $('#slideshow0'+num+' img:eq(0)');
				}

				$('#slideshow0'+num).siblings('.caption').html('<p>'+$(element).attr('alt')+'</p>'); 
				$('#slideshow0'+num).siblings('.title-nav').children('.slideshow-title').html($(element).attr('rel'));
			}
		
			$('#slideshow01').cycle({  
				fx: 'fade',
				speed: 'fast',
				timeout: 5000,
				pager: '.pager1',
				after: function() {showCaption(1);}
			});
			
			$('#slideshow02').cycle({  
				fx: 'fade',
				speed: 'fast',
				timeout: 5000,
				pager: '.pager2',
				after: function() {showCaption(2);}
			});
			
			$('#slideshow03').cycle({  
				fx: 'fade',
				speed: 'fast',
				timeout: 5000,
				pager: '.pager3',
				after: function() {showCaption(3);}
			});
			
			$('#slideshow04').cycle({  
				fx: 'fade',
				speed: 'fast',
				timeout: 5000,
				pager: '.pager4',
				after: function() {showCaption(4);}
			});
			
			$('#slideshow05').cycle({  
				fx: 'fade',
				speed: 'fast',
				timeout: 5000,
				pager: '.pager5',
				after: function() {showCaption(5);}
			});
			
		// Auto slider on Application Pages	
		
			$('#slider').cycle({  
				fx: 'fade',
				speed: 'fast',
				timeout: 4000,
				pager: '#nav'
			});
			
		// Environment page accordion and more
		
			$('#links li').hover(function(){ 
				$(this).children('span').addClass('active');
			}, function(){ 
				$(this).children('span').removeClass('active');
			});
			
			$('#links li:nth-child(5)').hover(function(){ 
				$('#pictures li span').addClass('active')
			}, function(){ 
				$('#pictures li span').removeClass('active')
			});
			
			$('#links li:nth-child(5) a').addClass('active');
			$('#pictures li span').addClass('active');

			var activeEnv;
			$('#links li a').click(function(){
				if($(this).attr('href') == activeEnv) {
					$('#links li a').removeClass('active');
					$('#links li span').removeClass('active-click');
					$('#pictures li span').removeClass('active-click');
					$('#accordion-content').slideUp();
					activeEnv = "";
				} else { 
					// Clear Currently Active
					$('#links li a').removeClass('active');
					$('#links li span').removeClass('active-click');
					$('#pictures li span').removeClass('active-click');
					
					// Show Just Clicked
					$(this).addClass('active');

					if($(this).hasClass('down-arrow')) {
						$('#pictures li span').addClass('active-click');
					} else {
						$(this).siblings('span').addClass('active-click');
					};
					
					$('.accord-section,.accord-section-sm').hide();
					activeEnv = $(this).attr('href');
					$(activeEnv).show();
					$('#accordion-content').slideDown();
				};
			});
			
			var maxHeight = 0;
			$('#links li a:not(.active)').each(function() {
				var linkHeight = $(this).innerHeight();
				if(linkHeight > maxHeight) { maxHeight = linkHeight;}
				//alert(linkHeight);
			});
			
			$('#links li a').css('height',(maxHeight-33)+'px'); //Take the height, minus the padding// Environment page accordion and more
		
		//Life Cycle Page
		
			$('#links-life-cycle li').hover(function(){ 
				$(this).children('span').addClass('active');
			}, function(){ 
				$(this).children('span').removeClass('active');
			});
			
			$('#links-life-cycle li:nth-child(0)').hover(function(){ 
				$('#pictures li span').addClass('active')
			}, function(){ 
				$('#pictures li span').removeClass('active')
			});
			
			$('#links-life-cycle li:nth-child(0) a').addClass('active');
			$('#pictures li span').addClass('active');

			var activeEnv;
			$('#links-life-cycle li a').click(function(){
				if($(this).attr('href') == activeEnv) {
					$('#links-life-cycle li a').removeClass('active');
					$('#links-life-cycle li span').removeClass('active-click');
					$('#pictures li span').removeClass('active-click');
					$('#accordion-content').slideUp();
					activeEnv = "";
				} else { 
					// Clear Currently Active
					$('#links-life-cycle li a').removeClass('active');
					$('#links-life-cycle li span').removeClass('active-click');
					$('#pictures li span').removeClass('active-click');
					
					// Show Just Clicked
					$(this).addClass('active');

					if($(this).hasClass('down-arrow')) {
						$('#pictures li span').addClass('active-click');
					} else {
						$(this).siblings('span').addClass('active-click');
					};
					
					$('.accord-section').hide();
					activeEnv = $(this).attr('href');
					$(activeEnv).show();
					$('#accordion-content').slideDown();
				};
			});
			
			var maxHeight = 0;
			$('#links-life-cycle li a:not(.active)').each(function() {
				var linkHeight = $(this).innerHeight();
				if(linkHeight > maxHeight) { maxHeight = linkHeight;}
				//alert(linkHeight);
			});
			
			$('#links-life-cycle li a').css('height',(maxHeight-33)+'px'); //Take the height, minus the padding
			
		// Grade Page Equal Height-ify
		
			var geHeight;
			
			function gradeHeight(gradeID) {
				geHeight = $('#'+gradeID).outerHeight();
				$('#'+gradeID+' .grade-bg').css('height',(geHeight));
				$('#grades-list').css('height',geHeight);
			}
			
			$('#grades-list ul li a').click(function() {
				gradeHeight($(this).attr('rel'));
			});
			
			gradeHeight('recycled');
			
		// Tech Docs Accordion
			
			/* Code to make the first accordion of all tech docs active and open. Commented out on 11/05/10
			
				$('.tech-docs').each(function() {
					$(this).children('dt:first').addClass('active');
					$(this).children('dd:first').show();
				});
				
			*/
			
			$('.tech-docs dt').hover(function(){  
				$(this).addClass('hover');
			}, function(){
				$(this).removeClass('hover');
			});
			
			var sidenavHeight;
			
			$('.tech-docs dt').click(function(){
				if($(this).hasClass('active')){
					$(this).removeClass('active');
					$(this).next('dd').slideUp();
				} else {
					$(this).siblings('dt').removeClass('active');
					$(this).siblings('dd').slideUp().delay(500);
					$(this).addClass('active');
					$(this).next('dd').slideDown();
				}
			});
			
		// Tech Docs Sidebar
			
			////Rollover state for according title supplier docs
			/*$(".section-name-locked").hoverIntent({
				interval: 0,
				over: supplierHoverIn,
				timeout: 0,
				out: supplierHoverOut
			});
			
			function supplierHoverIn() {
				if(!lockedSupplierAccordionOpen) {
					$(".section-name-locked").css('background','url('+includePath+'img/layout/locked_gr.gif) 6px 2px no-repeat');
				} 
			}
			
			function supplierHoverOut() {
				if(!lockedSupplierAccordionOpen) {
					$(".section-name-locked").css('background','url('+includePath+'img/layout/locked_ma.gif) 6px 2px no-repeat');
				} 
			}
			
			$('.section-name').click(function() {
				$(".section-name-locked").css('background','url('+includePath+'img/layout/locked_ma.gif) 6px 2px no-repeat');
				lockedSupplierAccordionOpen = false;
			});
			
			//////////////////////////////////////////////////////
			
			var lockedSupplierAccordionOpen = false;
			$(".section-name-locked").click(function() {
				if(lockedSupplierAccordionOpen) {
					lockedSupplierAccordionOpen = false;
				} else {
					$(".section-name-locked").css('background','url('+includePath+'img/layout/locked_gr.gif) 6px 2px no-repeat');
					lockedSupplierAccordionOpen = true;
				}
			});*/
			
			//Distance Filter
			$('#distance-dd').click(function(){  
				$(this).children('ul').slideToggle();
			});
			
			$('#distance-dd ul li').click(function(){  
				var radius_txt = $(this).attr('rel');
				var radius = parseInt(radius_txt);
				if (isNaN(radius)) {
					radius = 0;
				}
				$('input[name=radius]').val(radius);
				$(this).parent().prev().html(radius_txt);
			});
			
			
			$('#region-dd').click(function(){  
				$(this).children('ul').slideToggle();
			});
			
			$('#region-dd ul li').click(function(){  
				var currentRegion = $(this).attr('rel');
				$(this).parent().prev().html(currentRegion.toUpperCase());
		
				///////////Hide all containers first ////////
				$(".techDocsContainer").css('display','none');
				
				////////Display the corrent one ////////////
				$('#'+currentRegion+'-tdContainer').css('display','block');
			});
			
		//////////// Country Select Thing on Contact Page
		
			var currentRegion;
			var clickedRegion;
			var clickedCountry;
			$('#region-select li a').hover(function(){ 
				if($('#region-select li a').hasClass('active')) {  
					// If one of the main regions has already been selected/clicked, do not change map background on hover
				} else {
					currentRegion = $(this).attr('rel');
					$('#contact-map').addClass(currentRegion+'-map');
				}
			},function(){  
				$('#contact-map').removeClass(currentRegion+'-map');
			});
			
			$('#region-select li a').click(function(){  
				clickedRegion = $(this).attr('rel');
				clickedCountry = '';
				
				// Remove all classes from maps and make currently selected map active
				$('#contact-map').removeClass();
				$('#contact-map').addClass(clickedRegion+'-map-clicked');
				
				// Close all other region dialogs and open current country one
				$('.regions').hide();
				$('#'+clickedRegion+'-regions').show();
				
				// Remove all classes from region select links and make this one active
				$('#region-select li a').removeClass('active');
				$(this).addClass('active');
			});
			
			$('.country-select li a').click(function(){  
				clickedRegion = $(this).parent().parent().parent('.regions').attr('rel'); //Find this region again, in case they came here w/o clicking
				clickedCountry = $(this).text();
				$(this).parent().parent().parent().hide();
				
				//HIde the select country text
				$('#map-info').css('display','none');
				
				////Hide the intial text
				$('#defaultContactText').css('display','none');
				
				////Set the correct dropdown form types
				$('#formType').load(includePath+'include/ajaxFiles/contactForm/getFormTypeDropDown.php?region='+clickedRegion);
				
				////Set the correct additional fields if they are needed
				//$('#countryList').load(includePath+'include/ajaxFiles/contactForm/getCountryList.php',{'country':clickedCountry});
				$('#countryListLI').html('');
				$.post(includePath+'include/ajaxFiles/contactForm/getCountryList.php',{'country':clickedCountry},function(data) {
					$('#countryListLI').html(data);
				});
				
				////Load the contact info in the lefthand callout
				$('#contactLocationsContainer').load(includePath+'include/ajaxFiles/contactForm/locations/'+clickedRegion+'.php',{'country':clickedCountry});
				
				////Show the form
				$('#contact-form').css('display','block');
				
				return false;
				
			});
			
			$('.close-region').click(function(){  
				$(this).parent('div').hide();
				$('#region-select li a').removeClass();
				$('#contact-map').removeClass();
			});
		
		//////////// Contact Form /////////////////////////////////////
		
		//Show send samples when form type product is selected with europe as region ///
		$('#formTypeSelect').livequery('change',function() {
			if($('#formTypeSelect').val() == "Product" && clickedRegion == "europe") {
				$('#samplesCheckboxContainer').css('display','block');
			} else {
				$('#samplesCheckboxContainer').css('display','none');
				$('.sendMeArproSamples').attr('checked',false);
			}
			
			if($('#formTypeSelect').val() == "Samples") {
				displayAdditionalContactFields();
			} else {
				hideAdditionalContactFields();
			}
		});
		
		//Show addition address fields, when samples are to be sent //////
		$('.sendMeArproSamples').livequery('change',function() {
			if($(this).attr('checked') == true) {
				displayAdditionalContactFields();
			} else {
				hideAdditionalContactFields();
			}
		});
		
		//Show the additional fields 
		function displayAdditionalContactFields() {
			$('#addFields1').load(includePath+'include/ajaxFiles/contactForm/getAddAddressFields1.php');
			$('#addFields2').load(includePath+'include/ajaxFiles/contactForm/getAddAddressFields2.php');
		}
		
		//Hide the fields
		function hideAdditionalContactFields() {
			$('#addFields1').html('');
			$('#addFields2').html('');
		}
		
		//Update form when country is changed via dropdown
		$('#contactCountry').livequery('change',function() {
			var selectedRegion = '';
			$.get(includePath+'include/ajaxFiles/getContactFormRegion.php?country='+$(this).val(),function(data) {
				if(data == "europe") {clickedRegion = data;}
				hideAdditionalContactFields();
				$('#formType').load(includePath+'include/ajaxFiles/contactForm/getFormTypeDropDown.php?region='+data);
			});
			
		});
		
		$('.mapLink').livequery('click',function() {
			window.open('map.php?id='+$(this).attr('rel'),'Window1','menubar=no,width=570,height=500,toolbar=no,resizable=yes,scrollbars=yes');
			return false;
		});
		
		$(".emailCol").colorbox({ iframe: true, innerWidth: 500, innerHeight: 600, opacity: .6 });
		
		//////////////LCA Download Form ///////////////////////////
		$('#lcaFormDownload').click(function() {
			var lang = $(this).prev('select').val();
			if(lang.length) {
				$.get(includePath+'include/ajaxFiles/trackLcaDownload.php?lang='+lang);
				window.open(includePath+'include/library/lca/reports/arpro_lca_report_'+lang+'.pdf');
			} else {
				alert('Please selected a language.');
			}
			return false;
		});
		
		/* -----------------------------------------------------------
					Tech Docs Americas 
		-------------------------------------------------------------*/
		$('.supplier-document').click(function() {
			var displayDoc = false;
			var fileName = $(this).attr('rel');
			$.ajax({
				url: includePath+'include/ajaxFiles/checkSupplierLogin.php',
				async: false, 
				success: function(data) {
					if(data != "logged_in") { //Not Logged in
						$(this).colorbox({width:"520px", height:"270px", iframe: true, href: includePath+'include/forms/supplierLogin.php?fileName='+fileName, title: "Supplier Login", open:true });
					} else {
						displayDoc = true;
					}
				}
			});
			
			return displayDoc;
				
			
			
		});
		
		////////////////////Feedback ///////////////////////////////
		function validateEmail(email) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email)) {
				return true;
			} else {
				return false;
			}
		}
		
		$('#feedbackSubmit').click(function() {
			var typeOfFeedback = $("input[@name='typeof']:checked").val();
			var pageLink = $('#pageLink').val();
			var comments = $('#comments').val();
			var email = $('#email').val();
			
			if($("input[@name='typeof']:checked").size() == 0 || pageLink.length == 0 || comments.length == 0 || email.length == 0) {
				alert('Please fill in all fields!');
				return false;
			} else if (!validateEmail(email)) {
				alert('Please enter a properly formatted email!');
				return false;
			} else {			
				$.post(includePath+'include/ajaxFiles/submitFeedback.php',{typeOfFeedback:typeOfFeedback,pageLink:pageLink,comments:comments,email:email},function(data) {
					$('#feedbackContainer').html(data);
				});
			}
		});
		
		////////////// Select Language //////////////////////////////////
		$("#select-language").colorbox({width:"620px", height:"330px", iframe:true});
		$(document).bind('cbox_open', function(){
			$('#branding-slides').css({'display':'none'});
		}).bind('cbox_cleanup', function(){
			$('#branding-slides').css({'display':'block'}); 
		});
		////////////// Company Innovation Slider //////////////////////////////////
		$('#cars').jcarousel({
						scroll:4,
						wrap: "circular",
						easing: "easeInOutBack",
						animation: 1300
				});
				
		/* IE 6 Hover Bug */
		if ($.browser.msie && parseInt($.browser.version) == 6)  
		{
		
			if(!$("#accordion h2").hasClass("visited")) {
				$("#accordion h2").hover(
					  function () {
						$(this).css( {backgroundPosition: "right -54px"} );
					  },
					  function () {
						$(this).css( {backgroundPosition: "right top"} );
					  }
					);
			}
		}
		
		/*Innovation Larger Image*/
		/* Defaults first car to selected */
		$('#cars li:first').addClass('current');
		
		$('#cars li').hover(
			function () {
				
				$(this).addClass("hover");
				$(this).css({cursor:"pointer"});
				
			},
			function () {
				$(this).removeClass("hover");
			}
			
		);	
		$('#cars li').click(function(){
			var getLarge = $(this).attr('rel');
			$('#innovation-image').attr('src',getLarge);
			$(this).addClass('current');
			$('#cars li').not(this).removeClass('current');
		});	
		
/* Moulders */
$('#arpro-approved .close').click(function(){
	
	$(this).parents('li.open').addClass('closed').removeClass('open');
	 
	return false;

});

$('#arpro-approved .expand').click(function(){
	
	$(this).parents('li.closed').addClass('open').removeClass('closed');
	
	return false;

});


/* Strategy */
$('.tip').qtip({
   content: {
      text: function(api) {
         // Retrieve content from custom attribute of the $('.selector') elements.
         return '<img src="/img/content/strategy/'+$(this).attr('rel')+'.gif" width="189" height="159" />';
      }
   },
   position: {
      my: 'bottom center',
      at: 'top center',
      target: 'mouse',
      adjust: {
      	y: -10
      }
   },
   style: {
      classes: 'ui-tooltip-arpro ui-tooltip-shadow',
      tip: {
         
         width: 25,
         height: 14
      }
   }
});

	});
	
	$(document).ready(function() {
	   $('#property-tabs, #processing-tabs, #grades-tabs').tabs();
	});
