$("html").removeClass("no-js");

// http://jdbartlett.github.com/innershiv | WTFPL License
window.innerShiv=(function(){var d,r;return function(h,u){if(!d){d=document.createElement('div');r=document.createDocumentFragment();/*@cc_on d.style.display = 'none'@*/}var e=d.cloneNode(true);/*@cc_on document.body.appendChild(e);@*/e.innerHTML=h.replace(/^\s\s*/, '').replace(/\s\s*$/, '');/*@cc_on document.body.removeChild(e);@*/if(u===false)return e.childNodes;var f=r.cloneNode(true),i=e.childNodes.length;while(i--)f.appendChild(e.firstChild);return f}}());
// jQuery plugin based on .load() for use with innerShiv
// http://jdbartlett.github.com/innershiv for more info
// $('selector').loadShiv('example.html selector');
jQuery.fn.loadShiv = function (url, params, callback) {
	var off, selector, self, type;

	if (!this.length || typeof url !== 'string') {
		return this;
	}

	off = url.indexOf(' ');
	if (off >= 0) {
		selector = url.slice(off, url.length);
		url = url.slice(0, off);
	}

	type = 'GET';

	if (params) {
		if (jQuery.isFunction(params)) {
			callback = params;
			params = null;
		} else if (typeof params === 'object') {
			params = jQuery.param(params, jQuery.ajaxSettings.traditional);
			type = 'POST';
		}
	}

	self = this;

	jQuery.ajax({
		url: url,
		type: type,
		dataType: 'html',
		data: params,
		complete: function (res, status) {
			var shivved;

			if (status === 'success' || status === 'notmodified') {
				shivved = jQuery(innerShiv((selector ? '<div>' : '') + res.responseText, false));

				if (selector) {
					shivved = shivved.find(selector);
				}

				self.empty().append(shivved);
			}

			if (callback) {
				self.each(callback, [res.responseText, status, res]);
			}
		}
	});

	return this;
}
// Input placeholder support?
$.support.placeholder = (function() {
    return "placeholder" in document.createElement("input");
})();
// Home page feature sliding and image loader
$.fn.extend({slide: function() {
	if (!($this = $(this)).stop(true, true).hasClass("current"))
		$this.addClass("selected").animate({left: 0, opacity: 1}, 1000, function() {
			$this.removeClass("selected").addClass("current").removeAttr("style");
		}).siblings().stop(true, true).filter(".current").animate({left: -20, opacity: 0}, 1000, function() {
			$(this).removeClass("current").removeAttr("style");
		}).closest("section").find("div.selector li").removeClass("current").eq($this.index()).addClass("current");
	return this;
}});
$.fn.image = function(src, f){ 
	return this.each(function() {
		var i = new Image();
		i.onload = f;
		i.src = src;
		this.appendChild(i);
	});
};

