var addthis_config = {ui_click: true}
var ajaxRunning = false;
$(function() {
	initSubnav();
	initGlobalWidgets();
	initForms();

	
	if (slides!=null) {
		$(".iws-slideshow").iwsSlideshow2({ slides:slides, duration:7000 });
	}
	$(".landing-page-thumb h3").addClass("transition");
	$(document).bind("keydown",handleKey);
	if($.browser.msie && $.browser.version < 8)
		$("#navigationband").css("width",document.body.clientWidth+1000 + "px");
		
	$(".gallery-item").mouseenter(function() {
		$("img",this).animate({"opacity":.8},200);
	}).mouseleave(function() {
		$("img",this).animate({"opacity":1},200);
	});
	
	$(".list-item-active").each(function() {
		if($(this).data("href")) {
			$(this).mouseenter(function() {
				$(this).css("background","#f7dbac");
			}).mouseleave(function() {
				$(this).css("background","transparent");
			}).click(function(e) {
				if($(this).data("target"))
					window.open($(this).data("href"),$(this).data("target"));
				else window.open($(this).data("href"),"_top");
			}).css("cursor","pointer");
		}
	});
});

function handleKey(e) {
	if(e.keyCode == 192) {
		$("#IDHint").css("visibility","visible");
	}
}

function showID() {
	$("#pageid").css("display","block");
}

function AdvanceSlide() {
	$(".iws-slideshow").iwsSlideshow2("next");
}

function EnableSound() {
	$(".iws-slideshow").iwsSlideshow2("option","sound",1);
}

function DisableSound() {
	$(".iws-slideshow").iwsSlideshow2("option","sound",0);
}

function initSubnav()
{
	$(".subnav-item").mouseenter(function() {
		$(".subnav-item-bg",this).css("background-color","#9d1e00");
		$(this).css("color","#ffffff !important");
		Cufon.replace(".cufon-trop");
	}).mouseleave(function() {
		$(".subnav-item-bg",this).css("background-color","transparent");
		$(this).css("color","#9e1e00 !important");
		Cufon.replace(".cufon-trop");
	});
}

function initGlobalWidgets() {
	$(".trop-button").ss();
	/*$("h3",".trop-button").addClass("shadow");
	$(".trop-button").mouseenter(function() {
		$("h3",this).removeClass("shadow");
	}).mouseleave(function() {
		$("h3",this).addClass("shadow");
	});*/
	
	$(".datepicker-input").datepicker({ minDate:0 });
	$(".calendar-icon").click(function() {
		$(this).siblings("input").datepicker();
		$(this).siblings("input").datepicker("show");
	});
	$(".iws-dropdown").iwsDropdown2();
	$(".accordion").accordion({autoHeight:false,collapsible: true});
	$(".colorbox-trigger").colorbox();
	
	$("#pagewrapper").ajaxStart(function(e) {
		ajaxRunning = true;
		
	});
	$("#pagewrapper").ajaxStop(function() {
		ajaxRunning = false;
	});

	$(".subnav-link").closest("a").click(function() {
		$(".subnav-link.active").removeClass("active");
		$("p",this).addClass("active");
	});
}

function initForms() {
	/*$(".ajax-form-trigger").click(function() {
		
	});
	*/
	$(".form-reset-button").click(function() {
		document.getElementById($(this).closest("form").attr("id")).reset();
	});
	
	$(".form-submit-button-custom").click(function() {
		var form = $(this).closest("form");
		$("form").unbind("ajaxStart.indicator");
		$("form").unbind("ajaxStop.indicator");
		$(form).bind("ajaxStart.indicator",function(e) {
			$(".loading-indicator",this).show();
		}).bind("ajaxStop.indicator",function(e) {
			$(".loading-indicator",this).hide();
		});
	});
	
	$(".form-submit-button").click(function() {
		$($(this).closest("form")).submit();
	});
	
	$(".ketchup-form").each(function() {
		$(this).ketchup();
	});
	
	$(".ketchup-enter-field").bind("keydown",function(e) {
		if(e.keyCode == 13) {
			var n = $($(this).closest("form"));
			n.submit();	
			return false;
		}
	});
}

(function(){
  // if firefox 3.5+, hide content till load (or 3 seconds) to prevent FOUT
  var d = document, e = d.documentElement, s = d.createElement('style');
  if (1){ // gecko 1.9.1 inference
    s.textContent = 'body{visibility:hidden}';
    var r = document.getElementsByTagName('script')[0];
    r.parentNode.insertBefore(s, r);
    
	function f(){ 
		s.parentNode && s.parentNode.removeChild(s); 
	}
	var und;

	if(($.browser.ie != und)) {
		if(addEventListener) {
			addEventListener('load',f,false);
		}
	}
	
	setTimeout(f, $.browser.mozilla ? 1200 : 500);
  }
})();
