/* INITIALIZATION */

jQuery
(
 function()
 {
  /* MAIN FUNCTIONS */
  search();
  scrollable();
  hover_menu();
  slideShops();
  initPanorama();
  
  /* SHOPS SCROLL */
  
  /* MAP MENU */
  if( $( "#shopping-mall_map_search" ).length > 0 )
  {
   initMapMenu();
  }
  ByRei_jScroller2.config.refreshtime = 50;
 }
);



/* MAIN MENU */

function hover_menu()
{
 $(".nav li.space")
  .hover( function()
          {
           _this = $(this);
           clearTimeout( $(this).data( "timeout" ) );
           $(".nav li.space").each(
           function()
           {
            if( $(this).attr( 'id' ) != _this.attr( 'id' ) && $(this).find( "ul.sub-nav" ).parent( "div.container-nav" ).length == 1 )
            {
             $(this).find( "div.container-nav-bg" ).remove();
             $(this).find( "ul.sub-nav" ).unwrap();
             $(this).find( "ul.sub-nav" ).hide();
            }
           });

           if( _this.find( "ul.sub-nav" ).parent( "div.container-nav" ).length != 1 )
           {
            _this.children( "ul.sub-nav" ).wrap( "<div class=\"container-nav\">" );
            _this.children( "div.container-nav" ).append( "<div class=\"container-nav-bg\">" );
           }
           _this.find( "ul.sub-nav" ).show();
           
          }, function() {
          
           clearTimeout( $(this).data( "timeout" ) );
           var _this = $(this);
           
           $(".sub-nav li.category_shop.hasShop").each(
           function()
           {
            if( $(this).find( "ul.ul_sub-sub-nav" ).parent( "div.sub-sub-nav" ).length == 1 )
            {
             $(this).find( "ul.ul_sub-sub-nav" ).hide();
             $(this).find( "div.sub-sub-nav" ).hide();
             $(this).find( "div.sub-sub-nav div.container-nav-border" ).remove();
             $(this).find( "div.sub-sub-nav div.container-nav-bg" ).remove();
             $(this).find( "ul.ul_sub-sub-nav" ).unwrap();
            }
           });
           
           $(this).data( "timeout", setTimeout( function()
           {
           
            if( _this.find( "ul.sub-nav" ).parent( "div.container-nav" ).length == 1 )
            {
             _this.find( "div.container-nav-bg" ).remove();
             _this.find( "ul.sub-nav" ).unwrap();
             _this.find( "ul.sub-nav" ).hide();
            }
            
           }, 500 ) );
         });
             
 $(".nav li.space .sub-nav li.category_shop.hasShop")
  .hover( function()
              {
               clearTimeout( $(this).data( "timeout" ) );
               $(this).addClass( "selected" );
               var _this = $(this);
               
               if( _this.find( "ul.ul_sub-sub-nav" ).parent( "div.sub-sub-nav" ).length != 1 )
               {
                _this.find( "ul.ul_sub-sub-nav" ).wrap( "<div class=\"sub-sub-nav\">" );
                _this.children( "div.sub-sub-nav" ).prepend( "<div class=\"container-nav-border\">" );
                _this.children( "div.sub-sub-nav" ).append( "<div class=\"container-nav-bg\">" );
               }
               
               var top = _this.parent('ul.sub-nav').offset().top - _this.parents(".container-nav").offset().top;
               _this.children( "div.sub-sub-nav" ).css('top', -top);
               _this.children( "div.sub-sub-nav" ).css('height', _this.parents(".container-nav").height() + top );
               
               $(this).data( "timeout", setTimeout( function()
               {
                _this.find( "ul.ul_sub-sub-nav" ).stop().show();
                _this.find( "div.sub-sub-nav" ).stop().show();
               }, 500 ) );
               
              }, function()
              {
               $(this).removeClass( "selected" );
               clearTimeout( $(this).data( "timeout" ) );
               var _this = $(this);
               
               $(this).data( "timeout", setTimeout( function()
               {
                if( _this.find( "ul.ul_sub-sub-nav" ).parent( "div.sub-sub-nav" ).length == 1 )
                {
                 _this.find( "ul.ul_sub-sub-nav" ).hide();
                 _this.find( "div.sub-sub-nav" ).hide();
                 _this.find( "div.sub-sub-nav div.container-nav-border" ).remove();
                 _this.find( "div.sub-sub-nav div.container-nav-bg" ).remove();
                 _this.find( "ul.ul_sub-sub-nav" ).unwrap();
                }
                 
                $(".sub-nav li.category_shop.hasShop").each(
                function()
                {
                 if( $(this).hasClass( "selected" ) )
                 {
                  $(this).find( "ul.ul_sub-sub-nav" ).stop().show();
                  $(this).find( "div.sub-sub-nav" ).stop().show();
                 }
                 else
                 {
                  $(this).find( "ul.ul_sub-sub-nav" ).stop().hide();
                  $(this).find( "div.sub-sub-nav" ).stop().hide();
                 }
                });

               }, 500 ) );
              });
             
 $(".nav li.space li.shop")
  .hover( function()
              {
               clearTimeout( $(this).data( "timeout" ) );
               $(this).addClass( "selected" );
               var _this = $(this);
               
               if( _this.children( "div.sub-sub-sub-nav" ).length != 1 )
               {
                // href
                var str_href = "";
                if( typeof(  _this.attr( "href" ) ) != "undefined" )
                 str_href = _this.attr( "href" );
                // opening_times
                var str_opening_times = "";
                if( typeof( _this.attr( "opening_times" ) ) != "undefined" )
                {
                 var opening_times = _this.attr( "opening_times" ).split("|");
                 str_opening_times = "  <div class=\"div_content_shop\">Horaires d'ouverture :"
                                   + "   <div class=\"div_opening_times\">";
                 for( var i = 0; i < opening_times.length; i++ )
                 {
                  str_opening_times += "<p>" + opening_times[i] + "</p>";
                 }
                 str_opening_times += "   <\/div>"
                                    + "  <\/div>";
                }
                // phone_number
                var str_phone_number = "";
                if( typeof(  _this.attr( "phone_number" ) ) != "undefined" )
                 str_phone_number = _this.attr( "phone_number" );
                // logo_http_link
                var str_logo_http_link = "";
                if( typeof(  _this.attr( "logo_http_link" ) ) != "undefined" )
                {
                 str_logo_http_link = "  <div class=\"logo_shop_menu\">"
                                     +"   <img src=\"" + _this.attr( "logo_http_link" )  + "\" alt=\" \" style=\"max-width: 200px; max-height: 97px;\" title=\"" + _this.attr( "logo_name" )  + "\" \/>"
                                     +"  <\/div>";
                }

                _this.append( "<div class=\"sub-sub-sub-nav\">"
                             +" <div class=\"container-nav-border\"><\/div>"
                             +" <div class=\"content_sub-sub-sub-nav\">"
                             +"  <p>"
                             +"   <a href=\"" + str_href  + "\" class=\"title_nav\">Voir la fiche<\/a>"
                             +"  <\/p>"
                             +    str_logo_http_link
                             +    str_opening_times
                             +    str_phone_number
                             +" <\/div>"
                             +" <div class=\"container-nav-bg\"><\/div>"
                             +"<\/div>" );
                
                var top = _this.parent('.ul_sub-sub-nav').offset().top - _this.parents(".container-nav").offset().top;
                _this.children( "div.sub-sub-sub-nav" ).css('top', -top);
                                
                $(this).data( "timeout", setTimeout( function()
                {
                 _this.children( "div.sub-sub-sub-nav" ).stop().show();                
                }, 200 ) );
               }
               
              }, function() {
               clearTimeout( $(this).data( "timeout" ) );
               $(this).removeClass( "selected" );
               var _this = $(this);
               $(this).data( "timeout", setTimeout( function()
               {
                _this.children( "div.sub-sub-sub-nav" ).remove();
                $(".sub-nav li.shop").each(
                function()
                {
                 if( $(this).hasClass( "selected" ) )
                  $(this).children( "div.sub-sub-sub-nav" ).stop().show();
                 else
                  $(this).children( "div.sub-sub-sub-nav" ).remove();
                });
                
               }, 200 ) );
              } );
}



