/**
 * i-printer Javascript
 *
 * @requires jQuery 1.3.2
 * @requires formConflictManager
 * @requires help
 * @requires subForm
 * @requires utils
 * @requires slider
 */


$(document).ready(function(){

    // alle productOptions gleich hoch machen!
    // das muss passieren, bevor irgend etwas über
    // formConflictManager o.ä. ausgeblendet wird
    $('ul.scrollproducts').equalHeights('li');
    $('div.productConfig').equalHeights('div.productOptions');
    $('div.cart>div.item>div').equalHeights();

    Buttons.init();
    subForm.init();
    formConflictManager.init();

    // jedes fünfte Element auf der Startseite hat keinen rechten rand und keinen strich
    $('.productSelection ul.products li:nth-child(5n)').css({'padding-right': '0px', 'background-image': 'none'});
    
    // die letzte Linie in der Produktkonfiguration weglassen
    $('div.productOptions:last-child').css('background-image','none');


    $('a#loginSubmit').bind("click", function() {
        $('form#login').submit();
        return false;
    });

    $('div.offer select').bind('change', function() {
        $(this).parent().find('.price').html( $(this.options[this.selectedIndex]).attr("price") );
    });


    FormExtras.init();
    PriceCalc.init();

    
    // hover-rahmen einbauen
   // $('.productSelection ul.products li, .productSelection  ul.scrollproducts li').prepend('<span class="hover-display"></span>');

    $('.productSelection ul.products > li').hover(
      function() {
        $(this).find('span.hover-display, a.button-continue, div.info').css('display', 'block')
               .end().find('a.name').css({'background-position':'left bottom'});
      },
      function() {
        $(this).find('span.hover-display, a.button-continue, div.info').hide()
               .end().find('a.name').css({'background-position':'left top'});
        var bubble = $(this).find('div.info').data('helpBubble');
        if(bubble != false) {
          $(bubble).removeBubble();
        }
      }
    );
    $('.productSelection ul.scrollproducts > li').hover(
      function() {
        $(this).find('a.button-continue, div.info').css({'display':'block'})
               .end().find('a.name').css({'background-position':'left bottom'})
               .end().css({'background-color':'#D0D0D0'});
      },
      function() {
        $(this).find('a.button-continue, div.info').hide()
               .end().find('a.name').css({'background-position':'left top'})
               .end().css({'background-color':'transparent'});
        var bubble = $(this).find('div.info').data('helpBubble');
        if(bubble != false) {
          $(bubble).removeBubble();
        }
      }
    );    

    //pricecalc nach laden sofort ausfuehren
    $("#configForm").trigger("change");

    //letzten rand/rahmen entfernen bei verschieden listen
     $('div.productConfig').find('div.productOptions:last-child').css({'border':'none'});
     $('div.productConfig .optioncopies').find('div.copyOptionsV:last-child').css({'border':'none'});
     $('#mainNav ul.menu').find('li:last-child').css({'border-right':'none'});
     $('div.cart').find('div.item:last-child').css({'border-bottom':'none'});
    //floats am ende der bloecke beenden (oft sind da die buttons)
    //$('div.block, div.productConfig, div.optionBlock').append('<br style="clear:both"/>'); 
    
    // Workaround für IE select/option-Bug
    if($.browser.msie && $.browser.version<8) IEfix.init();
    // Für den IE:
    // -------------------------------------------------
    if($.browser.msie) {
      // runde ecken an die hover-flächen
      $('.productSelection ul.products > li > span.hover-display').append('<span class="focus-tl"></span><span class="focus-tr"></span><span class="focus-bl"></span><span class="focus-br"></span>');
      
      if ($.browser.version<8)  {
        //buttons span laenge ueber inhalt bestimmen
        $('a.button-left, a.button-right, a.button, a.button-continue, a.button-previous').each(function(){
          if ($(this).css('min-width').indexOf('px') !=-1) {
            $(this).width(parseInt($(this).css('min-width')));
            $(this).find('span').width(parseInt($(this).css('min-width'))-9);
          }
          else {
            var text = $(this).text();
            $('body').append('<a class="button" id="span"><span style="display: inline">' + text + '</span></a>');
            var breite = $('a#span span').width();
            $('a#span').remove();
            $(this).width(breite + 9);
          };
          $(this).find('span img').css({'margin-top':'0px'});
        });
        $('div.block, div.productConfig, div.optionBlock, div.item').append('<span style="clear:both"/>');
      }
      
    }

});





