// ------------------------------------- Huttig JS

// Search Product show-hide
function disableProd() {
	if ($('#branches').attr('checked')) {
		$('#whocarry').hide();
		$('#branchmap').show();
		$('#therma_tru, #masonite, #louisiana, #simpson, #timbertech, #woodgrain, #fiberweb, #hbg').attr('disabled', true);
	} else {
		$('#whocarry').show();
		$('#branchmap').hide();
		$('#therma_tru, #masonite, #louisiana, #simpson, #timbertech, #woodgrain, #fiberweb, #hbg').removeAttr('disabled');
	}
}
	

// Styling Checkboxes & Radio buttons
$('#search-controls input:radio').each(function() { 
	$('<span class="radio"></span>').insertBefore(this);
	$(this).hide();
});
$('#search-controls input:checkbox').each(function() { 
	$('<span class="checkbox"></span>').insertBefore(this);
	$(this).hide();
});

// Set initial Psudeo Radio
$("input[type='radio']:checked").prev().css({backgroundPosition: '0px 0px'});

// Set Psudeo Radio to trigger Radio Button 
$('#search-controls span.radio').click(function() {
	if (!$(this).next().attr('checked')) {
		$(this).parent().find("input[type='radio']:checked").prev().css({backgroundPosition: '-14px 0px'});
		$(this).next().attr('checked',true);
		$(this).css({backgroundPosition: '0px 0px'});
		disableProd();
	}
});

// Set Psudeo Radio to trigger Radio Button 
$('#search-controls span.checkbox').click(function() {
	if (!$(this).next().attr('checked')) {
		$(this).next().attr('checked',true);
		$(this).css({backgroundPosition: '0px 0px'});
	} else {
		$(this).next().attr('checked',false);
		$(this).css({backgroundPosition: '-12px 0px'});
	}
});
		
// Show-Hide Search Controls on click
function revealLoc() {
	if ($("#slidewrap").css('padding-top') == '0px') {
		$("#slidewrap").animate( { paddingTop:"120px" } , 300, function() {
			// change search-controls z-index so controls are clickable 
			$("#search-controls").css('zIndex','2000');
		});
	} else {
		// Let search-controls be hidden by slidewrap
		$("#search-controls").css('zIndex','1');
		$("#slidewrap").animate( { paddingTop:"0px" } , 300 );
	}
	scroll(0,0);
}
$("#locator-tab").click(function () { revealLoc();  return false });

// Show-Hide Audience slection on hover
$("a.aud").hover(function() {
		$(this).find("b").stop().animate( { marginTop:"150px" } , 300 );
	}, function() {
		$(this).find("b").stop().animate( { marginTop:"295px" } , 300 );
}); 

//Search Reset
$('#htg-search').blur(function() {
	var ival = $(this).attr("value");
	if (ival == "") {
		$(this).attr("value","{Search Huttig}");
	}
}); 

//Zip Reset
$('#zipcode').blur(function() {
	var ival = $(this).attr("value");
	if (ival == "") {
		$(this).attr("value","{Zip Code}");
	}
}); 

//Location form search validation
function vSearch() {
	var r = false;
	if (document.locationSearch.zipcode.value == "{Zip Code}") alert("Please Enter Your Zip Code");
	else r = true;
	return r;
}

//Adds active class on current page links
$("a").each(function() {
	var href = this.getAttribute('href'); 
	if (href!= null) href = href.replace("/","");
	var location = window.location.pathname.replace("/","");
	//location = location.substring(location.lastIndexOf('/') + 1);	
	if (location != "") {
		if ( href == location) {
			$(this).removeClass("active").addClass("active");
		}
		if ($(this).parents().is("#menu") || $(this).parents().is("#topmenu")) {
			href = href.split(".");
			location = location.split(".");
			if (location[0].indexOf(href[0]) != -1) {
				$(this).removeClass("active").addClass("active");
			}
		}
	}
}); 


//Product tab color fix
$("#content3 div.extcenter").parents("#slidewrap").find("#content4 h2").css("background-color","#f2f2f2");
