(function ($) {

Drupal.behaviors.teleport = {
  attach: function(context, settings) {
    /*$('div#tasks').css({position: 'absolute', top: 0});
    $('div#tasks').hide();
    
    $('section#main-content').hover(function () {
      $('div#tasks').show();
    }, function () {
      $('div#tasks').hide();
    });*/
    
    //$('.article-content #slider').css({height: 0});
    //$('#menu-secondary').hide();
    $('#adverts-wrapper ul.rubric').hover(function () {
      $('#adverts-wrapper ul.rubric a').fadeIn('fast');
      $('#adverts-wrapper ul.rubric').css({'border': '1px solid #DDD', 'box-shadow': '2px 2px 10px rgba(0,0,0,0.1)'});
      $('#adverts-wrapper ul.rubric a.active').css({color: '#444', 'border-bottom': 'none'});
      $('#adverts-wrapper ul.rubric li').css({'background': 'none'});
    }, function () {
      $('#adverts-wrapper ul.rubric a:not(.active)').hide();
      $('#adverts-wrapper ul.rubric').css({'border': '1px solid #FFF', 'box-shadow': 'none'});
      $('#adverts-wrapper ul.rubric a.active').css({color: '#08C', 'border-bottom': '1px dotted #08C'});
      $('#adverts-wrapper ul.rubric li').css({'background': 'transparent url(/sites/teleport/themes/adaptivetheme_teleport/css/images/icon-arrow-down.png) left center no-repeat'});
    });

    $('#menu-bar').mouseover(function() {
      if ($('#menu-secondary').css('display') == 'block') {
        clearTimeout(timer);
      } 
      else {
        timer = setTimeout(function () { 
          $('#menu-secondary').slideDown('fast', function () { 
            $('#menu-bar #menu-user-block .item-list').show();
            //$(this).stop();
          });
        }, 400);
      }
    });

    $('#menu-bar').mouseout(function() {
      if ($('#menu-secondary').css('display') == 'none') {
        clearTimeout(timer);
      }
      else {
        timer = setTimeout(function () {
          $('#menu-bar #menu-user-block .item-list').hide();
          $('#menu-secondary').slideUp('fast');
        }, 1000);
      }
    });

    /*$('#menu-bar ul.menu-primary li span').click(function () {
      if ($('#menu-secondary').css('display') != 'block') {
        $('#menu-secondary').slideDown(300, function () { 
          $('#menu-bar #menu-user-block .item-list').show();
          //$(this).stop();
        });
      }
    });*/

    $('#menu-bar ul.menu-primary li a, #menu-bar ul.menu-primary li span').mouseenter(function () {
      //h = $('#menu-secondary').height();
      $('#menu-bar #menu-secondary ul.menu').hide();
      $('#menu-bar #menu-secondary ul.menu-' + $(this).attr('rel')).show();
      $('#menu-bar #menu-secondary ul.menu-' + $(this).attr('rel')).css({opacity: 0});
      $('#menu-bar #menu-secondary ul.menu-' + $(this).attr('rel')).animate({opacity: 1});
    });

    $('#weather a.weather').click(function () {
      if (!$(this).hasClass('active')) {
        var parent = '#' + $(this).parent().parent().attr('id');
        //alert(parent + ' div.' + $('#weather a.weather.active').attr('rel'));
        $(parent + ' div.' + $(parent + ' a.weather.active').attr('rel')).hide(); 
        $(parent + ' div.' + $(this).attr('rel')).fadeIn();
        $(parent + ' a.weather').removeClass('active');
        $(this).addClass('active');
      }
    });    

    function hideCities() {
      $('#weather-cities').css({
        background: 'none',
        border: '1px solid transparent',
        'box-shadow': 'none'
      });
      $('#weather-cities').find('a:not(.active)').hide();
      $('#weather-cities').find('a.active').removeClass('hover');
    }

    $('#weather-cities').hover(function () {
      $(this).find('a.active').addClass('hover');

      if (jQuery.support.opacity) {
        $(this).css({
          background: 'rgba(255, 255, 255, 0.9)'
        });
      }
      else {
        $(this).css({
          background: '#FFF'
        }); 
      }

      $(this).css({
        border: '1px solid #EEE',
        'box-shadow': '2px 2px 10px rgba(0,0,0,0.2)'
      });
      //$('#weather-cities').find('a').slideDown();
      $('#weather-cities').find('a').fadeIn();
    }, function () {
      hideCities();
    });

    $('#weather-cities a').click(function () {
      if (!$(this).hasClass('active')) {
        $('#weather div.weather').hide();
        $('#weather div#weather-' + $(this).attr('rel')).show();
        $('#weather-cities').find('a.active').removeClass('active');
        $(this).addClass('active');
        hideCities();
        $.cookie('teleport_weather_city', $(this).attr('rel'), {expires: 365});
      }
      //alert($.cookie('teleport_weather_city'));
    });
    
    $('#currencies').hover(function () {
      //$('#currencies-table').slideDown('fast', function() { $(this).stop(); } );
      $('#currencies-table').show();
    }, function () {
      //$('#currencies-table').slideUp('fast');
      $('#currencies-table').hide();
    });
    
    $('.article-teaser .slider-wrapper').css({
      /*height: 100,*/ 
      position: 'relative'
    });

    if (($.support.opacity && !$.browser.opera) || ($.browser.opera && parseInt($.browser.version, 10) > 9)) {
      $('.article-teaser .slider').css({
        background: 'rgba(64,64,64,0.75)' 
      }); 
    }
    else {
      $('.article-teaser .slider').css({
        background: '#888'
      }); 
    }

    $('.article-teaser .slider').css({
      display: 'block',
      clear: 'both', 
      overflow: 'hidden', 
      position: 'absolute', 
      height: 0, 
      bottom: 0, 
      padding: '0 10px'
    });

    $('.article-teaser a.slider').css({
      color: '#FFF'
    });
        
    $('.article-teaser').hover(function () {
      $(this).find('a.slider').stop();
      $(this).find('a.slider').animate({height: $(this).find('.slider-wrapper').height() - 16, 'padding-top': 8, 'padding-bottom': 8}, 300);
    }, function () {
      $(this).find('a.slider').stop();
      $(this).find('a.slider').animate({height: 0, 'padding-top': 0, 'padding-bottom': 0}, 300);
    });

    $('#menu-secondary').height('100%');
    if ($.browser.msie) {
      $('#menu-secondary').css({'min-height': 80});
    }

    //alert($('#menu-secondary').height());
    
    /*$('form#comment-form').toggle(function () {
      $(this).slideDown();
    }, function () {
      $(this).slideUp();
    });
    
    $('#comments h2.comment-form').click(function () {
      $('form#comment-form').toggle('slow');
    });*/
  }
}

})(jQuery);
;

