// JavaScript Document
/**
 * Main menu, categories menu and buttons
 */
$(function(){
		
    // BUTTONS
    $('.fg-button').hover(
        function(){
            $(this).removeClass('ui-state-default').addClass('ui-state-focus');
        },
        function(){
            $(this).removeClass('ui-state-focus').addClass('ui-state-default');
        }
        );
	
    // MENUS
    $('#flat').menu({
        content: $('#flat').next().html(), // grab content from this page
        showSpeed: 400,
        width: 148
    });
	
    $('#flat2').menu({
        content: $('#flat2').next().html(), // grab content from this page
        showSpeed: 400,
        width: 175
    });
	
    $('#flat3').menu({
        content: $('#flat2').next().html(), // grab content from this page
        showSpeed: 400,
        width: 175
    });
	
    $('#flat4').menu({
        content: $('#flat4').next().html(), // grab content from this page
        showSpeed: 400,
        width: 175
    });
	
    $('#flat5').menu({
        content: $('#flat2').next().html(), // grab content from this page
        showSpeed: 400,
        width: 175
    });
	
    $('#hierarchy').menu({
        content: $('#hierarchy').next().html(),
        flyOut: true,
        width: 100
    });
	
    $('#hierarchy').click( function(){
        //$('#category_menu_panel').slideUp();
        slideToggle('#category_menu_panel', false);
    }
    );
	
    $('#flat').click( function(){
        //$('#category_menu_panel').slideUp();
        slideToggle('#category_menu_panel', false);
    }
    );
	
    $('body').click(function(){
        //$('#category_menu_panel').slideUp();
        slideToggle('#category_menu_panel', false);
    });
	
    /*
	$('#category_menu_btn').click(function(e){
		e.stopPropagation();
	});
	*/
	
	var hiConfig = {    
         sensitivity: 3,
         interval: 400,
         over: toggleMenu,
         timeout: 500,
         out: toggleMenuOut     
    };
 
   /* $('#category_menu_btn').hoverIntent( hiConfig );*/
	
 if ($('#category_menu_btn').length)
 {
  $('#category_menu_btn').hoverIntent( hiConfig );
 }
 
    $('#category_menu_panel').hover(
        function () {
        },
        function () {
            closeOtherMenus();
            //$('#category_menu_panel').slideUp();
            slideToggle('#category_menu_panel', false);
                showSpeed: 400;
            $('#category_menu_item').removeClass("oemenu-li-hover");
            $('#category_menu_item').addClass("oemenu-li");
        }
        );
	
    //ie6
    $('#category_menu_item').hover(
        function () {
            $(this).removeClass("oemenu-li");
            $(this).addClass("oemenu-li-hover");
        },
        function () {
        //$(this).removeClass("oemenu-li-hover");
        //$(this).addClass("oemenu-li");
        }
        );
	
/*
	$('.menu-second-li').hover(
      function () {
		$(this).removeClass("menu-second-li"); 
  	    $(this).addClass("menu-second-li-hover");
      }, 
      function () {
		$(this).removeClass("menu-second-li-hover"); 
  	    $(this).addClass("menu-second-li");
      }
    );
	
	$('div.left_hover').hover(
      function () {
		$(this).removeClass("menu-div-left"); 
  	    $(this).addClass("menu-div-left-hover");
      }, 
      function () {
		$(this).removeClass("menu-div-left-hover"); 
  	    $(this).addClass("menu-div-left");
      }
    ); */
	
});

function toggleMenu()
{
	slideToggle('#category_menu_panel', true);
}
	
function toggleMenuOut()
{
}

function closeOtherMenus() {
    for(var i=0; i<allUIMenus.length; i++) {
        menuHandle = allUIMenus[i];
        if (menuHandle.menuOpen == true) {
            menuHandle.kill();
        }
    }
}

//this is a fix for the jQuery slide effects
function slideToggle(el, bShow){
    var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");
  
    // if the bShow isn't present, get the current visibility and reverse it
    if( arguments.length == 1 ) bShow = !visible;
  
    // if the current visiblilty is the same as the requested state, cancel
    if( bShow == visible ) return false;
  
    // get the original height
    if( !height ){
        // get original height
        height = $el.show().height();
        // update the height
        $el.data("originalHeight", height);
        // if the element was hidden, hide it again
        if( !visible ) $el.hide().css({
            height: 0
        });
    }

    // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
    if( bShow ){
        $el.show().animate({
            height: height
        }, {
            duration: 250
        });
    } else {
        $el.animate({
            height: 0
        }, {
            duration: 250,
            complete:function (){
                $el.hide();
            }
        });
    }
}


/* lang menu */
$(function(){
    // BUTTONS
    $('.fg-button').hover(
        function(){
            $(this).removeClass('ui-state-default').addClass('ui-state-focus');
        },
        function(){
            $(this).removeClass('ui-state-focus').addClass('ui-state-default');
        }
        );

    // MENUS
    $('#hierarchy').menu({
        content: $('#hierarchy').next().html(),
        crumbDefaultText: ' '
    });

    $('#hierarchybreadcrumb').menu({
        content: $('#hierarchybreadcrumb').next().html(),
        backLink: false
    });
});