jQuery(document).ready(function() {
        jQuery(".dim").css("height", jQuery(document).height());
		
		jQuery('#faq_link').trigger('click');

});

jQuery(window).bind("resize", function() { jQuery(".dim").css("height", jQuery(window).height()); });

var updateReferralCode = function(referral_code_element_id) {
    var referral_code = "";
    jQuery("#styled_form :input[name='only_apply_ref_code']").val('T');
    if (referral_code_element_id != null && typeof(referral_code_element_id) != 'undefined' && jQuery(referral_code_element_id).length) {
        referral_code = jQuery(referral_code_element_id).val();
    }
    jQuery("#styled_form :input[name='referral_code']").val(referral_code);
    jQuery("#styled_form").submit();
};

var shopFor = function(productId,trackId) {
    jQuery(productId).parent(".dim").css("height", jQuery(document).height());
    jQuery(productId).parent(".dim").fadeIn();
    jQuery(productId).centerInClient();

    jQuery(productId).parent(".dim").click(function(event) {
        if (event.target.className == "dim") {
            jQuery(productId).parent(".dim").fadeOut();
            return false;
        }
    });

    jQuery(productId).find(".close").click(function() {
        jQuery(productId).parent(".dim").fadeOut();
        return false;
    });

    return false;
};

var closeLightsoutAndSubmit = function(productId,prodType,isLoggedIn) {
    var prodname = "unknown";
    if (prodType != null && typeof(prodType) != undefined) {
        switch(prodType) {
            case 1:
                prodname = "MyReputation";
                break;
            case 2:
                prodname = "MyChild";
                break;
            case 3:
                prodname = "MyPrivacy";
                break;
            case 4:
                prodname = "MyEdge";
                break;
			case 5:
				prodname = "Bundle";
				break;
            default:
                prodname = "unknown"
        }
    }

    jQuery(productId).fadeOut();
    var url = '/secure/reg';
    var selection = jQuery(productId).find(".shoppingForm").find(':input:checked');
    if (isLoggedIn != null && typeof(isLoggedIn) != undefined && isLoggedIn) {
        url += '_clarify?';
    } else {
        url += '1?';
    }
    if (selection != null && selection.attr('value') != null) {
        url +='id='+prodType+'&plan_id='+selection.attr('value');
    }
    document.location=url;
    return false;
}

var buyIt = function(formDivId,prodType,isLoggedIn) {
    var prodname = "unknown";
    if (prodType != null && typeof(prodType) != undefined) {
        switch(prodType) {
            case 1:
                prodname = "MyReputation";
                break;
            case 2:
                prodname = "MyChild";
                break;
            case 3:
                prodname = "MyPrivacy";
                break;
            case 4:
                prodname = "MyEdge";
                break;
			case 5:
				prodname = "Bundle";
				break;
            default:
                prodname = "unknown"
        }
    }

    var url = '/secure/reg';
    var selection = jQuery(formDivId).find(".shoppingForm").find(':input:checked');
    if (isLoggedIn != null && typeof(isLoggedIn) != undefined && isLoggedIn) {
        url += '_clarify?';
    } else {
        url += '1?';
    }
    if (selection != null && selection.attr('value') != null) {
        url +='id='+prodType+'&plan_id='+selection.attr('value');
    }
    document.location=url;
    return false;
};


jQuery.fn.centerInClient  = function(options) {
    /// <summary>Centers the selected items in the browser window. Takes into account scroll position.
    /// Ideally the selected set should only match a single element.
    /// </summary>
    /// <param name="fn" type="Function">Optional function called when centering is complete. Passed DOM element as parameter</param>
    /// <param name="forceAbsolute" type="Boolean">if true forces the element to be removed from the document flow
    ///  and attached to the body element to ensure proper absolute positioning.
    /// Be aware that this may cause ID hierachy for CSS styles to be affected.
    /// </param>
    /// <returns type="jQuery" />
    var opt = { forceAbsolute: false, container: window, completeHandler: null };
    jQuery.extend(opt, options);

    return this.each(function(i) {
        var el = jQuery(this);
        var jWin = jQuery(opt.container);
        var isWin = opt.container == window;

        // force to the top of document to ENSURE that
        // document absolute positioning is available
        if (opt.forceAbsolute) {
            if (isWin)
                el.remove().appendTo("body");
            else
                el.remove().appendTo(jWin.get(0));
        }

        // have to make absolute
        el.css("position", "absolute");

        // height is off a bit so fudge it
        var heightFudge = isWin ? 2.0 : 1.8;

        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

        el.css("left", x + jWin.scrollLeft());
        el.css("top", y + jWin.scrollTop());

        // if specified make callback and pass element
        if (opt.completeHandler)
            opt.completeHandler(this);
    });
};
//document accordion
jQuery(document).ready(function() {
	//hide message_body after the first one
	jQuery(".message_list .message_body:gt(0)").hide();


	jQuery(".collapse").css("opacity","0.5");
	//toggle message_body
	
	jQuery(".expander").click(function(){
		jQuery(this).parent().next(".message_body").slideDown(500);
		jQuery(this).next(".collapse").css("opacity","1");
		jQuery(this).next(".collapse").css("color", "#FF5E00");
		jQuery(this).removeClass('link_highlight');
		jQuery(this).css("opacity","0.5");
		jQuery(this).css("color", "#434540");
		jQuery(this).css("background-position", "0 -20px")

		return false;
	});
	
	jQuery(".expand").click(function(){
		jQuery(this).parent().next(".message_body").slideDown(500);
		jQuery(this).next(".collapse").css("opacity","1");
		jQuery(this).next(".collapse").css("color", "#FF5E00");
		jQuery(this).removeClass('link_highlight');
		jQuery(this).css("opacity","0.5");
		jQuery(this).css("color", "#434540");
		jQuery(this).css("background-position", "0 -20px")

		return false;
	});

	jQuery(".collapse").click(function(){
		jQuery(this).parent().next(".message_body").slideUp(500);
		jQuery(this).prev(".expand").css("opacity","1");
		jQuery(this).prev(".expand").css("color", "#FF5E00");
		jQuery(this).prev(".expand").css("background-position","0 0");	
		jQuery(this).css("opacity","0.5");
		jQuery(this).css("color", "#434540");
		return false;
	});
});


