$(document).ready(function() {

    if ($.browser.msie && $.browser.version.substr(0,1)<=7) {
        var zIndexNumber = 1000;
        $('div').each(function() {
            $(this).css('zIndex', zIndexNumber);
            zIndexNumber -= 10;
        });
    }

    $('#slider_area').cycle({ 
        fx:'scrollLeft',
        easing:'backout', 
        timeout:5000,
        pager:'#numbers'
    });

    $('.newsticker-jcarousellite').jCarouselLite({
        vertical:true,
        visible:11,
        auto:800,
        hoverPause:true,
        speed:500
    });

    $('ul.gallery li a').fancybox();

    //Rearrange menu hack
    $('#nav .cat-item-4').find('li').not('#nav .cat-item-35').remove();
    $('#nav .cat-item-4').insertAfter('#nav .page-item-2');
    $('#nav .cat-item-3').insertAfter('#nav .cat-item-4');
    $('#nav .cat-item-36').insertAfter('#nav .cat-item-38');
    $('#nav .cat-item-1').insertAfter('#nav .page-item-69');
    $('#nav .cat-item-4 .children').prepend('<li><a href="/category/business-opportunities">Latest Business Opportunities<'+'/a><'+'/li>');
    $('#nav .cat-item-39:eq(0)').prependTo('#nav .cat-item-3 ul:eq(0)');
    $('#nav .cat-item-37:eq(0)').insertAfter('#nav .cat-item-39:eq(0)');
    $('#nav .cat-item-44').insertAfter('#nav .cat-item-41');
    $('.cat-item-44 a').attr('href', '/newsletters');
    $('#nav .cat-item-69 a').attr('href', '/newsletters/#tnfi3');

    //Sidebar remove item hack
    if ($('#page_right .box_content_sub h1:contains("Browse by Category")').length && $('.biz_details').length == 0) {
        children_items = $('#page_right .box_content_sub h1:contains("Browse by Category")').parent().find('ul:eq(0)').children();
        if ($('.event_details').length == 1 || $('.box_content_sub .cat-item-37.current-cat-parent').length == 1) {
          children_items.each(function() {
              if (!$(this).hasClass('cat-item-3')) {
                  $(this).hide();
              }
          });
        } else if ($('h1.single').length == 1) {
          children_items.each(function() {
              if (!$(this).hasClass('cat-item-1')) {
                  $(this).hide();
              }
          });
        } else {
          children_items.each(function() {
              if (!$(this).hasClass('current-cat') && !$(this).hasClass('current-cat-parent')) {
                  $(this).hide();
              }
          });
        }
    }

    $("a[href^='http://']").each(function() {
      if (!$(this).attr('href').match('israeltrade.org.au')) {
        $(this).attr('target', '_blank');
      }
    });

    $('.js_hide, .contact_form li.optional').hide();

    $('.contact_form li.optional_click').click(function() {
        $(this).hide();
        $('.contact_form li.optional').fadeIn();
    });

    $('.js_hide').parent().find('strong:eq(0)').css('cursor', 'pointer').click(function() {
      $(this).parent().find('.js_hide').slideToggle();
    });
});