$window = $(window);
$(document).ready(function() {
	// Placeholder support for old browsers
	if (!$.support.placeholder) {
		$("input[placeholder], textarea[placeholder]").focus(function() {
			if (($input = $(this)).val() == $input.attr("placeholder"))
				$input.val("");
		}).blur(function() {
			if (($input = $(this)).val() == "" || $input.val() == $input.attr("placeholder"))
				$input.val($input.attr("placeholder"));
		}).blur().parents("form").submit(function() {
			$(this).find("input[placeholder], textarea[placeholder]").each(function() {
				if (($input = $(this)).val() == $input.attr("placeholder"))
					$input.val("");
			});
		});
	}
	
	// Prevent blank keyword search
	$("#search").submit(function() {
		if (!$(this).find("input").val()) {
			alert("Please enter a search term.");
			event.preventDefault();
		}
	});
	
	// Home page features slider
	if (($features = $("#features")).length) {
		$slides = $features.find("ul.slides>li");
		interval = setInterval(function() {
			$slides.eq(($slides.filter(".current").index() + 1) % $slides.length).slide();
		}, 7500);
		$features.find("div.selector a").click(function(event) {
			clearInterval(interval);
			$slides.eq($(this).parent().index()).slide();
			event.preventDefault();
		});
	}
	
	// Side menu expansion
	$("#side nav>ul>li>ul>li>ul, #warranty-radio-buttons>li>ul").prev().toggle(function(event) {
		$(this).next().slideDown().parent().addClass("open");
		event.preventDefault();
	}, function(event) {
		($this = $(this)).next().slideUp(function() {
			$this.parent().removeClass("open");
		});
		event.preventDefault();
	}).parent().addClass("dropdown");
	
	// Ambient Technologies links
	$('a[href*="ambienttechnologies.com"]').click(function(event) {
		$('<div id="ambient"></div>').hide().appendTo("body").load("/wp-content/themes/vermontcastings/ambient.html", function() {
			$(this).fadeIn();
		});
		event.preventDefault();
	});
	
	// Help Me Choose launch
	$("a[href*=choose]").click(function(event) {
		$('<div id="help"></div>').hide().appendTo("body").loadShiv(this.href, function() {
			$(this).fadeIn();
		});
		event.preventDefault();
	});

	// Galleries
	($gallery = $("#gallery").add("section.gallery")).find(".selector a").click(function(event) {
		($parent = $(this).parent()).add($parent.closest("section").find("ul.slides>li").eq($parent.index())).addClass("current").siblings().removeClass("current");
		event.preventDefault();
	}).end().find("li.prev>a").click(function(event) {
		if (!$gallery.find("li.current").removeClass("current").prev().addClass("current").length)
			$gallery.find("li:last-child").addClass("current");
		event.preventDefault();
	}).parent().next().click(function(event) {
		if (!$gallery.find("li.current").removeClass("current").next().addClass("current").length)
			$gallery.find("li:first-child").addClass("current");
		event.preventDefault();
	});
	
	// Compare checkboxes and links
	$("div.compare input").live("change", function(event) {
		numchecked = ($compares = $(this).closest("div").parent().closest("ul, div").find("div.compare input")).filter(":checked").length;
		$compares.closest("li, section").removeClass("comparing").has("input:checked").toggleClass("comparing", numchecked >= 2);
		$compares.not(":checked").attr("disabled", numchecked >= 4).closest("div").toggleClass("disabled", numchecked >= 4);
	});
	$("div.compare>a").live("click", function(event) {
		$('<div id="compare"></div>').hide().appendTo("body").load("/wp-content/themes/vermontcastings/compare.php", $(this).closest("div").parent().closest("ul, div").find(":input").add("input[name=category]").serialize(), function() {
			$("html, body").animate({scrollTop: ($this = $(this)).fadeIn().toggleClass("absolute", $this.children().outerHeight(true) > $window.height()).offset().top});
		});
		event.preventDefault();
	});
	
	// Search results expansion
	$("section.search #glossary a").click(function(event) {
		($this = $(this)).parent().html($this.html()).next().slideDown();
		event.preventDefault();
	});
	if (($products = ($grid = $("section.search #grid")).children()).length > 8) {
		$products.eq(7).nextAll().hide();
		$grid.after('<a href="">More Products</a>').next().click(function(event) {
			start = ($grid = $(this).prev()).height();
			$grid.children().show();
			end = $grid.height();
			$grid.css({height: start}).animate({height: end}, (end - start) * 3, function() {
				$(this).removeAttr("style");
			});
			($this = $(this)).animate({marginBottom: $this.outerHeight() * -1, opacity: 0}, (end - start) * 3, function() {
				$this.remove();
			});
			event.preventDefault();
		});
	}
	
	
	// Product details photos and videos
	$("#selector a").click(function(event) {
		($parent = $(this).parent()).add($("#photos").children().eq($parent.index())).addClass("current").siblings().removeClass("current");
		event.preventDefault();
	});
	
	// Product size and color list highlighting rows
	$cells = ($lineup = $("#lineup table").first()).find("td");
	$("#sizes a, #colors a").bind("focus, click", function() {
		$cells.removeClass("highlight prev");
		$lineup.find("th:contains(Size), th:contains(Color)").siblings().filter(":contains(" + $(this).attr("title") + ")").each(function() {
			$cells.filter(":nth-child(" + ($(this).index() + 1) + ")").addClass("highlight").prev().addClass("prev");
		});
	}).blur(function() {
		$cells.removeClass("highlight prev");
	}).click(function(event) {
		$("html, body").animate({scrollTop: $lineup.offset().top}, 1500);
		event.preventDefault();
	});
	
	// Image zoom
	$("a.zoom").click(function(event) {
		($zoom = $('<div id="zoom"><div><a href="" class="close">Close</a></div></div>')).hide().appendTo("body").children().image(this.href, function() {
			$this = $(this);
			setTimeout(function() {
				($zoom = $zoom.fadeIn().children()).toggleClass("tall", $zoom.width() / $zoom.height() < 16/9);
				$this.css({top: ($zoom.height() - $this.height()) / 2});
			}, 1);
		});
		event.preventDefault();
	});

	// Product details tabs
	($tabs = $("#tabs")).find("a").click(function(event) {
		($parent = $(this).parent()).add($tabs.siblings("section").eq($parent.index())).addClass("current").siblings().removeClass("current");
		event.preventDefault();
	});
	
	// Product details definition popup
	$("dfn").each(function() {
		($this = $(this)).data("title", $this.attr("title"));
	}).hover(function() {
		($this = $(this)).attr("title", "");
		timeout = setTimeout(function() {
			$this.click();
		}, 500);
	}, function() {
		clearTimeout(timeout);
		($this = $(this)).attr("title", $this.data("title")).children("dl").fadeOut(500, function() {
			$(this).remove();
		});
	}).click(function() {
		clearTimeout(timeout);
		($this = $(this)).children("dl").remove();
		$this.append('<dl class="dfn" style="left: ' + ($this.position().left + $this.innerWidth() / 2) + "px; top: " + ($this.position().top + $this.innerHeight()) + 'px;"><dt>' + $this.text().replace(/(?:^|\s)\w/g, function(match) {return match.toUpperCase();})
 + "</dt><dd>" + (title = $this.data("title")) + "</dd></dl>").children().last().hide().fadeIn(100);
	});
	
	// Recipe index
	$("#index a").click(function(event) {
		$("html, body").animate({scrollTop: $(href = $(this).attr("href")).offset().top}, 1000);
		event.preventDefault();
	});
	
	// Manuals popup
	$("div.manuals").closest("body").click(function(event) {
		$("div.manuals").find("aside>div, section").removeClass("current");
	}).find("aside>h3>a").click(function(event) {
		event.preventDefault();
		event.stopPropagation();
		$(this).parent().next().toggleClass("current");
	}).end().find("div.manuals").find("h2>a").click(function(event) {
		event.preventDefault();
		$(this).parent().addClass("current").siblings().removeClass("current");
	}).end().find("h4>a").click(function(event) {
		event.preventDefault();
		event.stopPropagation();
		($div = $(this).parent().next()).css({marginTop: $div.outerHeight() / -2}).parent().addClass("current").removeClass("right").toggleClass("right", $div.offset().left + $div.outerWidth() > $(window).width()).siblings().removeClass("current");
	}).end().find("div").click(function(event) {
		event.stopPropagation();
	}).find("h5~ul>li>a").click(function(event) {
		event.preventDefault();
		event.stopPropagation();
		$(this).closest("div").find("li").not($(this).parent()).removeClass("current");
		$(this).parent().toggleClass("current");
	});
/*	($manuals = $("section.manuals")).find("#content>section>ul>li").bind("click focusin", function(event) {
		$("#content li").removeClass("focus");
		$(this).addClass("focus").not(":has(a.close)").children("section").append('<a href="" title="close" class="close">X</a>').children().last().click(function(event) {
			$("body").click();
			event.stopPropagation();
			event.preventDefault();
		});
		event.stopPropagation();
	}).children("a").click(function(event) {
		event.preventDefault();
	});
	$manuals.closest("body").bind("click focusin", function() {
		$("#content li").removeClass("focus");
	});*/
	
	$window.resize(function() {
		($compare = $("#compare")).toggleClass("absolute", $compare.children().outerHeight(true) > $window.height());
		($zoom_img = ($zoom = $("#zoom").children()).toggleClass("tall", $zoom.width() / $zoom.height() < 16/9).children("img")).css({top: ($zoom.height() - $zoom_img.height()) / 2});
	});
});

