/*
$Id: fixes.js,v 1.1 2008/11/18 11:23:32 max Exp $
vim: set ts=2 sw=2 sts=2 et:
*/

/*
  Position:absolute elements will not move when window is resized if a sibling contains float elements and a clear:both element
  https://bugzilla.mozilla.org/show_bug.cgi?id=442542
  FireFox 3.0+
*/
if (navigator.userAgent.toLowerCase().search(/firefox\/(3\.\d+)/i) != -1 && typeof(window.$) != 'undefined') {
  $.event.add(
    window,
    'resize',
    function() {
      var h = document.getElementById('header');
      if (!h || $(h).css('position') != 'absolute')
        return;

      document.getElementById('header').style.position = 'static';
      setTimeout(
        function() {
          document.getElementById('header').style.position = 'absolute';
        },
      20);
    }
  );
}

/*
  - The last item of the horizontal drop drown menu expands beyond the page's right side boundary
  All browsers
  
  - li:hover pseudo-class doesn't work
  IE 6
*/
$(document).ready(
  function(){

    var max_offset_x = $("#content-container").offset().left + $("#content-container").width();

    $("#main-navigation > div > div > ul > li").hover(
      function(){
        if ($.browser.msie)
          this.className += " over";

        if ($(this).children("ul").offset()){
          var el_offset_x = $(this).children("ul").offset().left + $(this).children("ul").outerWidth();
          if (el_offset_x > max_offset_x)
            $(this).children("ul").css("left","-"+(el_offset_x - max_offset_x)+"px");
        }
      },
      function(){
        if ($.browser.msie)
          this.className = this.className.replace(/ over/, "");
      }
    );

  }
);

/*
  Create tabs with the product details page sections
*/
$(document).ready(
  function(){

    var tabsList = '<ul id="ptabs">';

    $("#center-main .dialog.ptab").each(function (i) {
      tabsList += '<li rel="ptab'+ i +'"><span><span>' + $(this).find(".title h2").text() + '</span></span></li>';

      $(this).attr("id", "ptab" + i)
        .find(".title").hide().end()
        .hide();
    });

    $("#center-main .dialog.ptab:first").show();

	tabsList += '</ul>';
    $("#center-main .dialog.ptab:first").before(tabsList);
    $("#ptabs li:first").addClass('selected');

	$(function(){
		$('#ptabs li').click(function(){
			$(this)
				.addClass('selected')
				.siblings().removeClass('selected');
			$("#center-main .dialog.ptab").hide();
			$("#"+$(this).attr("rel")).show();
		});
	});

  }
);

