﻿$(document).ready(function(){
	$('.dhtml').show();
		
	$('.flyout-container').hide();
	$('.flyout>.copy').toggle(
		function(){
			$(this).parent()
				.addClass('flyout-open');
				//.mouseleave(function(){
				//	$(this)
				//		.delay(3000)
				//		.queue(function(){
				//			$('>.copy',this).click();
				//			$(this).dequeue();
				//		});
				//})
				//.mouseenter(function(){
				//	$(this).clearQueue();
				//});
			$('.flyout-container',$(this).parent()).slideDown('fast');
		},
		function(){
			$(this).parent()
				.removeClass('flyout-open');
				//.unbind('mouseleave')
				//.unbind('mouseenter')
				//.clearQueue();
			$('.flyout-container',$(this).parent()).slideUp('normal');
		}
	);
	
	$("#contact").click(showContact);
	$("#contactFlyout").click(showContact);
	
	/*$.weblook({
		api: "wl_57162e2c8047a71d24e72228418ebeedc252cc10",
		noFlash: false
	});*/
});

function whenVisible(element,callback){
	element = $(element);
	
	if(element.length == 0 || checkIfVisible()) return;
	
	var parent;
	if(element.is(':hidden')){
		parent = element.parents(':hidden:last');
		parent.watch("display,visibility",checkIfVisible);
	}
	
	$(window).resize(checkIfVisible);
	$(window).scroll(checkIfVisible);
	
	function checkIfVisible(){
		if(isVisible(element) == false) return false;
		
		if(parent != null) parent.unwatch("display,visibility");
		$(window).unbind('resize',checkIfVisible);
		$(window).unbind('scroll',checkIfVisible);
		
		callback();
		return true;
	}
}

function isVisible(element){
	element = $(element);
	
	if(element.is(':hidden')) return false;
	
	var windowHeight = $(window).height();
	var scrollTop = $(document).scrollTop();
	var scrollBottom = windowHeight + scrollTop;
	
	var offset = element.offset().top;
	var height = element.height();
	
	if(offset > scrollTop && offset + height/2 < scrollBottom) return true;
	return false;
}

function showContact(){
	if($("#contactFlyout").css("display") == "none")
		$("#contactFlyout").slideDown("fast");
	else
		$("#contactFlyout").slideUp("fast");
}		

Cufon.replace('h1,h2,h4,h5,h6,.excerpt>.copy>blockquote,#sub-title,.tabs>li>a', { fontFamily: 'Avenir LT Std'});
//Cufon.replace('#nav>li>a', { fontFamily: 'Avenir LT Std', hover: true });
Cufon.replace('#copy>blockquote,.cell>blockquote,.graphLabel,.graphLabelDouble', { fontFamily: 'BlairMdITC TT'});