// Popup behavior
$("#compare, #zoom, #ambient, #help, a.close").live("click", function(event) {
	$("body").children().last().fadeOut(function() {
		$(this).remove();
	});
	event.preventDefault();
});
$("#compare>div, #zoom>div, #ambient>div, #help>div").live("click", function() {
	return false;
});
$("#help label").live("click", function() {
	$(this).find("input").attr("checked", "checked").change();
});
$('#compare a[href!=""], #ambient a[href!=""], #help a[href!=""]').live("click", function() {
	location.href = this.href;
});
$("#compare a.remove, #help a.remove").live("click", function(event) {
	(($table = ($this = $(this)).closest("table")).find("th").length > 1) ? $table.find("tr>:nth-child(" + ($this.closest("td").index() + 1) + ")").remove() : $("body").children().last().click();
	event.preventDefault();
});

/*
 * MyFonts Webfont Build ID 740575, 2011-04-01T11:16:26-0400
 * 
 * The fonts listed in this notice are subject to the End User License
 * Agreement(s) entered into by the website owner. All other parties are 
 * explicitly restricted from using the Licensed Webfonts(s).
 * 
 * You may obtain a valid license at the URLs below.
 * 
 * Webfont: Proxima Nova A Bold Italic
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/a-bold-it/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNovaA-BoldIt
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova A Italic
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/a-regular-it/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNovaA-RegularIt
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova A Regular
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/a-regular/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNovaA-Regular
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova S Italic
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/s-regular-it/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNovaS-RegularIt
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova S Bold Italic
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/s-bold-it/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNovaS-BoldIt
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova S Bold
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/s-bold/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNovaS-Bold
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova A Bold
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/a-bold/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNovaA-Bold
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova S Regular
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/s-regular/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNovaS-Regular
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova Regular
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/regular/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNova-Regular
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova Bold Italic
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/bold-it/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNova-BoldIt
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova Bold
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/bold/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNova-Bold
 * CSS font-weight: normal
 * 
 * Webfont: Proxima Nova Italic
 * URL: http://new.myfonts.com/fonts/marksimonson/proxima-nova/regular-it/
 * Foundry: Mark Simonson
 * Copyright: Copyright (c) Mark Simonson, 2005. All rights reserved.
 * License: http://www.myfonts.com/viewlicense?1056
 * Licensed pageviews: 10,000/month
 * CSS font-family: ProximaNova-RegularIt
 * CSS font-weight: normal
 * 
 * (c) 2011 Bitstream, Inc
*/



