//Font rendering
Cufon.replace('#leftColumn h1');
Cufon.replace('#leftColumn h2');
Cufon.replace('#leftColumnSingle h1');
Cufon.replace('#leftColumnSingle h2');
Cufon.replace('#rightColumn h1');

function hideDDL(btnID){
		$("#"+ btnID + "DDL").fadeOut("normal");
}

function showDDL(btnID){
		var btnPos = $("#"+ btnID).position();
		var btnWidth = $("#"+ btnID).width();
		var btnHeight = $("#"+ btnID).height();
		var ddlX = btnPos.left + (btnWidth / 2);
		var ddlY = btnPos.top - 0;		
		
		$("#"+btnID+"Link").height(($("#"+ btnID + "DDL").height() + btnHeight) + "px"); 
		
		$("#"+ btnID + "DDL").css("top", (ddlY + btnHeight) + "px");
		$("#"+ btnID + "DDL").css("left", ddlX + "px");
		$("#"+ btnID + "DDL").fadeIn("fast");
}

$(document).ready(function() {
    //BEGIN FLASH DETECTION
    hideAlert();

    var flashVersion = swfobject.getFlashPlayerVersion();

    //Uncomment the following line to reset the cookie.  FOR TESTING ONLY
    //$.cookie('EQTRemind', 'true');  

    if ($.cookie('EQTRemind') == "true" || $.cookie('EQTRemind') == null) {
        //If the reminder cookie is true then proceed 
        if (flashVersion.major <= 9 && flashVersion.release < 155) {
            //If the Flash version is less than our specified version then proceed
            if (flashVersion.major == 0) {
                $("#flashMessage").slideDown("1000");
                $("#alertIcon").fadeIn("700");
                $("#alertMessage").html("<img src='/images/alertMessage.gif' border='0' usemap='#Map' /><map name='Map' id='Map'><area shape='rect' coords='607,0,793,10' href='http://www.adobe.com/go/EN_US-H-GET-FLASH' target='_blank' alt='Get Flash' /></map>");
                $("#alertMessage").fadeIn("700");
                $("#dontAsk").fadeIn("700");
                $("#alertClose").fadeIn("700");
            }
            else {
                //If there is no Flash then proceed  
                $("#flashMessage").slideDown("1000");
                $("#alertIcon").fadeIn("700");
                //Easiest way to detect what has been checked on the "Don't Ask Again" box.
                $("#alertMessage").html("<img src='/images/alertMessageUpgrade.gif' border='0' usemap='#Map' /><map name='Map' id='Map'><area shape='rect' coords='560,0,753,10' href='http://www.adobe.com/go/EN_US-H-GET-FLASH' target='_blank' alt='Get Flash' /></map>");
                $("#alertMessage").fadeIn("700");
                $("#dontAsk").fadeIn("700");
                $("#alertClose").fadeIn("700");
            }
        }
    }

    $("#dontAsk").click(function() {
        $("#dontAsk img").toggle();
    });

    $("#alertClose").click(function() {
        if ($("#dontAskNoCheck").css("display") == "block" || $("#dontAskNoCheck").css("display") == "inline") {
            $.cookie('EQTRemind', 'true');
        }
        if ($("#dontAskCheck").css("display") == "block" || $("#dontAskCheck").css("display") == "inline") {
            $.cookie('EQTRemind', 'false');
        }
        $("#flashMessage").slideUp("600");
    });
    // END FLASH DETECTION



	//Drop Down Menus
	$(".mainNavItem").hoverIntent(
		function(){showDDL($(this).attr("id"));},
		function(){hideDDL($(this).attr("id"));}
	);						   
	
	//Main Nav Image Swap
    $("#mainNav a img").mouseover(function() { var t = $(this); t.attr('src', t.attr('src').replace('_nor', '_ovr')); });
    $("#mainNav a img").mouseout(function() { var t = $(this); t.attr('src', t.attr('src').replace('_ovr', '_nor')); });

    //News Background Image Swap
    //	$(".dkBox").mouseover(function(){var t= $(this);t.css('background-image',t.css('background-image').replace('_nor','_ovr'));});
    //	$(".dkBox").mouseout(function(){var t= $(this);t.css('background-image',t.css('background-image').replace('_ovr','_nor'));});
    //	$(".ltBox").mouseover(function(){var t= $(this);t.css('background-image',t.css('background-image').replace('_nor','_ovr'));});
    //	$(".ltBox").mouseout(function(){var t= $(this);t.css('background-image',t.css('background-image').replace('_ovr','_nor'));});

    //Home page buttons
    $(".learnMore_blu").mouseover(function() { var t = $(this); t.attr('src', t.attr('src').replace('_nor', '_ovr')); });
    $(".learnMore_blu").mouseout(function() { var t = $(this); t.attr('src', t.attr('src').replace('_ovr', '_nor')); });
    $(".learnMore_brn").mouseover(function() { var t = $(this); t.attr('src', t.attr('src').replace('_nor', '_ovr')); });
    $(".learnMore_brn").mouseout(function() { var t = $(this); t.attr('src', t.attr('src').replace('_ovr', '_nor')); });
    $(".learnMore_org").mouseover(function() { var t = $(this); t.attr('src', t.attr('src').replace('_nor', '_ovr')); });
    $(".learnMore_org").mouseout(function() { var t = $(this); t.attr('src', t.attr('src').replace('_ovr', '_nor')); });
    $(".allNewsButton a img").mouseover(function() { var t = $(this); t.attr('src', t.attr('src').replace('_nor', '_ovr')); });
    $(".allNewsButton a img").mouseout(function() { var t = $(this); t.attr('src', t.attr('src').replace('_ovr', '_nor')); });

    $("#mapContainer a").click(function() {
        var thisID = $(this).attr("id");
        var thisPage = $(this).attr("rev");
        $("#" + thisID).colorbox({ width: "600", height: "550", iframe: true, href: thisPage, open: true });
    });
	
	try {
		$(".single").colorbox();
	}
	catch(err){}

    $("#contactForm input").click(function() {
        if ($(this).attr("type") == "checkbox") { $("#" + $(this).attr("id") + "_bubble").fadeOut("normal"); }
    });

    $("#contactForm input").keyup(function() {
        clearBubble($(this).attr("id"));
    });
    $("#contactForm textarea").keyup(function() {
        clearBubble($(this).attr("id"));
    });
    $("#contactForm select").mouseup(function() {
        clearBubble($(this).attr("id"));
    });
	
	//Calculators setup
	$('#A_CalculatorDisclaimer').css('display','none');
	$('.Footnote').css('display','none');
	
	$.each($('#rightColumn p a'), function(i, val){
		if($(this).attr('title') == 'http://www.TimeValue.com'){$(this).css('display','none');}								   
	});
	//alert($('#rightColumn a').attr('title'));
	$('#calcDisclaim').hide();
	$('#calcTips').hide();
	$('.disclaimer').toggle(function(){
		$('#calcDisclaim').slideDown('normal');										
	},function(){
		$('#calcDisclaim').slideUp('normal');		
	});
	
	$('.tips').toggle(function(){
		$('#calcTips').slideDown('normal');										
	},function(){
		$('#calcTips').slideUp('normal');		
	});
	//$('.disclaimer').colorbox({width:500, height:400, inline:true, href:"#calcDisclaim"});		
});

