// MLL Telecom website JavaScript functions
// Requires JQuery 1.3.2 library

/** Subnav **/
$(document).ready(function() {
	$('#nav_home').bind('mouseover', function() {
		$('#nav > ul > li > ul').attr('style', 'display: none;');
	});

	$('#nav_who').bind('mouseover', function() {
		$('#nav > ul > li > ul').attr('style', 'display: none;');
		$('#nav_who > ul').attr('style', 'display: block;');
	});
	$('#nav_who > ul').bind('mouseout', function() {
		$('#nav_who > ul').attr('style', 'display: none;');
	});
	
	$('#nav_what').bind('mouseover', function() {
		$('#nav > ul > li > ul').attr('style', 'display: none;');
		$('#nav_what > ul').attr('style', 'display: block;');
	});
	$('#nav_what > ul').bind('mouseout', function() {
		$('#nav_what > ul').attr('style', 'display: none;');
	});
	
	$('#nav_company').bind('mouseover', function() {
		$('#nav > ul > li > ul').attr('style', 'display: none;');
		$('#nav_company > ul').attr('style', 'display: block;');
	});
	$('#nav_company > ul').bind('mouseout', function() {
		$('#nav_company > ul').attr('style', 'display: none;');
	});
	
	$('#nav_news').bind('mouseover', function() {
		$('#nav > ul > li > ul').attr('style', 'display: none;');
		$('#nav_news > ul').attr('style', 'display: block;');
	});
	$('#nav_news > ul').bind('mouseout', function() {
		$('#nav_news > ul').attr('style', 'display: none;');
	});
	
	$('#nav_support').bind('mouseover', function() {
		$('#nav > ul > li > ul').attr('style', 'display: none;');
		$('#nav_support > ul').attr('style', 'display: block;');
	});
	$('#nav_support > ul').bind('mouseout', function() {
		$('#nav_support > ul').attr('style', 'display: none;');
	});
	
	$('div#search').bind('mouseover', function() {
		$('#nav > ul > li > ul').attr('style', 'display: none;');
	});
	
	$('#logo').bind('mouseover', function() {
		$('#nav > ul > li > ul').attr('style', 'display: none;');
	});
});

/** Search box **/

$(document).ready(function() {	   

	$('#search_link').bind('click', function() {
		$('#search_link').attr('style', 'display: none;');
		$('#search > form').attr('style', 'display: block;');
		return(false);
	});
	
	$('#cse-search-box label').bind('click', function() {
		$('#search > form').attr('style', 'display: none;');
		$('#search_link').attr('style', 'display: block;');
	});
});


/** Pod link and news/blog/events story styling **/

$(document).ready(function() {
	$('div.pod a:not(.social, .feed_icon, .pod_video)').append('<span class="link_arrow">&gt;</span>');
	$('div.pod ul.linklist li:last-child').addClass('last');
	$('dl.news_list a').append('<span class="link_arrow">&gt;</span>');
});


/** Automatically make all external links open in new window/tab **/
$(document).ready(function() {
	$("a").filter(function() {
	    return this.hostname && this.hostname !== location.hostname;
	}).attr('target', '_blank');
});


/** Blog comments **/
$(document).ready(function() {
	$("#blog_comments_link a").click(function() {
		$("#blog_comments_link").fadeOut("fast", function() {
			$("#blog_comments_form_holder").fadeIn("slow", function() {
				$('#blog_comments_form').submit(function() {
					$.post(($(this).attr('action')+'/ajax'), $(this).serialize(), function($data) {
						if ($data!="FAIL") {
							$('#blog_comments_form_holder').empty();
							$('#blog_comments_form_holder').html($data);
							return(false);
						}
					});
				});
			});
		});
		return(false);
	});
});


/** Explanations **/
$(document).ready(function() {
	$("li#explain_link").show();
	$("li#explain_link").click(function() {
		$("a.glossary_link").attr("style", "background-color: orange;");
		alert('Please hover over or click any term highlighted in orange to see its definition.');
		return(false);
	});
});


function MM_CheckFlashVersion(reqVerStr, msg) {
	with (navigator) {
		var isIE = (appVersion.indexOf("MSIE") != -1 && userAgent
				.indexOf("Opera") == -1);
		var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
		if (!isIE || !isWin) {
			var flashVer = -1;
			if (plugins && plugins.length > 0) {
				var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description
						: "";
				desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description
						: desc;
				if (desc == "")
					flashVer = -1;
				else {
					var descArr = desc.split(" ");
					var tempArrMajor = descArr[2].split(".");
					var verMajor = tempArrMajor[0];
					var tempArrMinor = (descArr[3] != "") ? descArr[3]
							.split("r") : descArr[4].split("r");
					var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
					flashVer = parseFloat(verMajor + "." + verMinor);
				}
			}
			// WebTV has Flash Player 4 or lower -- too low for video
			else if (userAgent.toLowerCase().indexOf("webtv") != -1)
				flashVer = 4.0;

			var verArr = reqVerStr.split(",");
			var reqVer = parseFloat(verArr[0] + "." + verArr[2]);

			if (flashVer < reqVer) {
				if (confirm(msg))
					window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
			}
		}
	}
}