// JavaScript Document

// DOM Ready
$(function() {
	
if ($.browser.msie && $.browser.version.substr(0,1)<7) {
	try {
  		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {} // stops background flicker on :hover in <= ie6
}
	
Cufon.replace('#banner h1, #sidebar li h3, #menu li a, .home #banner a.more, .home #main-content li.testimonial p.from, .main #main-content h3, .docs #main-content h2, .resourcelibrary #main-content h2, .demo #main-content h2');
	
	// Modal
	$modal = $("#mdlPopup");
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	$modal.before("<div id=\"overlay\"><!--[if lte IE 6]><iframe></iframe><![endif]--></div>");
	$overlay = $("#overlay").css({ height: $(document).height(), opacity: "0.6" });		
	
});

// Modal
modal = function() {
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	$modal.find("div").load("modal.html");
	var left = (windowW/2)-(modalW/2);
	var top = ((windowH/2)+$(window).scrollTop())-(modalH/2) - 22;
	$overlay.fadeIn(500);
	$("#overlay iframe").css({ top: top, left: left, width: $modal.outerWidth(), height: $modal.outerHeight() })
	
	$modal
	.css({ top: top, left: left })
	.fadeIn(500)
	.find("a[class='modal-close']")
	.click(function(e) {
		e.preventDefault();
		$modal.find("#flash").remove();
		$modal.hide();
		$overlay.fadeOut(750);
	});
}

$(window).resize(function() {
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	var left = (windowW / 2) - (modalW / 2);
	var top = ((windowH / 2) + $(window).scrollTop()) - (modalH / 2) - 22;
	if ($modal.is(":visible")) {
		$modal.animate({ top: top, left: left }, 500);
	}
});