/* * * * * Misc. jQuery application of design * * * * */

/* SHARED PAGE TEMPLATE STYLES */
var enableBlurring = true;
$(function () {
	$("div.globalContact").hide();
	$("a.contactToggle").click(function () {
		var $globalContact = $(this).next("div.globalContact");
		if ($globalContact.is(':hidden')) {
			$globalContact.slideDown();
			$(this).children().html('Collapse Contact Us');
		}
		else {
			$globalContact.slideUp();
			$(this).children().html('Contact Us');
		}
		$("html, body").animate({ scrollTop: $globalContact.offset().top - $globalContact.height() });
		return false;
	});

	function ToggleMask($input) {
		$input.each(function (index) {
			$this = $(this);
			if ($this.val() != '')
				$this.prev("label").hide();
			else
				$this.prev("label").show();
		});
	}

	ToggleMask($(".masked label").next("input").keyup(function () {
		ToggleMask($(this));
	}));
	if (enableBlurring)
		$(".masked label").next("input").focus(function () {
			$(this).prev("label").addClass("blurred");
		}).blur(function () {
			$(this).prev("label").removeClass("blurred");
		});

	//	ERROR MESSAGE TEXT ON HOVER
	//
		$("span.errorText").hide();
		$("span.errorMessage").css('cursor' , 'help').hover(
			function () {
				var thisSpan = $(this).find("span.errorText");
				thisSpan.show();
				if (thisSpan.height() + parseInt(thisSpan.css("margin-bottom")) + parseInt(thisSpan.css("margin-top")) + parseInt(thisSpan.css("padding-top")) + parseInt(thisSpan.css("padding-bottom")) + thisSpan.offset().top > $(window).scrollTop() + $(window).height())
					thisSpan.css("top", "-" + thisSpan.height() + "px");
			},
			function () {
				$(this).find("span.errorText").hide();
			}
		);
});

Sys.Net.WebRequestManager.add_invokingRequest(onInvoke);
Sys.Net.WebRequestManager.add_completedRequest(onComplete);
var running = false;
function onInvoke(sender, args) {
	running = true;
	setTimeout(function () { if (running) $("div.AJAXLoading").show(); }, 500);
}

function onComplete(sender, args) {
	$("div.AJAXLoading").hide();
	running = false;
}
jQuery(document).ready(function () {

	$("a.video").click(function () {
		$.fancybox({
			'padding': 0,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'title': this.title,
			'overlayOpacity': 0.6,
			'overlayColor': '#000',
			'width': 640,
			'height': 385,
			'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type': 'swf',
			'swf': {
				'wmode': 'transparent',
				'allowfullscreen': 'true'
			}
		});

		return false;
	});
	
	$("a.iframe").fancybox({
		'padding': 0,
		'autoScale': false,
		'transitionIn': 'none',
		'transitionOut': 'none',
		'overlayOpacity': 0.6,
		'overlayColor': '#000'
	});

	if ($("ul.menu.LN1").html().replace(/ /g,"").length==0)
		$("div.leftCol").remove();
});

