var headingFont = {
    src: '/Fonts/fontin.swf'//,
    //ratios: [7, 1.32, 11, 1.31, 13, 1.24, 14, 1.25, 19, 1.23, 27, 1.2, 34, 1.19, 42, 1.18, 47, 1.17, 48, 1.18, 69, 1.17, 74, 1.16, 75, 1.17, 1.16]
    };
sIFR.activate(headingFont);

$(document).ready(function() {
						   
	function pageLoad(hash) {
		if(hash) {
			$("#content-wrapper").load(hash + ".aspx #Content",'',function() {
				$("#content-wrapper").fadeIn("normal");
				onContentLoaded();
			});
		} else { //default
			$("#content-wrapper").load("Default.aspx #Content",'',onContentLoaded()); 
		}
	}

	function onContentLoaded() {
	    $("#Footer").fadeIn("normal");
        $("#Content").css("zoom", '');
	    setContentLinkHandlers();
	    setCustomFonts();
	    $('#ClientList').listnav({
	        includeAll: true,
	        showCounts: false
	        });
		setFaqHandlers();
		setHeights();
	}
	
	function setContentLinkHandlers() {
	    $("a.ContentLink").unbind("click");
	    $("a.ContentLink").click(function() {
	        loadContent($(this));
	        return false;
	    });
	}

    function setFaqHandlers() {
        $('.faq').find('dd').hide();
	    $('.faq').find("dt").click(function(){
	        $(this).next().toggle();
		});
    }

	function setCustomFonts() {
        sIFR.replace(headingFont, {
              selector: 'h1',
              css: [
              '.sIFR-root { font-size:32px; font-weight:normal; text-align: center; color: #46592A; }'
              ],
              wmode: 'transparent'
        });
        sIFR.replace(headingFont, {
              selector: 'h2',
              css: [
              '.sIFR-root { font-size:18px; font-weight:normal; text-align: left; color: #46592A; }'
              ],
              wmode: 'transparent'
        });
        sIFR.replace(headingFont, {
              selector: 'h3',
              css: [
              '.sIFR-root { font-size:16px; font-weight:normal; text-align: left; color: #46592A; }'
              ],
              wmode: 'transparent'
        });
        sIFR.replace(headingFont, {
              selector: '#ContactList dt',
              css: [
              '.sIFR-root { font-size:16px; font-weight:normal; text-align: right; color: #46592A; }'
              ],
              wmode: 'transparent'
        });
	}

    function setHeights() {
		var windowHeight = $(window).height();
        var contentHeight = windowHeight - 260;
        if (contentHeight > 0)
        {
	        $("#ContentContainer").css('min-height', contentHeight + 'px'); 
		    var verbiageHeight = contentHeight - 60;
		    if (verbiageHeight > 0)
		    {
	            $(".Verbiage").height(verbiageHeight + 'px');
	        }
	        var clientListHeight = contentHeight - 105;
		    if (clientListHeight > 0)
		    {
	            $("#ClientList").height(clientListHeight + 'px');
	        }
	    }
	}

    function initHistory() {
	    var initialHash = $.history.getCurrent();
	    if(initialHash == '') {
	        var pageURL = $(window).attr("location").pathname;
		    initialHash = getURLHash(pageURL);
		}
		$.history.add(initialHash);
		
	    $(window).historyadd(function(e, currentHash, previousHash) {
		    if(currentHash == '') {
			    currentHash = 'Default';
		    }
		    pageLoad(currentHash);
	    });
	    
	    $(window).history(function(e, hash) {
		    if(hash == '') {
			    hash = 'Default';
		    }
		    pageLoad(hash);
	    });
    }
    
    function getURLHash(url) {
        var hash = url;
        hash = hash.replace(/^.*#/, '');
        hash = hash.substr(0,hash.length-5);
        return hash;
    }
    
	function loadContent(link) {
	    var currentHash = $.history.getCurrent();
	    var nextHash = getURLHash(link.attr("href"));
        if (nextHash != currentHash)
        {
            $("#Footer").fadeOut("fast");
            $("#content-wrapper").fadeOut("fast",function(){$.history.add(nextHash)});
        }
	}
	
	$("#Content").wrap('<div id="content-wrapper"></div>');
    setHeights();
    initHistory();

    //GKJ$(".PlainCornered").corner();
    $("#PageContainer").fadeIn("fast", function() {
        $(this).css("zoom", '');
        var myBorder = RUZEE.ShadedBorder.create({ corner:8, shadow:16 });
        myBorder.render('Header');
        myBorder.render('ContentContainer');
        //GKJ$("#MainMenu").corner();
        onContentLoaded();
    });
    $(window).resize(function(){
        setHeights();
    });    
});
