function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function()
	{
		var cookie = $.cookie(this.id);
		if(cookie != null && String(cookie).length < 1) 
		{
			$('#' + this.id + '.expandfirst ul:first').show();
		}
		else 
		{		
			$('#' + this.id + ' .' + cookie).next().show();
		}
	});
	$('ul.menu li a').click(
		function() {

			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) 
			{
				if((String(parent).length > 0) && (String(this.className).length > 0)) 
				{
					if($(this).next().is(':visible')) 
					{
						$.cookie(parent, null);
					}
					else 
					{
						$.cookie(parent, this.className);
					}
					$(this).next().slideToggle('normal');
				}				
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) 
			{
				if($('#' + parent).hasClass('collapsible')) 
				{
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) 
			{
				$('#' + parent + ' ul:visible').slideUp('normal');
				if((String(parent).length > 0) && (String(this.className).length > 0)) 
				{
					$.cookie(parent, this.className);
				}
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}

var lc = 1;
var lt = null;

function initLandingPages() {
    $('ul.menu li a').click(function() {
        if ($(this).attr('id') != "") {
            var page_name = $(this).attr('id'); // need to give anchor id same as 'page' in XML
            //alert(page_name);

            var lpArray = eval(page_name);

            var page_body_html = RenderLandingArea(lpArray);
            resetLoader();
            $('div#page-body').html(page_body_html);
            $('div#page-body img').load(landLoaded);

            //            $.ajax(
            //			{
            //			    type: 'GET',
            //			    url: 'landing.xml?',
            //			    dataType: 'xml',
            //			    success: function(xml) {
            //			        var page_node = $(xml).find('page[id = ' + page_name + ']');
            //			        var page_body_html = page_node.find('page-body').text();
            //			        resetLoader();
            //			        $('div#page-body').html(page_body_html);
            //			        $('div#page-body img').load(landLoaded);
            //			    }
            //			})
        }
    });
}

function landLoaded() {
    if ($('div#page-body img').length > lc) {
        lc++;
    }
    else showLanding();
}

function resetLoader()
{
    $('div#page-body-loader').show();
    $('div#page-body').hide();
    lc = 1;
    if (lt != null) clearTimeout(lt);
    lt = setTimeout(showLanding, 6000);
}

function showLanding() {
    $('div#page-body-loader').hide();
    $('div#page-body').show();
}

$(document).ready(function() { initMenus(); initLandingPages(); });