/**
 * @projectname     Cazare Turistica
 * @version         1.0 2010.07.01
 * @copyright       Copyright (C) 2008 - 2010 All rights reserved.
 * @license         Commercial
 * @author          Székely Csaba / csaba@szekely.ro / http://www.csaba.szekely.ro
 *
 * @desc            Product accordion menu script / inspired by : Ryan Stemkoski's accordion_menu
 */

jQuery(document).ready(function() {
    // loading accordion menu
    accordionMenu();
    // language selector menu
    topMenu(".top_language_first_line",".top_language_elements_container");
}); // end ready func.



/**
* Dropdown menu sistem function
* @access public
*
* @param trigger button
* @param element to show
*
* @return none
*/

function topMenu(trigger_button, submenu_container){
        // hiding submenu placeholder
    jQuery(submenu_container).hide();
    // on anuntCategory dropdown change
    jQuery(trigger_button).hover(function(){
        // removing timeout
        clearTimeout(jQuery(trigger_button).data('timeoutId'));
        // fading in div
        jQuery(submenu_container).fadeIn(350);
    }); // end func onchange

    // hidding submenu holde if out
    jQuery(trigger_button).mouseleave(function(){
        // setting timeout for fadeout
        var timeoutId = setTimeout( function(){
            // hidding submenu
            jQuery(submenu_container).hide();
         }, 400);
        //set the timeoutId, allowing us to clear this trigger if the mouse comes back over
        jQuery(this).data('timeoutId', timeoutId);
    });  // end on mouseout
    // on submenu mouse over
    jQuery(submenu_container).hover(function(){
        // removing timeout
        clearTimeout(jQuery(trigger_button).data('timeoutId'));
    }); // end on submenu mouse over
    // on submenu mouse out
    jQuery(submenu_container).mouseleave(function(event){
//        console.log(event);
        // triggering main menu mouse out
        jQuery(trigger_button).trigger('mouseleave');
    }); // end on submenu mouse out
}; // end function topMenu



/**
* Accordion menu sistem
* @access public
* @param none
* @return none
*/

function accordionMenu(){
    // declaring curr open menu
    var curr_open = 'empty';
    //ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
    jQuery('.accordionButton').click(function() {
        // if there is a parent county
        if(jQuery(this).next('.accordionContent').children().size() > 0){
            //REMOVE THE ON CLASS FROM ALL BUTTONS
            jQuery('.accordionButton').removeClass('on');
            //NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
             jQuery('.accordionContent').slideUp('normal');
            // closing slide button
            jQuery('.accordion_expand_btn').html('+');
            // changing colors
            jQuery('.accordionButton').css({color:'#808080'});
            jQuery('.accordion_expand_btn').css({background:'#E39E37', color:'#fff'});

            //IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
            if(jQuery(this).next().is(':hidden') == true) {
                //ADD THE ON CLASS TO THE BUTTON
                jQuery(this).addClass('on');
                //OPEN THE SLIDE
                jQuery(this).next().slideDown('normal');
                // changes open button
                jQuery('.accordion_expand_btn', this).html('-');
                // changing menu color
                jQuery(this).css({color:'#0173B1'});
                jQuery('.accordion_expand_btn', this).css({background:'#0173B1', color:'#fff'});
             }  // end if this next
        }// end if menu with children.
     }); // end accordion button click

    //ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER
    jQuery('.accordionButton').mouseover(function() {
        jQuery(this).addClass('over');
    //ON MOUSEOUT REMOVE THE OVER CLASS
    }).mouseout(function() {
        jQuery(this).removeClass('over');
    }); // end button on mouse over

    // CLOSES ALL S ON PAGE LOAD
    jQuery('.accordionContent').hide();
    // the menu expand button
    jQuery('.accordion_expand_btn').html('+');
    // OPENS THE DIV THAT IS ASSIGNED WITH THE ID open
    jQuery("#open").trigger('click');
    jQuery("#open").css({color:'#0173B1'});
    jQuery("#open").find('.accordion_expand_btn').html('-');
    jQuery("#open").find('.accordion_expand_btn').css({background:'#0173B1', color:'#fff'});
} // end fuction accordion menu

