$(document).ready(function() {

    // dom enabled class
    $('body').addClass('js');

    $('#content_main .list_calendar li:first, #content_main .grid_1 h2:first-child, #content_main .grid_2 h2:first-child, #content_main .grid_3 h2:first-child, #content_main .grid_4 h2:first-child, #nav_meta li:first-child, #footer li:first').addClass('first');

    // print link
    $('#content_main .list_actions .print').click(function() {
        window.print();
        return false;
    });

    $("#content_main .list_entrance li li a").bigTarget({
        clickZone: 'li:eq(0)' // jQuery parent selector
    });

    // nav_offices
    $('#content .rounded').prepend('<span class="top"></span>').append('<span class="btm"></span>');
    $('#nav_offices .body').hide();
    $('#nav_offices').hoverIntent({
        interval: 0,
        over: makeTall,
        timeout: 500,
        out: makeShort
    });
    function makeTall() { $(this).find('h4 a').addClass('hover').end().find('.body').show(); }
    function makeShort() { $(this).find('h4 a').removeClass('hover').end().find('.body').hide(); }

    $('#nav_offices h4 a, #nav_offices li a').focus(function() {
        $(this).addClass('hover').parent().next().show();
    });
    $('#nav_offices li a').focus(function() {
        $(this).parents('#nav_offices').find('h4 a').addClass('hover').parent().next().show();
    });
    $('#nav_sub li a').not($('#nav_offices li a')).focus(function() {
        $(this).parents('#nav_sub').find('#nav_offices h4 a').removeClass('hover').parent().next().hide();
    });


    // alternative toggle function for simpleMenu
    function altToggleMenu(item, toggle) {
        $(item)[toggle ? 'addClass' : 'removeClass'](this.activeClass);
        var sub = $(item).find(this.menuType).eq(0);
        sub[toggle ? 'slideDown' : 'slideUp']('fast');
    }

    // main navigation
    $('#nav_main').simpleMenu({
        itemType: '#nav_main > ul > li',
        menuType: 'div.nav_main_sub',
        toggleMenu: altToggleMenu
    });

    // homepage entrance blocks
    $('#content_main .list_entrance').simpleMenu({
        itemType: '.list_entrance > li',
        menuType: 'ul',
        toggleMenu: altToggleMenu
	}).find('li:first .entrance_container').hide();

	// FAQ
	var faq = new LBi.Tabs({
	   menuSelector: 'ul.faq',
	   tabRelation: 'faq'
	});
	
	// dialog
	$('object').prepend('<param name="wmode" value="transparent" />');
	$('embed').attr("wmode", "transparent");
	// IE requires more work
	$(document).ready(function() {
		var embedTag;
		$("embed").each(function(i) {
			embedTag = $(this).attr("outerHTML");
			if ((embedTag != null) && (embedTag.length > 0)) {
				embedTag = embedTag.replace(/embed /gi, "embed wmode=\"transparent\" ");
				$(this).attr("outerHTML", embedTag);
			}
		});
	});

	$('#content_main a[rel="dialog-disclaimer"]').click(function() {
		var disclaimerUrl =	this.href;
		$('#dialog-disclaimer .disclaimer-yes').attr('href', disclaimerUrl);
	});

	var manager = new LBi.Dialogs({
		template:		'<div class="dialog"><p></p></div>',
		orientation:	'top right',
		offset:			10,
		modal:			false
	});
	manager.register('disclaimer', LBi.Class.extend(
		// base class to extend from
		LBi.CenteredDialog,

		// constructor
		function() {
			this.modal = true;
			$('body').addClass('overlay-inc');
		}
	));

});