$(document).ready(function() {

    if (!($.browser.msie && $.browser.version.substr(0, 1) < 7)) {

        $("#mainnav li:not(#subnav li):not(li.active) ul").hide();

        $("#mainnav li:not(#subnav li)").hover(
                function() {

                    $(this).siblings().children("ul").hide();
                    $(this).children("ul").stop(1, 1);
                    $(this).children("ul").fadeIn(200);
                    $("#mainnav li.active:not(#subnav li)").addClass("restore_active");
                    $("#mainnav li.active:not(#subnav li)").removeClass("active");

                },
                function() {
                    $("#mainnav li.restore_active").addClass("active");
                    $("#mainnav li.restore_active").removeClass("restore_active");

                    $(this).children("ul").stop(1, 1);
                    if (!$(this).hasClass("active")) {
                        $(this).children("ul").fadeOut(200);
                        $("#mainnav li.active:not(#subnav li) ul").stop(1, 1);
                        $("#mainnav li.active:not(#subnav li) ul").fadeIn(200);
                    }
                }

        );
    }

    /**********************************************************
     ***** Cycle for the homepage
     **********************************************************/
	if ($('#content .teaser').length) {


		$('.teaser .content').cycle({
			fx: 'fade',
			timeout: 12000,
			pager: '.teaser_nav',
			random: 1,
			fit: 0,
			delay: 2000,
			height: '300px',
			cleartypeNoBg: true,
			pagerAnchorBuilder: pagerFactory,
			after: function(currSlideElement, nextSlideElement, options, forwardFlag) {

				if ($.browser.msie) {
					$(nextSlideElement).find('.message').fadeTo('slow', 0.8);
				} else {
					$(nextSlideElement).find('.message').fadeIn('slow');

				}
			}


		});


		$(".teaser .message").click(function(){
			var a = $(this).find('a:first');

			location = getRoot() + $(a).attr('href');
		});
    }


});

function pagerFactory(idx, slide) {
        return '<li><a href="#">'+(idx+1)+'</a></li>';
}