/* SEARCH */

function search()
{
 $("input[alt]").bind( 'focus', function()
 {
  if( $(this).data( "isEmpty" ) )
  {
   $(this).data( "isEmpty", false );
   $(this).removeClass( "defaultValue" );
   $(this).val( "" );
  }
 } );

 $("input[alt]").bind( 'blur', function()
 {
  if( $(this).val() == "" )
  {
   $(this).data( "isEmpty", true );
   $(this).val( $(this).attr( "alt" ) );
   $(this).addClass( "defaultValue" );
  }
  else
  {
   $(this).data( "isEmpty", false );
   $(this).removeClass( "defaultValue" );
  }
 } );

 $("input[alt]").each( function()
 {
  if( $(this).val() == "" || $(this).val() == $(this).attr( "alt" ) )
  {
   $(this).data( "isEmpty", true );
   $(this).val( $(this).attr( "alt" ) );
   $(this).addClass( "defaultValue" );
  }
  else
   $(this).data( "isEmpty", false );
 } );
}



/* SCROLLABLE */

function scrollable()
{
 // Scrollable
 $( "*.scrollable" )
  .css( "overflow", "hidden" )
  .each( function( i, element )
         {
          var data = { position: $(element).position(),
                       offset: $(element).offset(),
                       width: $(element).outerWidth(),
                       height: $(element).outerHeight(),
                       marginTop: isNaN( parseInt( $(element).css( "marginTop" ) ) ) ? 0 : parseInt( $(element).css( "marginTop" ) ),
                       marginLeft: isNaN( parseInt( $(element).css( "marginLeft" ) ) ) ? 0 : parseInt( $(element).css( "marginLeft" ) ),
                       marginRight: isNaN( parseInt( $(element).css( "marginRight" ) ) ) ? 0 : parseInt( $(element).css( "marginRight" ) ),
                       css: eval( "(" + $(element).attr( "scrollableCss" ) + ")" ) };
                       
          // if( $(element).attr( "scrollWidth" ) > $(element).outerWidth() || $(element).hasClass( "scrollableForceH" ) )
          // {
           // $(element).after( '<div class="scroll horizontal"><span><\/span><\/div>' );
           // $(element).next( "div.scroll" )
                     // .css({ top: ( $(element).hasClass( "scrollablePosHTop" ) ?
                                        // ( data.position.top - $(element).next( "div.scroll" ).height() ) : //- 10
                                        // ( data.position.top + data.height ) + ( data.marginTop ? data.marginTop : 0 ) ),
                            // left: data.position.left + ( data.marginLeft ? data.marginLeft : 0 ) })
                     // .css( typeof data.css == "undefined" ? {} : data.css );
           
           // $(element).next( "div.scroll" ). find( "span" )
                     // .draggable({
                                 // axis: 'x',
                                 // containment: 'parent',
                                 // drag: function( event, ui )
                                       // {
                                        // percent = ui.position.left * 100 / ( $(ui.helper).parent().width() - $(ui.helper).outerWidth() );
                                        
                                        // scrollLeft = $(element).attr( "scrollWidth" ) - $(element).width();
                                        // scrollLeft = scrollLeft * percent / 100;
                                        // $(element).attr( "scrollLeft", scrollLeft );
                                       // }
                                // });
          // }
          
          if( $(element).attr( "scrollHeight" ) > $(element).outerHeight() || $(element).hasClass( "scrollableForceV" ) )
          {
           var arrow_height = 12;
           $(element).after( '<div class="scroll vertical"><a class="scroll_top" /><span><\/span><a class="scroll_bottom" /><\/div>' );
           $(element).next( "div.scroll" )
                     .css({ top: data.position.top + ( data.marginTop ? data.marginTop : 0 ),
                            left: ( data.position.left + data.width + ( data.marginLeft ? data.marginLeft : 0 ) ),
                            height: data.height - arrow_height*2 });
           
           $(element).next( "div.scroll" ). find( ".scroll_top" )
                     .mousedown(
                      function()
                      {
                       draggableSpan = $(element).next( "div.scroll" ). find( "span" );
                       draggableParent = $(draggableSpan).parent();
                       percent = ( $(draggableSpan).position().top - parseInt( $(draggableParent).css("paddingTop") ) ) * 100 / ( $(draggableParent).height() - $(draggableSpan).outerHeight() );
                       speedPer100px = 1500;
                       speed = 0;
                       
                       distance = $(draggableParent).height() - $(draggableSpan).outerHeight();
                       distance = percent * distance / 100;
                       
                       speed = distance * speedPer100px / 100;
                       
                       $(draggableSpan).animate( { top: $(draggableParent).css("paddingTop") }, speed, 'linear' );
                       $(draggableParent).prev(".scrollable").animate( { scrollTop : 0 }, speed, 'linear' );
                      })
                     .mouseup(
                     function()
                     {
                      draggableSpan = $(element).next( "div.scroll" ). find( "span" );
                      draggableParent = $(draggableSpan).parent();
                      
                      $(draggableSpan).stop();
                      $(draggableParent).prev(".scrollable").stop();
                     });
                      
           $(element).next( "div.scroll" ). find( ".scroll_bottom" )
                     .mousedown(
                      function()
                      {
                       draggableSpan = $(element).next( "div.scroll" ). find( "span" );
                       draggableParent = $(draggableSpan).parent();
                       percent = ( $(draggableSpan).position().top - parseInt( $(draggableParent).css("paddingTop") ) ) * 100 / ( $(draggableParent).height() - $(draggableSpan).outerHeight() );
                       speedPer100px = 1500;
                       speed = 0;
                       
                       distance = $(draggableParent).height() - $(draggableSpan).outerHeight();
                       distance = ( ( 100 - percent ) < 0 ? 0 : ( 100 - percent ) ) * distance / 100;
                       
                       speed = distance * speedPer100px / 100;
                       
                       $(draggableSpan).animate( { top: ( $(draggableParent).height() + parseInt( $(draggableParent).css("paddingTop") ) - $(draggableSpan).outerHeight() ) }, speed, 'linear' );
                       $(draggableParent).prev(".scrollable").animate( { scrollTop : ( $(draggableParent).prev(".scrollable").attr("scrollHeight") - $(draggableParent).prev(".scrollable").height() ) }, speed, 'linear' );
                      })
                     .mouseup(
                     function()
                     {
                      draggableSpan = $(element).next( "div.scroll" ). find( "span" );
                      draggableParent = $(draggableSpan).parent();
                      
                      $(draggableSpan).stop();
                      $(draggableParent).prev(".scrollable").stop();
                     });
           
           $(element).next( "div.scroll" )
                     .find( "span" )
                     .draggable({
                                 axis: 'y',
                                 containment: 'parent',
                                 drag: function( event, ui )
                                 {
                                  percent = ( ui.position.top - parseInt( $(ui.helper).parent().css("paddingTop") ) ) * 100 / ( $(ui.helper).parent().height() - $(ui.helper).outerHeight() );
                                  
                                  scrollTop = $(element).attr( "scrollHeight" ) - $(element).height();
                                  scrollTop = scrollTop * percent / 100;
                                  $(element).attr( "scrollTop", scrollTop );
                                 }
                                });
          }
         } );
}