// safari 3.1: data-css
// firefox 3.6+: woff
// firefox 3.5+: data-css
// chrome 4+: data-css
// chrome 6+: woff
// IE 5+: eot
// IE 9: woff
// opera 10.1+: data-css
// mobile safari: svg/data-css
// android: data-css

var browserName, browserVersion, webfontType,  webfontTypeOverride;
 
if (typeof(customPath) == 'undefined')
	var customPath = false;


if (typeof(woffEnabled) == 'undefined')
	var woffEnabled = true;


if (/myfonts_test=on/.test(window.location.search))
	var myfonts_webfont_test = true;

else if (typeof(myfonts_webfont_test) == 'undefined')
	var myfonts_webfont_test = false;


if (customPath)
	var path = customPath;

else {
	var scripts = document.getElementsByTagName("SCRIPT");
	var script = scripts[scripts.length-1].src;

	if (!script.match("://") && script.charAt(0) != '/')
		script = "./"+script;
		
	var path = script.replace(/\\/g,'/').replace(/\/[^\/]*\/?$/, '');
}


if (myfonts_webfont_test)
	document.write('<script type="text/javascript" src="' +path+ '/MyFontsWebfontsOrderM2834959_test.js"></script>');


if (/webfont=(woff|ttf|eot)/.test(window.location.search))
{
	webfontTypeOverride = RegExp.$1;

	if (webfontTypeOverride == 'ttf')
		webfontTypeOverride = 'data-css';
}


