$( function ()
{

    //    $( "ul.dropdown li.dropdown_box_effect" ).click( function ()
    //    {

    //        if ( $( '#location_list' ).is( ':visible' ) )
    //        {
    //            $( this ).addClass( "hover" );
    //            $( 'ul:first', this ).css( 'visibility', 'visible' );
    //        }
    //        else
    //        {
    //            $( 'ul.dropdown li,.dropdown_box_effect', this ).removeClass( "hover" );
    //            $( '#location_list' ).css( 'visibility', 'hidden' );
    //        }

    //    } );

    var windowObjectReference = null; // global variable  
    var PreviousUrl;

    $( "ul.dropdown li ul li:has(ul)" ).find( "a:first" ).append( " &raquo; " );

    $( "ul.dropdown li.dropdown_box_effect" ).toggle( function ()
    {

        $( this ).addClass( "hover" );
        $( 'ul:first', this ).css( 'visibility', 'visible' );

        $( ".sub_menu li" ).click( function ()
        {

            var selectedText = $( 'a', this ).text();
            var redirectLocation = $( 'a', this ).attr( 'href' );
            $( '.dropdown_box_effect span' ).text( '' );
            $( '.dropdown_box_effect span' ).text( selectedText );

            //Hide the drop down
            $( 'ul.dropdown li,.dropdown_box_effect', this ).removeClass( "hover" );
            $( '#location_list' ).css( 'visibility', 'hidden' );

            if ( windowObjectReference == null || windowObjectReference.closed )
            {
                windowObjectReference = window.open( redirectLocation, "blank" );
            }
            else if ( PreviousUrl != redirectLocation )
            {
                windowObjectReference = window.open( redirectLocation, "blank" );
                /* if the resource to load is different, 
                then we load it in the already opened secondary window and then 
                we bring such window back on top/in front of its parent window. */
                windowObjectReference.focus();
            }
            else
            {
                windowObjectReference.focus();
            }
            PreviousUrl = redirectLocation;




        } );
    },
  function ()
  {

      $( 'ul.dropdown li,.dropdown_box_effect', this ).removeClass( "hover" );
      $( '#location_list' ).css( 'visibility', 'hidden' );
  }
);

} );
