﻿//-----------------------------------------------
// User-defined functions using jQuery library
// Version: 1.0
// Authors: Conor MacNeill
// Date: 23/07/08
//-----------------------------------------------

(function($){
  $.fn.vCenter = function(options) {
    var pos = {
      sTop : function() {
        return window.pageYOffset || document.documentElement && document.documentElement.scrollTop ||	document.body.scrollTop;
      },
      wHeight : function() { 
        return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;
      }
    };
    return this.each(function(index) {
      if (index == 0) {
        var $this = $(this);
        var elHeight = $this.height();
		    var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
        $this.css({
          position: 'absolute',
          marginTop: '0',
          top: elTop
        });


      }
    });
  };

})(jQuery);

// Hides popup straight away
//$("div.popup").addClass("hidden");

// When DOM is ready...
$(document).ready(function(){
    // Company lookup
    /*$("a.company-lookup").click(function() {
        $("div[class*='popup']").fadeOut("normal");
        $("#company-lookup").fadeIn("slow");
        if (!$.browser.opera) { 
            $("#company-lookup").draggable(); 
        }
        return false;
    });*/
    
    // Close popup
    $("div.popup a.popup-close") 
        .livequery("click", function(event) { 
            $(this).parent().parent().fadeOut("slow");
            $("#error-popup").remove();
            /*$(this).parent().parent().queue(function() {
                $("#error-popup").remove();
            });*/
            return false;
        }
    );

    $("div.popup a.popup-close-fast") 
        .livequery("click", function(event) { 
            $(this).parent().parent().hide();
            return false;
        }
    );    
    


    // Fix for IE6 lack of :hover support - NEEDS MORE WORK
    /*if ($.browser.msie) {

        $("ul.tiered-menu li").hover(
            function() {
                $(this).children().children().prepend("<!--[if IE 6]><iframe class=\"popup\"></iframe><![endif]-->");
                $(this).children().addClass("submenu");
            },
            function() {
                $("iframe").remove();
                $(this).children().removeAttr("class");
            }
        );

    }*/


    // Trying to emulate min-width in IE6
    var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
    if (badBrowser) {
        $(window).bind("load resize", 
            function() {
                var w   = $(window).width();
                var minWidth = $("body").css("min-width");
                if(minWidth != null) {
                    var nav = minWidth.replace("px","");

                    if ( w <= nav ) {
                        $("body").css("width",minWidth);
                    }
                    if ( w > nav ) {
                        $("body").removeAttr("style");
                    }
                }
            }
         );
    } // END if IE/badBrowser


    // Position popup in middle of the window
    $(window).bind("load resize",
        function() {
            var windowHeight = $(window).height();
            var popupHeight = $("div.popup").height();
            var headerHeight = $("div.header").height();
            var topCss = ( (windowHeight / 2) - (popupHeight / 2) ) - headerHeight - 15;
            $("div.popup").css("top",topCss);
        }
    );


}); // END DOM


function toggleCheckBox(firstID, secondID) {
    if ($("#" + firstID).is(":checked")) {
        $("#" + secondID).attr("checked", false);
        $("#" + secondID).attr("disabled", true);
    }
    else {
        $("#" + secondID).attr("disabled", false);
    }
}

function displaySovereignInfo(subsectorid, labelId) {
    if ($("#" + subsectorid + " option[value='sovereignwealthf']").is(":selected")) {
        $("#" + labelId).css("visibility", "visible"); ;
    }
    else {
        $("#" + labelId).css("visibility", "hidden");
        
    }
}

