$(document).ready(function() {
	
	//search click and blur handler-----------------
		$('.search-box input').click(function() {
			if ($(this).val()=='Search'){
				$(this).val('');
			}				
		});
		$('.search-box input').blur(function() {
  			if ($(this).val()==''){
				$(this).val('Search');
			}	
		});
	//----------------------------------------------
	
	//Show left nav after page loads
	$('.primary-nav-subpage').css('display', 'block');
		
	//Horizontal Nav Fade------------------------------------------------------------
	if ( $.browser.msie != true) {
		
		$('.header-main-nav ul li ul').css('display', 'none'); //Hide css nav before hoverIntent to prevent clipping on first hover

    	$(".header-main-nav").hoverIntent({
     		sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
     		interval: 50,   // number = milliseconds for onMouseOver polling interval
     		over: showNavFade,     // function = onMouseOver callback (required)
     		timeout: 300,   // number = milliseconds delay before onMouseOut
     		out: hideNavFade       // function = onMouseOut callback (required)
   		});
		
	 	$(".header-main-nav ul li").hoverIntent({
     		sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
     		interval: 50,   // number = milliseconds for onMouseOver polling interval
     		over: menuDown,     // function = onMouseOver callback (required)
     		timeout: 0,   // number = milliseconds delay before onMouseOut
     		out: menuUp       // function = onMouseOut callback (required)
   		});
		
		$(".header-nav-fade").hoverIntent({
			sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
     		interval: 50,   // number = milliseconds for onMouseOver polling interval
     		over: hideNavFade,     // function = onMouseOver callback (required)
     		timeout: 300,   // number = milliseconds delay before onMouseOut
     		out: hideNavFade       // function = onMouseOut callback (required)
		});
		
 	}
	else{}
	
	function menuDown(){
		//$('.header-main-nav ul li ul').css('display', 'none');
		$(this).find(".sub").stop().slideDown(200);
	}
	
	function menuUp(){
		$(this).find(".sub").stop().fadeOut(200);
	}
	
	function showNavFade(){
		//$(".header-nav-fade").fadeIn(500); //disabled
	}
	
	function hideNavFade(){
		$(".header-nav-fade").fadeOut(200);
	}
	//-------------------------------------------------------------------------------
	
	//Scroll------------------------------------------------------
	//Functionality: Smooth scrolls a page to the location of a selector
	//Use: <a class="scroll" href="#" title=".selector">Link</a>
	$(function() {
		$('.scroll').bind('click',function(event){
			var anchor = $(this).attr('title');
			
			var windowLimit = $(document).height()-$(window).height();
			if($(window).scrollTop()<$(anchor).offset().top){
				$('html, body').animate({
					scrollTop: [windowLimit, 'swing']
				}, 1500);
			}
			else{
				$('html, body').stop().animate({
					scrollTop: [$(anchor).offset().top, 'swing']
				}, 1500);
			}
			event.preventDefault();
		});
	});
	//------------------------------------------------------------

}); //End document.ready()

//Open link---------------------------------------------------
//open document link and close window after the document opens
//usage: <a href="#" onclick="openLink('http://www.domain.com/folder/document.pdf')">Link</a>
//href="#" required for chrome
function openLink(link){
	openWindow=window.open(link, '_blank');
	openWindow.onload = closeWindow;
}
function closeWindow(){
	openWindow.close();
}
//------------------------------------------------------------