if (/MSIE (\d+\.\d+)/.test(navigator.userAgent))
{
	browserName = 'MSIE';
	browserVersion = new Number(RegExp.$1);
	if (browserVersion >= 9.0 && woffEnabled)
		webfontType = 'woff';
	else if (browserVersion >= 5.0)
		webfontType = 'eot';
}
else if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
{
	browserName = 'Firefox';
	browserVersion = new Number(RegExp.$1);
	if (browserVersion >= 3.6 && woffEnabled)
		webfontType = 'woff';
	else if (browserVersion >= 3.5)
		webfontType = 'data-css';
}
else if (/Chrome\/(\d+\.\d+)/.test(navigator.userAgent)) // must check before safari
{
	browserName = 'Chrome';
	browserVersion = new Number(RegExp.$1);

	if (browserVersion >= 6.0 && woffEnabled)
		webfontType = 'woff';

	else if (browserVersion >= 4.0)
		webfontType = 'data-css';
}
else if (/Mozilla.*(iPhone|iPad).* OS (\d+)_(\d+).* AppleWebKit.*Safari/.test(navigator.userAgent))
{
		browserName = 'MobileSafari';
		browserVersion = new Number(RegExp.$2) + (new Number(RegExp.$3) / 10)

	if(browserVersion >= 4.2)
		webfontType = 'data-css';

	else
		webfontType = 'svg';
}
else if (/Mozilla.*(iPhone|iPad|BlackBerry).*AppleWebKit.*Safari/.test(navigator.userAgent))
{
	browserName = 'MobileSafari';
	webfontType = 'svg';
}
else if (/Safari\/(\d+\.\d+)/.test(navigator.userAgent))
{
	browserName = 'Safari';
	if (/Version\/(\d+\.\d+)/.test(navigator.userAgent))
	{
		browserVersion = new Number(RegExp.$1);
		if (browserVersion >= 3.1)
			webfontType = 'data-css';
	}
}
else if (/Opera\/(\d+\.\d+)/.test(navigator.userAgent))
{
	browserName = 'Opera';
	if (/Version\/(\d+\.\d+)/.test(navigator.userAgent))
	{
		browserVersion = new Number(RegExp.$1);
		if (browserVersion >= 10.1)
			webfontType = 'data-css';
	}
}


if (webfontTypeOverride)
	webfontType = webfontTypeOverride;

switch (webfontType)
{
		case 'eot':
		document.write("<style>\n");
				document.write("@font-face {font-family:\"Proxima Nova\";src:url(\"" + path + "/fonts/eot/style_148510.eot\");}\n");
				document.write("@font-face {font-family:\"Proxima Nova Bold\";src:url(\"" + path + "/fonts/eot/style_148514.eot\");font-weight: bold;}\n");
				document.write("</style>");
		break;
		
		case 'woff':
		document.write("<style>\n");
				document.write("@font-face {font-family:\"Proxima Nova\";src:url(\"" + path + "/fonts/woff/style_148510.woff\") format(\"woff\");}\n");
				document.write("@font-face {font-family:\"Proxima Nova Bold\";src:url(\"" + path + "/fonts/woff/style_148514.woff\") format(\"woff\");font-weight: bold;}\n");
				document.write("</style>");
		break;
	
		case 'data-css':
		document.write("<link rel='stylesheet' type='text/css' href='" + path + "/fonts/datacss/MyFontsWebfontsOrderM2834959.css'>");
		break;
	
		case 'svg':
		document.write("<style>\n");
				document.write("@font-face {font-family:\"Proxima Nova\";src:url(\"" + path + "/fonts/svg/style_148510.svg#ProximaNova-Regular\") format(\"svg\");}\n");
				document.write("@font-face {font-family:\"Proxima Nova Bold\";src:url(\"" + path + "/fonts/svg/style_148514.svg#ProximaNova-Bold\") format(\"svg\");font-weight: bold;}\n");
				document.write("</style>");
		break;
		
	default:
		break;
}
