(function($,i,b){var j,k=$.event.special,c="location",d="hashchange",l="href",f=$.browser,g=document.documentMode,h=f.msie&&(g===b||g<8),e="on"+d in i&&!h;function a(m){m=m||i[c][l];return m.replace(/^[^#]*#?(.*)$/,"$1")}$[d+"Delay"]=100;k[d]=$.extend(k[d],{setup:function(){if(e){return false}$(j.start)},teardown:function(){if(e){return false}$(j.stop)}});j=(function(){var m={},r,n,o,q;function p(){o=q=function(s){return s};if(h){n=$('<iframe src="javascript:0"/>').hide().insertAfter("body")[0].contentWindow;q=function(){return a(n.document[c][l])};o=function(u,s){if(u!==s){var t=n.document;t.open().close();t[c].hash="#"+u}};o(a())}}m.start=function(){if(r){return}var t=a();o||p();(function s(){var v=a(),u=q(t);if(v!==t){o(t=v,u);$(i).trigger(d)}else{if(u!==t){i[c][l]=i[c][l].replace(/#.*/,"")+"#"+u}}r=setTimeout(s,$[d+"Delay"])})()};m.stop=function(){if(!n){r&&clearTimeout(r);r=0}};return m})()})(jQuery,this);
(function($){$.fn.iframePostForm=function(o){var J,a,i,n;a=$(this);o=$.extend({},$.fn.iframePostForm.defaults,o);if(!$('#'+o.iframeID).length){$('body').append('<iframe name="'+o.iframeID+'" id="'+o.iframeID+'" style="display:none"></iframe>')}return a.each(function(){i=$(this);i.attr('target',o.iframeID);i.submit(function(){o.post.apply(this);n=$('#'+o.iframeID);n.one('load',function(){J=n.contents().find('body');o.complete.apply(this,[J.html()]);setTimeout(function(){J.html('')},1)})})})};$.fn.iframePostForm.defaults={iframeID:'iframe-post-form',post:function(){},complete:function(response){}}})(jQuery);

var distance = 15;

if ($.browser.msie && $.browser.version < 7)
	DD_belatedPNG.fix("h1, nav, #area");

$(document).ready(function() {
	$("body").addClass("script");
	($pages = $("section"));
	(window.location.hash.length > 1) ? document.title = document.title.replace(/:.*/, "") + ": " + $(window.location.hash).addClass("active").find("h2").eq(0).text() : $pages.eq(0).addClass("active");
	$("a[href$=contact]").live("click", function(event) {
		($contact = $("#contact")).addClass("active").children().first().hide().fadeIn();
		$("#shade").css("opacity", 0).show().height(($everything = $("#everything")).height() > $(window).height() ? $everything.height() : $(window).height()).animate({opacity: .75});
		event.preventDefault();
	});
	$("#close, #shade").live("click", function() {
		$contact.children().first().add("#shade").fadeOut(function(){
			$contact.removeClass("active");
		});
	});
/*	$("form").live("submit", function(event) {
		$.post(($form = $(this)).attr("action"), $(this).serialize(), function(data){
			$form.closest("div").animate({left: distance * -1, opacity: 0}, "slow").after('<div class="content conf">' + data + '</div>').next().css("opacity", 0).animate({left: 0, opacity: 1}, "slow");
		});
		event.preventDefault();
	});*/
	($form = $("form")).iframePostForm({complete: function(data) {
		$form.closest("div").animate({left: distance * -1, opacity: 0}, "slow").after('<div class="content conf">' + data + '</div>').next().css("opacity", 0).animate({left: 0, opacity: 1}, "slow");
	}});
	$("select[name=type]").change(function() {
		if ($(this).val() == "Other")
			$(this).removeAttr("name").parent().addClass("hidden").next().removeClass("hidden").attr("name", "type").focus();
	});
	$("select[name=type]").parent().next().blur(function() {
		if (!$(this).val())
			$(this).removeAttr("name").addClass("hidden").prev().removeClass("hidden").children().val("").attr("name", "type").focus();
	});
});

$(function() {
	$(window).bind("hashchange", function() {
		if (window.location.hash.length > 1) {
			$page = $(window.location.hash);
			document.title = document.title.replace(/:.*/, "") + ": " + $page.find("h2").eq(0).text();
		} else {
			$page = $pages.eq(0);
			document.title = document.title.replace(/:.*/, "");
		}
		margin = parseInt(($active = $("section.active")).css("marginLeft"));
		direction = ($page.index() > $active.index()) ? 1 : -1;
		$active.stop(true, true).animate({marginLeft: margin + distance * direction * -1}, "slow");
		$page.stop(true, true).addClass("selected").css({marginLeft: margin + distance * direction, opacity: 0}).animate({marginLeft: margin, opacity: 1}, "slow", function() {
			$active.removeClass("active");
			$page.removeClass("selected").addClass("active");
			$("form").closest("div").css({left: 0, opacity: 1}).next(".conf").remove();
		});
	});
});