/* SLIDE SHOPS */

function slideShops()
{
 if( $( "#container_shop_scrollable > div" ).length == 2 )
 {
  // Bind events
  $( "#container_shop_scrollable" )
   .data( "positionPercent", 50 )
   .data( "timer", null )
   .mousemove( function(e)
               {
                /* $(this).data( "positionPercent", ( e.clientX - $(this).offset().left ) * 100 / $(this).width() );
                
                // Direction
                if( $(this).data( "positionPercent" ) < 30 )
                 ByRei_jScroller2.add( $( "#container_shop_scrollable > div:eq(0)" ).get(0), 'left' );
                else if( $(this).data( "positionPercent" ) > 70 )
                 ByRei_jScroller2.add( $( "#container_shop_scrollable > div:eq(0)" ).get(0), 'right' );
                
                // Speed
                if( $(this).data( "positionPercent" ) < 15 )
                 jscroller2_change_speed( $( "#container_shop_scrollable > div:eq(0)" ).get(0), '20' );
                else if( $(this).data( "positionPercent" ) < 30 )
                 jscroller2_change_speed( $( "#container_shop_scrollable > div:eq(0)" ).get(0), '5' );
                else if( $(this).data( "positionPercent" ) > 85 )
                 jscroller2_change_speed( $( "#container_shop_scrollable > div:eq(0)" ).get(0), '20' );
                else if( $(this).data( "positionPercent" ) > 70 )
                 jscroller2_change_speed( $( "#container_shop_scrollable > div:eq(0)" ).get(0), '5' );
                else */
                 jscroller2_change_speed( $( "#container_shop_scrollable > div:eq(0)" ).get(0), '0' );
               } )
   .mouseenter( function()
                {
                 window.clearTimeout( $(this).data( "timer" ) );
                } )
   .mouseout( function()
              {
               $(this).data( "timer",
                             window.setTimeout( function()
                                                {
                                                 jscroller2_change_speed( $( "#container_shop_scrollable > div:eq(0)" ).get(0), '1.7' );
                                                }, 500 ) );
              } );
  
  
  $( "#container_shop_scrollable ul li img" )
   .each( function( i, element )
          {
           $(this).css( "opacity", 0.65 );
           // console.log( this, element );
           $(this).data( "originalStyle", { width: $(this).width(), height: $(this).height() } );
           $(this).data( "originalStyle" ).opacity = 0.65;
           $(this).data( "originalStyle" ).top = ( ( $(this).parent().height() - $(this).data( "originalStyle" ).height ) / 2 ) + "px";
           $(this).data( "originalStyle" ).left = 0;
           $(this).data( "mediumStyle", ViGiSITE.core.calculSizeOfImage( null, 33, $(this).width(), $(this).height(), true ) );
           $(this).data( "mediumStyle" ).opacity = 0.80;
           $(this).data( "mediumStyle" ).top = ( ( $(this).parent().height() - $(this).data( "mediumStyle" ).height ) / 2 ) + "px";
           $(this).data( "mediumStyle" ).left = ( $(this).data( "originalStyle" ).width - $(this).data( "mediumStyle" ).width ) / 2;
           $(this).data( "bigStyle", ViGiSITE.core.calculSizeOfImage( null, 44, $(this).width(), $(this).height(), true ) );
           $(this).data( "bigStyle" ).opacity = 1;
           $(this).data( "bigStyle" ).top = ( ( $(this).parent().height() - $(this).data( "bigStyle" ).height ) / 2 ) + "px";
           $(this).data( "bigStyle" ).left = ( $(this).data( "originalStyle" ).width - $(this).data( "bigStyle" ).width ) / 2;
           
           $(this).css( "top", $(this).data( "originalStyle" ).top );
          } );
  $( "#container_shop_scrollable ul li img" )
   .mouseenter( function()
                {
                 index = $(this).index( "#container_shop_scrollable ul li img" );
                 indexPrev = ( index - 1 < 0 ? $( "#container_shop_scrollable ul li img" ).length - 1 : index - 1 );
                 indexNext = ( index + 1 > $( "#container_shop_scrollable ul li img" ).length - 1 ? 0 : index + 1 );
                 
                 $( "#container_shop_scrollable ul li img" ).eq(indexPrev).stop().css({ zIndex: 1 }).animate( $( "#container_shop_scrollable ul li img" ).eq(indexPrev).data("mediumStyle") ).parent().css({ zIndex: 1 });
                 $( "#container_shop_scrollable ul li img" ).eq(indexNext).stop().css({ zIndex: 1 }).animate( $( "#container_shop_scrollable ul li img" ).eq(indexNext).data("mediumStyle") ).parent().css({ zIndex: 1 });
                 $( "#container_shop_scrollable ul li img" ).eq(index).stop().css({ zIndex: 200 }).animate( $( "#container_shop_scrollable ul li img" ).eq(index).data("bigStyle") ).parent().css({ zIndex: 2 });
                } )
   .mouseout( function()
              {
               index = $(this).index( "#container_shop_scrollable ul li img" );
               indexPrev = ( index - 1 < 0 ? $( "#container_shop_scrollable ul li img" ).length - 1 : index - 1 );
               indexNext = ( index + 1 > $( "#container_shop_scrollable ul li img" ).length - 1 ? 0 : index + 1 );
               
               $( "#container_shop_scrollable ul li img" ).eq(indexPrev).stop().css({ zIndex: 0 }).animate( $( "#container_shop_scrollable ul li img" ).eq(indexPrev).data("originalStyle") ).parent().css({ zIndex: 0 });
               $( "#container_shop_scrollable ul li img" ).eq(indexNext).stop().css({ zIndex: 0 }).animate( $( "#container_shop_scrollable ul li img" ).eq(indexNext).data("originalStyle") ).parent().css({ zIndex: 0 });
               $( "#container_shop_scrollable ul li img" ).eq(index).stop().css({ zIndex: 0 }).animate( $( "#container_shop_scrollable ul li img" ).eq(index).data("originalStyle") ).parent().css({ zIndex: 0 });
              } );
 }
}
function jscroller2_change_speed( obj, speed )
{
 if( obj && speed )
 {
  for( var i=0 ; i<ByRei_jScroller2.obj.length ; i++ )
  {
   if( ByRei_jScroller2.obj[i][1].obj === obj )
   {
    ByRei_jScroller2.obj[i][3].speed = Number(speed);
   }
  }
 }
}