function checkVal(fieldID, message, valType, cbxOffset) {
    var fieldVal = $("#" + fieldID).attr("value");
    var bubbleID = fieldID + "_bubble";
    var pos = $("#" + fieldID).position();
    var fieldWidth = $("#" + fieldID).width();
    fieldWidth = fieldWidth - 35; //just an offset to make it look good.

    var bubbleContent = "<div class='bubble' id='" + bubbleID + "'>";
    bubbleContent = bubbleContent + "<div class='bubbleTop'><a href='javascript:void(0);'></a></div><div class='bubbleContent'>" + message + "</div><div class='bubbleBot'></div></div>";
    $("body").append(bubbleContent);
    //$("body").append("<div class='bubble' id='" + bubbleID + "'>" + message + "</div>");
    var bubbleHeight = $("#" + bubbleID).height();
    $("#" + bubbleID).css("left", pos.left + fieldWidth + cbxOffset);
    $("#" + bubbleID).css("top", (pos.top - bubbleHeight) + 2);
    $("#" + bubbleID).fadeTo("fast", .7);

    switch (valType) {
        case "email":
            if (isMail(fieldVal) == true) { $("#" + bubbleID).hide(); $("#ctl00_cphLeftColumnSingle_btnSubmit").attr("disabled", ""); break; }
            else { $("#" + bubbleID).css("display", "block"); }
            return false;
            break;
        case "hasContent":
            if (fieldVal.length > 0) { $("#" + bubbleID).hide(); $("#ctl00_cphLeftColumnSingle_btnSubmit").attr("disabled", ""); break; }
            else { $("#" + fieldID).focus(); $("#" + bubbleID).css("display", "block"); }
            return false;
            break;
        case "cbx":
            $("#" + fieldID).focus(); $("#" + bubbleID).css("display", "block");
            return false;
            break;
    }
}

function isMail(_email) {
    var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
    return emailReg.test(_email);
}

function validateText(oSrc, args) {
    args.IsValid = checkVal(oSrc.controltovalidate, oSrc.errormessage, "hasContent", 0);
    if (args.IsValid == false) {
        $("#" + oSrc.id + "span").hide();
        return false;
    }
    else { args.IsValid = true; }
}

function validateEmail(oSrc, args) {
    args.IsValid = checkVal(oSrc.controltovalidate, oSrc.errormessage, "email", 0);
    if (args.IsValid == false) {
        $("#" + oSrc.id + "span").hide();
        return false;
    }
    else { args.IsValid = true; }
}

function hideAlert() {
    $("#flashMessage").hide();
    $("#alertIcon").hide();
    $("#alertMessage").hide();
    $("#dontAsk").hide();
    $("#alertClose").hide();
}