//Autocomplete------------------------------------------------
    $(function () {
        var availableTags = [
			"Appliances",
			"Applications",
			"PASCAL",
			"Automotive",
			"Automotive Interior Trim",
			"Interior Trim",
			"Automotive Seating",
			"Automotive Noise",
			"Automotive Vibration",
			"Automotive Harshness",
			"Automotive Foams",
			"Specialty Foams",
			"Building",
			"Construction",
			"Coatings",
			"Adhesives",
			"Sealants",
			"Elastomers",
			"Footwear",
			"Packaging",
			"Electronics",
			"Electrical",
			"Flooring",
			"Artificial Turf",
			"Turf",
			"News",
			"Recent News",
			"Events",
			"Archive",
			"2009 News",
			"2008 News",
			"2007 News",
			"Products",
			"Product Finder",
			"Why",
			"Locations",
			"Map",
			"Interactive Map",
			"Capabilities",
			"Integrated Capabilities",
			"Customer Service",
			"Technical Support",
			"Industry Commitment",
			"Resources",
			"Product Brochures",
			"Technical Data Sheet",
			"Literature",
			"Product Stewardship",
			"ISO Certificates",
			"Quality Management",
			"Technical Bulletins",
			"Contact Us",
			"Phone Numbers",
			"Fax",
			"Answer Center",
			"Knowledge Base",
			"Technical Inquiry",
			"Ask a Question",
			"Email",
			"Where to Buy"
		];
        $("#search-box-text").autocomplete({
            source: availableTags,
            select: function (event, ui) {
                $("#search-box-text").val(ui.item.label);
				keyword();				
            }
        });
    });
//------------------------------------------------------------

//search keyword redirect-------------------------------------