/* MAP MENU */

function initMapMenu()
{
 $( "#shopping-mall_map_search" )
  .bind( "changeThematic",
         function()
         {
          if( $( "ul.thematics" ).length > 0 )
          {
           if( $( "ul.thematics li.selected", this ).length == 1 )
           {
            var id_thematic = $( "ul.thematics li.selected", this ).attr( "id_thematic" );
            
            $( "ul.categories li:not(.title)", this ).removeClass( "inactive" ).hide();
            $( "ul.categories li:not(.title,[id_thematic=" + id_thematic + "])", this ).addClass( "inactive" ).attr( "style", "" );
           }
           else
           {
            $( "ul.categories li:not(.title)", this ).addClass( "inactive" ).hide();
            $( "ul.shops li:not(.title)", this ).addClass( "inactive" ).hide();
           }
           
           $( "ul.categories" ).data( "opened", false ).mouseover();
           $(this).trigger( "changeCategory" );
           
           if( $( "ul.categories li:not(.title, .inactive)", this ).length == 0 && id_thematic )
           {
            $( "ul.shops li[id_category*=[" + id_thematic + "]]", this ).removeClass( "inactive" ).hide();
            $( "ul.shops" ).data( "opened", false ).mouseover();
           }
          }
          else
          {
           $( "ul.categories li" ).removeClass( "inactive" );
          }
         } )
  .bind( "changeCategory",
         function()
         {
          if( $( "ul.categories li.selected:visible", this ).length == 1 )
          {
           var id_thematic = $( "ul.categories li.selected", this ).attr( "id_thematic" );
           var id_category = $( "ul.categories li.selected", this ).attr( "id_category" );
           
           $( "ul.shops li:not(.title)", this ).removeClass( "inactive" ).hide();
           $( "ul.shops li:not(.title,[id_thematic*=[" + id_thematic + "]],[id_category*=[" + id_category + "]])", this ).addClass( "inactive" ).attr( "style", "" );
          }
          else
          {
           $( "ul.shops li:not(.title)", this ).addClass( "inactive" ).attr( "style", "" );
           
           if( $('ul.thematics').length == 1 )
           {
            $( "ul.categories li:not(.title):visible", this )
             .each( function( i, element )
              {
               $( "ul.shops li[id_category*=[" + $(element).attr("id_category") + "]]", "#shopping-mall_map_search" ).removeClass( "inactive" ).hide();
               $( "ul.shops li[id_category*=[" + $(element).attr("id_thematic") + "]]", "#shopping-mall_map_search" ).removeClass( "inactive" ).hide();
              } );
           }
          }
          $( "ul.shops" ).data( "opened", false ).mouseover();
         } );
 
 
 $( "ul li:not(.title)", "#shopping-mall_map_search" ).hide();
 $( "ul", "#shopping-mall_map_search" )
  .data( "timer", null )
  .data( "clicked", false )
  .mouseover( function()
              {
               if( $(this).data( "clicked" ) == false )
               {
                window.clearTimeout( $(this).data( "timer" ) );

                if( typeof $(this).data( "opened" ) == "undefined" || $(this).data( "opened" ) == false )
                {
                 $(this).data( "opened", true );
                 $( "li:not(.title, .inactive)", this ).stop().slideDown( 300, function(){ $(this).attr( "style", "display: list-item;" ); } );
                }
               }
               
               return false;
              } )
  .mouseout( function()
             {
              if( $(this).data( "opened" ) == true )
              {
               var ul = $(this);
               $(this).data( "timer", window.setTimeout( function()
                                                         {
                                                          if( $( "li:not(.title, .inactive, .selected)", ul ).length > 0 )
                                                          {
                                                           $( "li:not(.title, .inactive, .selected)", ul )
                                                            .stop()
                                                            .slideUp( 300, function()
                                                                           {
                                                                            $(this).attr( "style", "display: none;" );
                                                                            $(ul).data( "opened", false )
                                                                                 .data( "clicked", false );
                                                                           } );
                                                          }
                                                          else
                                                          {
                                                           $(ul).data( "opened", false )
                                                                .data( "clicked", false );
                                                          }
                                                         },
                                                         300 ) );
              }
             } );
 
 
 $( "#shopping-mall_map_search ul.thematics li:not(.title)" )
  .click( function()
          {
           $(this).parent().data( "clicked", true );
           $(this).parent().mouseout();
          } )
  .mouseover( function()
              {
               if( $(this).parent().data( "clicked" ) == false )
               {
                $( "li", $(this).parent() ).not( this ).removeClass( "selected" );
                $(this).addClass( "selected" );
                $( "#shopping-mall_map_search" ).trigger( "changeThematic" );
               }
              } );
              
 $( "#shopping-mall_map_search ul.categories li:not(.title)" )
  .click( function()
          {
           $(this).parent().data( "clicked", true );
           $(this).parent().mouseout();
          } )
  .mouseover( function()
              {
               if( $(this).parent().data( "clicked" ) == false )
               {
                $( "li", $(this).parent() ).not( this ).removeClass( "selected" );
                $(this).addClass( "selected" );
                $( "#shopping-mall_map_search" ).trigger( "changeCategory" );
               }
              } );
              
 $( "#shopping-mall_map_search ul.shops li:not(.title)" )
  .click( function()
          {
           $(this).parent().data( "clicked", true );
           $(this).parent().mouseout();
          } )
  .mouseover( function()
              {
               if( $(this).parent().data( "clicked" ) == false )
               {
                $( "li", $(this).parent() ).not( this ).removeClass( "selected" );
                $(this).addClass( "selected" );
                
                $( "#map" ).get(0).setDefaultShop( 0 );
                $( "#map" ).get(0).unsetAllShops();
                
                if( $(this).hasClass( "selected" ) && typeof $(this).attr( "map_lot_number" ) != "undefined" && $(this).attr( "map_lot_number" ) != "" )
                {
                 var map_lot_number = $(this).attr( "map_lot_number" ).split( "," );
                 
                 $.each( map_lot_number,
                         function( i, value )
                         {
                          $( "#map" ).get(0).setDefaultShop( $.trim( value ) );
                          $( "#map" ).get(0).setShop( $.trim( value ) );
                         } );
                }
               }
              } );
  
  $( "#shopping-mall_map_search" ).trigger( "changeThematic" );
}



