var TotalSlides     = 0;
var PreviousSlide   = 0;

$(document).ready(function(){       
  if($.browser.msie && $.browser.version < 7){
    if($('#Image-Maps').length > 0){
      $('#Image-Maps').attr('src','/pics/kidsclub.gif');
    }
    $("#site-content").pngFix();
  }
  
  setInterval(function(){
    StartSlideshow();
  }, 7500); 
  
  $("ul.area li a").click(
    function() { 
        var LoadUrl = $(this).attr("href") + '?_a';
        $("#content .left-column").html('<img src="/pics/ajax-loader.gif" class="loader" border="0" alt="loading..." />');
        $("#content .left-column").load(LoadUrl, function(response) { 
          $("a.lightbox").fancybox({
                'padding'                : 0,
                'autoScale'            : false,
                'transitionIn'    : 'none',
                'transitionOut'    : 'none',
                'titleShow'            : false,
                'overlayColor'  : '#1F1900'
            });
            CompareContentHeight();
            Cufon.replace('h1');
            Cufon.replace('#right-side #header .bottom');
            Cufon.replace('#navigation li a', {hover:true});
        });
        return false;
    }
  );  
    
    $("#azanimals li ul").css("display","none");
    $("#azanimals li.current ul").css("display","block");
    
    $("#azanimals li").click( function() {
        $("#azanimals li ul").css("display","none");
        $("ul", $(this)).css("display","block");
    });
  
  $("#navigation .subnavigation").css("display", "none");
  
  $("#navigation li").hover(
        function () {
            $(".subnavigation", $(this)).css("display", "block");
        }, 
        function () {
            $(".subnavigation", $(this)).css("display", "none");
        }
  );

    $("a.lightbox").fancybox({
        'padding'                : 0,
        'autoScale'            : false,
        'transitionIn'    : 'none',
        'transitionOut'    : 'none',
        'titleShow'            : false,
        'overlayColor'  : '#1F1900'
    });
    
    $("a.pong").fancybox({
        'padding'                : 0,
        'autoScale'            : false,
        'transitionIn'    : 'none',
        'transitionOut'    : 'none',
        'titleShow'            : false,
        'overlayColor'  : '#1F1900',
        'hideOnOverlayClick' : false,    
        'width'                    : 750,
        'height'                : 550,
        'type'                    : 'swf',
        'swf'                        : {
          'wmode'                        : 'transparent',
            'allowfullscreen'    : 'false',
            'bgcolor'           : '#582D0C'
        }
    });
    
    $("a.map").fancybox({
        'padding'                : 0,
        'autoScale'            : false,
        'transitionIn'    : 'none',
        'transitionOut'    : 'none',
        'titleShow'            : false,
        'overlayColor'  : '#1F1900',
        'hideOnOverlayClick' : false,    
        'width'                    : 920,
        'height'                : 650,
        'type'                    : 'iframe'
    });
    
    $("a.tictactoe").fancybox({
        'padding'                : 0,
        'autoScale'            : false,
        'transitionIn'    : 'none',
        'transitionOut'    : 'none',
        'titleShow'            : false,
        'overlayColor'  : '#1F1900',
        'hideOnOverlayClick' : false,
        'width'                    : 300,
        'height'                : 300,
        'type'                    : 'swf',
        'swf'                        : {
          'wmode'                        : 'transparent',
            'allowfullscreen'    : 'false'
        }
    });
       
    $(".youtube").click(function() {
        $.fancybox({
                'padding'                : 0,
                'autoScale'            : false,
                'transitionIn'    : 'none',
                'transitionOut'    : 'none',
                'titleShow'            : false,
                'overlayColor'  : '#1F1900',
                'width'                    : 750,
                'height'                : 500,
                'href'                    : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                'type'                    : 'swf',
                'swf'                        : {
                  'wmode'                        : 'transparent',
                    'allowfullscreen'    : 'true'
                }
            });

        return false;
    });
});    

function StartSlideshow(){
  var RightElementContainer    = $('#slide-right');
  var RightElement    = $('#slide-right a');
  
  var SlidingElement  = $('.slide');
  TotalSlides         = SlidingElement.length - 1;
  var CurrentSlide    = PreviousSlide + 1;
  
  if(PreviousSlide == TotalSlides){
    CurrentSlide      = 0;
  }

  if(TotalSlides > 0) {
    SlidingElement.eq(CurrentSlide).css({display:'block'})
    var PreviousLinkElement = SlidingElement.eq(PreviousSlide).find('.bottom');
    
    PreviousLinkElement.animate({bottom : '-80px'}, function(){
      
      SlidingElement.eq(CurrentSlide).append(RightElementContainer);
      SlidingElement.eq(PreviousSlide).find('.images').fadeOut('slow');
      SlidingElement.eq(CurrentSlide).find('.images').fadeIn('slow',function(){});
      SlidingElement.eq(PreviousSlide).find('.bottom').css('display','none');
      PreviousLinkElement.css('display','none');
      SlidingElement.eq(CurrentSlide).find('.bottom').css('display','block'); 
      var CurrentLinkElement = SlidingElement.eq(CurrentSlide).find('.bottom');      
      CurrentLinkElement.css({bottom:'-80px', display:'block'}).animate({ bottom : '0px' }, function(){
      
      RightElement.attr({'href': CurrentLinkElement.attr('href'), 'title':CurrentLinkElement.attr('title')});
      
      SlidingElement.eq(PreviousSlide).css({display:'none'});
      
      setTimeout(function(){
        PreviousSlide     = CurrentSlide; 
        return false;
      }, 1000);
      });
      
    });
    
  }
}

$(window).load(function(){
  CompareContentHeight();
});

function CompareContentHeight() {
    var LeftHeight = $("#left-side").height();
    if(LeftHeight > $("#right-side").height()) {
        $("#right-side").css("cssText", "height: " + LeftHeight + "px !important");    
    }
}
