/*
* Common javascript functions for SHRR.COM
* 
* -----------------
* TABLE OF CONTENTS
* -----------------
* 
* 1) Tabs
*	1.1) createTab function
*	1.2) Auto Tab-ulate
* 2) Footer
*	2.1) Bold Client Login
* 3) Email Disclaimer
*	3.1) ShowDisclaimer
*	3.2) Convert mail links
* 99) Miscellaneous javascript functions

*/



/* ==================================================
* 1) Tabs
* ================================================== */


	// 1.1) createTab function
	(function ($) {
		$.fn.createTabs = function () {
			var container = $(this);

			container.find('.tab-content').hide();
			container.find("ul.tabs li:first a").addClass("current").show();
			container.find(".tab-content:first").show();


			container.find('.tab-content').each(function () {
				// This uses jQuery's $.trim() function for IE8 compatibility
				if ( $.trim( $(this).html() ).length > 0   ) {

					// Show this tab
					container.find("ul.tabs li a[href=#" + $(this).attr('id') + "]").parent().css('display', 'block');
				}
			});


			container.find("ul.tabs li").click(function () {
				container.find("ul.tabs li a").removeClass("current");
				$(this).find("a").addClass("current");
				container.find(".tab-content").hide();

				var activeTab = $(this).find("a").attr("href");
				$(activeTab).fadeIn();

				if ($(this).find("a").attr("href") == "#map")
					$("iframe").attr("src", $("iframe").attr("src"));

				return false;
			});

		};
	})(jQuery);




$().ready(function () {


	// 1.2) Auto Tab-ulate
	if ($("#tab-panel").length) {

		$("#tab-panel").createTabs();
	}



});



/* ==================================================
* 2) Footer
* ================================================== */


// 2.1) Bold Client Login
$().ready(function () {
	$("#footer #links a").each(function () {
		if ($(this).text() == "Client Login")
			$(this).css( "font-weight", "bold" );
	});
});



/* ==================================================
* 3) Email Disclaimer
* ================================================== */


// 3.1) ShowDisclaimer
function ShowDisclaimer(name, domain) {
	var options = "width=500,height=500,status=no,scrollbars=yes,resizeable=yes,";
	var win = window.open( "/index.aspx/email-disclaimer/" + name + "/" + domain, "_new", options );
};


// 3.2) Convert mail links
$().ready(function () {
	// mailto links
	$('a[href^=mailto]').each(function () {
		var link = $(this).attr('href');
		var user = link.slice(link.indexOf(':') + 1, link.indexOf('@'));
		var domain = link.slice(link.indexOf('@') + 1);

		$(this).attr('href', '/');
		$(this).click(function () {
			ShowDisclaimer(user, domain);
			return false;
		});
	});

	// email-disclaimer links
	$('a[href*="/email-disclaimer/"]').each(function () {
		var link = $(this).attr('href');
		var address = link.substring(link.indexOf('/email-disclaimer/') + 18, link.length);
		var user = address.slice(0, address.indexOf('/'));
		var domain = address.slice(address.indexOf('/') + 1);


		$(this).attr('href', '/');
		$(this).click(function () {
			ShowDisclaimer(user, domain);
			return false;
		});
	});
});



/* ==================================================
* 99) Miscellaneous javascript functions
* ================================================== */

	// 99.1) Temporary clean URL Rewrite
	/*$().ready(function () {
		$('a[href^="/"]').not('a[href^="/upload"]').each(function () {
			$(this).attr("href", "index.aspx" + $(this).attr("href"));
		});
	});*/