/* INIT PANORAMA */

function initPanorama()
{
 if( $( ".panorama" ).length > 0 )
 {
  $( ".panorama" )
   .data( "timer", null )
   .each( function( i )
          {
           $( "div.pano_img:eq(0)", this ).css({
                                                position: "absolute",
                                                left: 0,
                                                top:  0
                                               })
                                          .clone()
                                          .appendTo( this );
           $( "div.pano_img:eq(1)", this ).css({ left: "-" + $( "div.pano_img:eq(0)", this ).css("width") })
          } );
  
  
  $( ".panorama span.joystick.right" )
   .mouseenter( function()
                {
                 panorama = $(this).parent();
                 
                 $(this).parent()
                        .data( "timer", 
                               window.setInterval( function()
                                                   {
                                                    panoImgs = $( "div.pano_img", panorama );
                                                    $(panoImgs).animate( { left: "-=10px" }, 0 );
                                                    
                                                    $(panoImgs).each( function(i)
                                                                      {
                                                                       if( $(this).position().left < ( 0 - $(this).width() ) )
                                                                       {
                                                                        otherPano = $(panoImgs).not(this);
                                                                        $(this).css({ left: ( otherPano.position().left + otherPano.width() ) });
                                                                       }
                                                                      } );
                                                   }, 100 ) );
                } )
   .mouseout( function()
                {
                 panorama = $(this).parent();
                 panoImgs = $( "div.pano_img", panorama );
                 
                 window.clearInterval( $(this).parent().data( "timer" ) );
                 $(this).parent().data( "timer", null );
                 $(panoImgs).stop();
                } );
  
  $( ".panorama span.joystick.left" )
   .mouseenter( function()
                {
                 panorama = $(this).parent();
                 
                 $(this).parent()
                        .data( "timer", 
                               window.setInterval( function()
                                                   {
                                                    panoImgs = $( "div.pano_img", panorama );
                                                    $(panoImgs).animate( { left: "+=10px" }, 0 );
                                                    
                                                    $(panoImgs).each( function(i)
                                                                      {
                                                                       if( $(this).position().left > ( $(panorama).width() + 100 ) )
                                                                       {
                                                                        otherPano = $(panoImgs).not(this);
                                                                        $(this).css({ left: ( otherPano.position().left - $(this).width() ) });
                                                                       }
                                                                      } );
                                                   }, 100 ) );
                } )
   .mouseout( function()
                {
                 panorama = $(this).parent();
                 panoImgs = $( "div.pano_img", panorama );
                 
                 window.clearInterval( $(this).parent().data( "timer" ) );
                 $(this).parent().data( "timer", null );
                 $(panoImgs).stop();
                } );
 }
}