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('fast');
				return false;
			}
		}
	);
}


jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

};


$(document).ready(function(){
    
    initMenus();

    
    $(".showmenu").click(
        function(){ 
        	$("#related").hide();
        	$(this).next("div").toggle();
        	$(".open").hide();
        	$(this).next("div").toggleClass("open");
        	return false;
        }
    );
   
    
    $(".close a").click(
        function(){ 
        	$(".open").hide();
        }
    );
    
    $(".related").click(
        function(){ 
        	$("#related").toggle();
        	return false; }
    );
    
    $("div.news h3").click(
        function(){ 
        	$(this).toggleClass('on');
        	$(this).next(".news-links").slideToggle();
        	return false; }
    );  
    
    /* only fades in FF and Safari etc. */
    
    if((navigator.appVersion.indexOf("MSIE 7.")!=-1)) {
    
    $("div.thumb a").hover(
		function () { $(this).next('div').show() },
		function () { $(this).next('div').hide() }
	);
	
	}else{
	
	$("div.thumb a").hover(
		function () { $(this).next('div').fadeIn('fast') },
		function () { $(this).next('div').fadeOut('fast') }
	);

	}

    
    
    
    $("div.thumb a").hover(
		function () { $(this).next('div').fadeIn('fast') },
		function () { $(this).next('div').fadeOut('fast') }
	);
    
    $(".nextimg").click(
        function(){ 
        	$("#carousel").cycle('next');}
    );
    //click on body to close
    $('html').click(function() {
        //alert(1);        // 
        $(".menuarea").hide();
     });
     $('.menuarea').click(function(event){
          event.stopPropagation();
      });
         

});



$(function() {
    
    $('#carousel').cycle({
    speed:  400,
    timeout: 0,
    next:   '#next', 
    prev:   '#prev',
    pager: 	'#pager',
    pagerEvent: 'mousedown'
	});
	
});


