var $j = jQuery.noConflict();
$j(document).ready(function() {

  /*$j(window).resize(function(){
    alert(1);
  });      */

  // Dirty dirty hack
  if($j.browser.mozilla == true)
  {
    if($j(window).width() % 2 != 0)
    {
      $j('.products_title').css({left: '-35px'});
      $j('#slider').css({ left: '-51px'});  
    }
    
    $j(window).bind('resize', function() {
      if($j(window).width() % 2 != 0)
      {
        $j('.products_title').css({left: '-35px'});
        $j('#slider').css({ left: '-51px'}); 
      }
      else
      {
        $j('.products_title').css({left: '-36px'});
        $j('#slider').css({ left: '-52px'}); 
      }
    });  
  }
  // Dirty dirty hack
  if($j.browser.webkit == true)
  {
    if($j(window).width() % 2 == 0)
    {
      $j('.products_title').css({left: '-35px'});
      $j('#slider').css({ left: '-51px'});  
    }
    
    $j(window).bind('resize', function() {
      if($j(window).width() % 2 == 0)
      {
        $j('.products_title').css({left: '-35px'});
        $j('#slider').css({ left: '-51px'}); 
      }
      else
      {
        $j('.products_title').css({left: '-36px'});
        $j('#slider').css({ left: '-52px'}); 
      }
    });  
  }

  // Add class to the last li in the list
  $j('.qtrans_language_chooser li:last').addClass('last');
  $j('.header_menu li:last').addClass('last');
  
  if($j('#slider_wrapper').length)
  {
  $j('#slider').cycle({ 
    fx:     'fade', 
    speed:  '1500', 
    timeout: 5000, 
    pager:  '#slider_navigation',
    pagerAnchorBuilder: function(idx, slide) { 
        return '<a href="#"><!-- --></a>'; 
    }
  });
  }
  
  // Image hover
  $j('#subproduct_right img.alignleft').each(function() {
    if($j(this).hasClass('default')) { }
    else {
      $j(this).parent().addClass('wp_image_wrapper');
      $j(this).parent('.wp_image_wrapper').prepend('<span class="wp_image_inner"></span>');
    }
  });    
  
  $j('.wp_image_inner').animate({'opacity': '0'});
  
  $j('.wp_image_wrapper').hover(function() {
    $j(this).find('.wp_image_inner').stop().animate({'opacity': '1'}, 'slow');
  }, function() {
    $j(this).find('.wp_image_inner').stop().animate({'opacity': '0'}, 'slow');
  });
  
  $j('.header_menu li a').hover(function() {
  if($j(this).parent().hasClass('current_page_item') || $j(this).parent().hasClass('current-page-ancestor')) {  }
  else 
    $j(this).stop().animate({ top: '-6px' }, 250);
    }, function() {
      $j(this).stop().animate({ top: 0}, 250);    
  });
   
   
  var window_height = $j(document).height();
  var body_height = $j('body').height();
  
  /**
   * Javascript for minimal container height - there is no possibility to do it without js I think
   * 390 = 184 (header) + 52 (footer) + 44 (footer to the content) + 72 (header to content) + 38 (top padding)   
   */   
  if(body_height == window_height)
  {
    var container_height = body_height - 390; 
    $j('.products').css({height: container_height });
  }
  
  // Destroy last border - also in the css, but with :last-child
  $j('#subproduct_right_ratings p:last').css({ border: 'none'});
  $j('.pricelist ul li:last').css({ border: 'none' });


  if($j('.faq').length)
  {
  
    $j('input#id_search').quicksearch('.faq .faq_row', {
      noResults: '.no_results'
    });
    // Create submenu
    $j('.current_page_item').append('<ul></ul>');
    
    // Create submenu elements  
    $j('.faq h3').each(function() {
      var id = $j(this).attr('id');
      var title = $j(this).html();
      
      $j('.current_page_item ul').append('<li class="left_child_li"><a href="#'+ id +'" title="'+ title +'">'+ title +'</a></li>');
      
    });  
  }
  
  if($j('.partners').length)
  {
    // Create submenu
    $j('.current_page_item').append('<ul></ul>');
    
    // Create submenu elements  
    $j('.partners h3.partners_title').each(function() {
      var id = $j(this).attr('id');
      var title = $j(this).html();
      
      $j('.current_page_item ul').append('<li class="left_child_li"><a href="#'+ id +'" title="'+ title +'">'+ title +'</a></li>');
      
    });  
  }
  
  if($j('.form_title').length)
  {
    // Create submenu
    $j('.current_page_item').append('<ul></ul>');
    
    // Create submenu elements  
    $j('h3.form_title').each(function() {
      var id = $j(this).attr('id');
      var title = $j(this).html();
      
      $j('.current_page_item ul').append('<li class="left_child_li"><a href="#'+ id +'" title="'+ title +'">'+ title +'</a></li>');
      
    });  
  }
  
  // Bubble open
  $j('.bubble_popup').click(function() {

    $j('.bubble').hide();  
    $j(this).parent().find('.bubble').show();
    
    return false;
    
  });

  // Bubble close  
  $j('.bubble_close').click(function() {
  
    $j(this).parent().parent().hide();
    
    return false;
    
  });
   
});