function keyword(){
	var sKeyword = $('[name=q]').val();
	sKeyword = sKeyword.toLowerCase();
	if 	(sKeyword == 'markets' || sKeyword == 'applications'){
		redirect('/polyurethane/markets/applications.htm');
		return false;
	}
	else if (sKeyword == 'appliances' || sKeyword == 'appliance'){
		redirect('/polyurethane/markets/appliances.htm');
		return false;
	}
	else if(sKeyword == 'pascal'){
		redirect('/polyurethane/markets/pascal.htm');
		return false;
	}
	else if(sKeyword == 'automotive'){
		redirect('/polyurethane/markets/automotive.htm');
		return false;
	}
	else if(sKeyword == 'automotive interior trim' || sKeyword == 'interior trim' || sKeyword == 'trim'){
		redirect('/polyurethane/markets/automotive-trim.htm');
		return false;
	}
	else if(sKeyword == 'automotive seating' || sKeyword == 'seating'){
		redirect('/polyurethane/markets/automotive-seating.htm');
		return false;
	}
	else if(sKeyword == 'nvh' || sKeyword == 'noise' || sKeyword == 'vibration' || sKeyword == 'harshness'){
		redirect('/polyurethane/markets/automotive-nvh.htm');
		return false;
	}
	else if(sKeyword == 'automotive foams' || sKeyword == 'specialty foams' || sKeyword == 'foams'){
		redirect('/polyurethane/markets/automotive-foams.htm');
		return false;
	}
	else if(sKeyword == 'building' || sKeyword == 'construction'){
		redirect('/polyurethane/markets/building_construction.htm');
		return false;
	}
	else if(sKeyword == 'coatings' || sKeyword == 'adhesives' || sKeyword == 'sealants' || sKeyword == 'elastomers'){
		redirect('/polyurethane/markets/coatings.htm');
		return false;
	}
	else if(sKeyword == 'footwear'){
		redirect('/polyurethane/markets/footwear.htm');
		return false;
	}
	else if(sKeyword == 'packaging'){
		redirect('/polyurethane/markets/packaging.htm');
		return false;
	}
	else if(sKeyword == 'electronics' || sKeyword == 'electrical'){
		redirect('/polyurethane/markets/electronics.htm');
		return false;
	}
	else if(sKeyword == 'flooring'){
		redirect('/polyurethane/markets/flooring.htm');
		return false;
	}
	else if(sKeyword == 'artificial turf' || sKeyword == 'turf'){
		redirect('/polyurethane/markets/artificial_turf.htm');
		return false;
	}
	else if(sKeyword == 'news' || sKeyword == 'recent news'){
		redirect('/polyurethane/news/index.htm');
		return false;
	}
	else if(sKeyword == 'events' || sKeyword == 'event'){
		redirect('/polyurethane/news/events.htm');
		return false;
	}
	else if(sKeyword == 'archive'){
		redirect('/polyurethane/news/archive.htm');
		return false;
	}
	else if(sKeyword == '2009 news'){
		redirect('/polyurethane/news/2009.htm');
		return false;
	}
	else if(sKeyword == '2008 news'){
		redirect('/polyurethane/news/2008.htm');
		return false;
	}
	else if(sKeyword == '2007 news'){
		redirect('/polyurethane/news/2007.htm');
		return false;
	}
	else if(sKeyword == 'products' || sKeyword == 'product finder'){
		redirect('/polyurethane/products/');
		return false;
	}
	else if(sKeyword == 'why' || sKeyword == 'why?'){
		redirect('/polyurethane/why/');
		return false;
	}
	else if(sKeyword == 'locations' || sKeyword == 'map' || sKeyword == 'interactive map'){
		redirect('/polyurethane/why/locations.htm');
		return false;
	}
	else if(sKeyword == 'integrated capabilities' || sKeyword == 'capabilities'){
		redirect('/polyurethane/why/capabilities.htm');
		return false;
	}
	else if(sKeyword == 'customer service' || sKeyword == 'technical support' || sKeyword == 'service' || sKeyword == 'support' || sKeyword == 'tech support'){
		redirect('/polyurethane/why/service_support.htm');
		return false;
	}
	else if(sKeyword == 'industry commitment' || sKeyword == 'commitment'){
		redirect('/polyurethane/why/commitment.htm');
		return false;
	}
	else if(sKeyword == 'resources' || sKeyword == 'resource'){
		redirect('/polyurethane/resources/');
		return false;
	}
	else if(sKeyword == 'brochures' || sKeyword == 'technical data sheet' || sKeyword == 'literature' || sKeyword == 'product brochures'){
		redirect('/polyurethane/resources/literature.htm');
		return false;
	}
	else if(sKeyword == 'stewardship' || sKeyword == 'product stewardship' || sKeyword == 'product stewardship information' || sKeyword == 'stewardship information'){
		redirect('/polyurethane/resources/stewardship.htm');
		return false;
	}
	else if(sKeyword == 'certificates' || sKeyword == 'iso certificates' || sKeyword == 'quality management'){
		redirect('/polyurethane/resources/certificates.htm');
		return false;
	}
	else if(sKeyword == 'technical bulletins' || sKeyword == 'tech bulletins' || sKeyword == 'bulletins' || sKeyword == 'bulletin'){
		redirect('/polyurethane/resources/tech_bulletins.htm');
		return false;
	}
	else if(sKeyword == 'contact' || sKeyword == 'contacts' || sKeyword == 'contact us' || sKeyword == 'phone numbers' || sKeyword == 'call us' || sKeyword == 'fax' || sKeyword == 'phone'){
		redirect('/polyurethane/contact/');
		return false;
	}
	else if(sKeyword == 'answer center' || sKeyword == 'answers' || sKeyword == 'kb' || sKeyword == 'knowledge base'){
		redirect('/polyurethane/contact/answer_center.htm');
		return false;
	}
	else if(sKeyword == 'technical inquiry' || sKeyword == 'tech inquiry' || sKeyword == 'inquiry'){
		redirect('/polyurethane/contact/technical_inquiry.htm');
		return false;
	}
	else if(sKeyword == 'question' || sKeyword == 'ask a question' || sKeyword == 'email'){
		redirect('/polyurethane/contact/question.htm');
		return false;
	}
	else if(sKeyword == 'where to buy' || sKeyword == 'buy polyurethanes' || sKeyword == 'purchase'){
		redirect('/polyurethane/contact/where.htm');
		return false;
	}
	else{
		return true;
	}
}

function redirect(sUrl){
	window.location = sUrl;
}

//------------------------------------------------------------
