/**
 * Site.js
 *
 * Custom javascript library for the XYNTEO website
 *
 * @author  John Phillips
 * @package Xynteo website
 * @subpackage   script library
 * @since   version 1
 * @version 1
 * @filesource
 *
 */
$(document).ready(function() {
    /**
     * This'll be to add a hover class for IE6 then...
     */
    $('#nav li').hover(function() {
          $(this).addClass('hover');
        }, function() {
          $(this).removeClass('hover');
        });

        $(".top-drop").click(function() {
                $(this).children().slideToggle("fast");
        });
        $(".nav-drop").hover(function () {
            $(this).children('ul').slideDown();
          },
          function () {
            $(this).children('ul').slideUp();
          });


          $(".next-drop").click(function(){
            $(this).next().slideToggle('slow');
            if($(this).hasClass('open') == true){
                    $(this).removeClass('open');
                    $(this).addClass('closed');
                }else{
                    $(this).removeClass('closed');
                    $(this).addClass('open');
                }
          });
//Collapsible functionality
        $('.collapsible').each(function(i) {
            var target = get_collapsible_target(this);
            collapsible_css(this,target, true);
        });


        $('.closed').hide();
        /**
         * Function to add expand/collapse image
         *
         *
         */
        function collapsible_css(object,target,loading){
            if(loading==false){
                if($(target).hasClass('closed')){
                    $(target).removeClass('closed');
                    $(object).addClass('opened');
                }else{
                    $(target).addClass('closed');
                    $(object).removeClass('opened');
                }
            }else{
                if( $(target).hasClass('closed')==false){
                    $(object).addClass('opened');
                }
            }
            return;
         };
        /**
         * Function to add expand/collapse image
         *
         *
         */
        function get_collapsible_target(object){
            if($(object).children().size() > 0){
                //there are child elements
                return $(object).children().not('strong');;
            }else{
                //collapse next element
                return $(object).next().not('strong');
            }
        };
        /**
         * Function to add expand/collapse image
         *
         *
         */
        $('.collapsible').click(function(){

                //determine the target
                var target = get_collapsible_target(this);
                //determine the CSS class
                collapsible_css(this,target,false);
                //show/hide target
                $(target).slideToggle();

        });
        $(".collapsible li, .collapsible a").click(function(e) {
            e.stopPropagation();
       });

});
