function strrev(str){
  return str.split("").reverse().join("");
}

jQuery(document).ready(function(){
	
	jQuery('ul.nav>li>ul').hide();	
	jQuery("ul.nav > li").hover(
		function () {
			jQuery(this).find('ul:hidden').slideDown("fast");
		}, 
		function () {
			jQuery(this).find('ul:visible').slideUp("fast");
		}
	);
	
	/* if product subnav is visible, add the toggled class, we'll need it below to make sure a mouseover on the parent doesn't hide an already visible sub-menu */
	jQuery('ul#products-nav>li>div').hide();
  if(jQuery('ul#products-nav a.trigger').length) {
    jQuery('ul#products-nav a.trigger').hoverIntent({
      sensitivity:3,
      interval:200,
      out:function(){},
      over:function(){
             if(!jQuery(this).hasClass('toggled')) {
               jQuery(this).parent().parent().find('div:visible').animate({width: 'hide', opacity: 'hide'}, 800);
               jQuery('a.trigger').removeClass('toggled');
             }
             jQuery(this).parent().find('div:hidden').animate({width: 'show', opacity: 'show'}, 800);
             jQuery(this).addClass('toggled');
      }
    });
  }

	jQuery("#specs").accordion({
		autoheight: false,
		header: '.trigger'
	});
	
	jQuery(".toggle-bar").click(function(){
		var $my_wrapper = jQuery(this);
		var $my_toggleobj = $my_wrapper.find("div.toggle-info")
		var $my_togglelink = $my_wrapper.find(".toggler");
		if(!$my_toggleobj[0]){
			$my_toggleobj = $my_wrapper.next("div.toggle-info")
		}
		if($my_togglelink.hasClass("toggled")){
			$my_togglelink.removeClass("toggled").attr("title", "Open");
			$my_togglelink.html("[ open ]");
			$my_toggleobj.slideToggle("fast");
		}else{
			$my_togglelink.addClass("toggled").attr("title", "Close");
			$my_togglelink.html("[ close ]");
			$my_toggleobj.slideToggle("fast");
		}
		return false;
	});
	
	jQuery(".toggler-close").click(function(){
		var $close_wrapper = jQuery(this).parent();
		$close_wrapper.slideToggle("fast")
    	jQuery(this).parents("div:first").prev().find("a.toggler").removeClass("toggled").attr("title", "Open").html("[ open ]");
		return false;
	});
	
	/* MWJ 2009-05-20: added #contact-nav-intl case for internationalised sites, which use overlaid HTML text rather than bg images in nav */
	jQuery("#contact-nav .one, #contact-nav-intl .one").click(function () {
      jQuery(".contact-viewport").animate({left:0},400);
      jQuery("#contact-nav a, #contact-nav-intl a").removeClass('active');
      jQuery(this).addClass('active');
    });
    
    jQuery("#contact-nav .two, #contact-nav-intl .two").click(function () {
      jQuery(".contact-viewport").animate({left:-671},400);
      jQuery("#contact-nav a, #contact-nav-intl a").removeClass('active');
      jQuery(this).addClass('active');
    });
    
    jQuery("#contact-nav .three, #contact-nav-intl .three").click(function () {
      jQuery(".contact-viewport").animate({left:-1342},400);
      jQuery("#contact-nav a, #contact-nav-intl a").removeClass('active');
      jQuery(this).addClass('active');
    });

/*
home rebuild - JGD
*/
	jQuery("#home-btn-opticswap").attr("href","#"); 
	jQuery("#home-btn-composer").attr("href","#"); 

	jQuery("#home-btn-opticswap").click(function () {
      jQuery(".home-viewport").animate({left:-935},400);
    });
	jQuery("#home-btn-composer").click(function () {
      jQuery(".home-viewport").animate({left:0},400);
    });
    
/*
/ home rebuild - JGD
*/
	jQuery('.lightbox').lightbox({
		fileLoadingImage: '/images/loading.gif',
		fileBottomNavCloseImage: '/images/closelabel.gif'
	});
	
/* mwj */
  /* Flags menu -- half-second delay before closing after mouse-out */
  $.countryflags = {over : false}; 
  $('#international').hover(
      function(){ $.countryflags.over = true;  $('#international #country-flags').slideDown(); },
      function(){ 
        $.countryflags.over = false; 
        setTimeout(function() { if(!$.countryflags.over) $('#international #country-flags').slideUp(); }, 500);
      } 
  );


  $('.obfuscated-address,.obfuscated-email').each(function(i,e) { 
    var e = $(e)
    e.text( strrev(e.text())); 
    e.attr('href', strrev(e.attr('href'))); 
  })
/* /mwj */
});
