jQuery.noConflict();
jQuery(document)
    .ready(
        function() {

          /* FANCYBOX */

          jQuery("a.single_image").fancybox({
            'overlayOpacity' : 0.7,
            'padding' : 0,
            'overlayColor' : '#626B71'
          });

          /*
           * Call Iframe with dynamic width/height
           *
           * <a class="fbDynamic"
           * href="http://link.com/?width=400&height=300">
           */
          if (jQuery('a.fbDynamic').length) {

            var dWidth = '';
            var dHeight = '';

            jQuery('a.fbDynamic').each(
                function() {
                  dWidth = parseInt(jQuery(this).attr('href')
                      .match(/width=[0-9]+/i)[0].replace(
                      'width=', ''));
                  dHeight = parseInt(jQuery(this)
                      .attr('href').match(
                          /height=[0-9]+/i)[0]
                      .replace('height=', ''));

                  jQuery(this).fancybox({
                    'width' : dWidth,
                    'height' : dHeight,
                    'hideOnContentClick' : false,
                    'overlayOpacity' : 0.7,
                    'padding' : 0,
                    'overlayColor' : '#626B71',
                    'autoScale' : false,
                    'transitionIn' : 'elastic',
                    'transitionOut' : 'elastic',
                    'type' : 'iframe',
                    'scrolling' : 'no'
                  });
                });

          }
          ;

          // Product Comparision Popup
          jQuery("a.fbIframe").fancybox({
            'hideOnContentClick' : false,
            'overlayOpacity' : 0.7,
            'padding' : 0,
            'overlayColor' : '#626B71',
            'type' : 'iframe',
            'height' : 580,
            'width' : 850,
            'scrolling' : 'no'
          });

          // Product Finder Popup
          jQuery("a.fbIframe2").fancybox({
            'hideOnContentClick' : false,
            'overlayOpacity' : 0.7,
            'padding' : 0,
            'overlayColor' : '#626B71',
            'type' : 'iframe',
            'height' : 420,
            'width' : 850,
            'scrolling' : 'no'
          });

          // History Timeline Popup
          jQuery("a.fbIframe3").fancybox({
            'hideOnContentClick' : false,
            'overlayOpacity' : 0.7,
            'padding' : 0,
            'overlayColor' : '#626B71',
            'type' : 'iframe',
            'height' : 535,
            'width' : 850,
            'scrolling' : 'no'
          });

          // Inline Popups (ImageGallery, Infobox, Video)
          jQuery("a.fbInline").fancybox({
            'hideOnContentClick' : false,
            'overlayOpacity' : 0.7,
            'padding' : 10,
            'overlayColor' : '#626B71'

          });

          jQuery("a.fbVideo").fancybox({
            'hideOnContentClick' : false,
            'overlayOpacity' : 0.7,
            'padding' : 10,
            'overlayColor' : '#626B71',
            'onStart' : function() {
              player();
            },
            'onClosed' : function() {
              jQuery('object').remove();
            }
          });

          /* Search Box Filter */
          var clickedFilter = false;
          jQuery('#currentSearchFilter').click(function() {
            if (clickedFilter == false) {
              jQuery('#searchFilterList').show();
              clickedFilter = true;
            } else {
              jQuery('#searchFilterList').hide();
              clickedFilter = false;
            }
          })

          jQuery('#searchFilterList a').click(function() {

              var selection = jQuery(this).text();
              var selectionHidden = jQuery(this).attr('id');

            jQuery('#currentSearchFilter').text(selection);
            jQuery('#searchFilterHidden').attr('value',selectionHidden);
            jQuery('#searchFilterList').hide();
            clickedFilter = false;
          })

          /* Search Box Language Selection */
          var clickedLanguage = false;
          jQuery('#currentLanguage').click(function() {
            if (clickedLanguage == false) {
              jQuery('#languageList').show();
              clickedLanguage = true;
            } else {
              jQuery('#languageList').hide();
              clickedLanguage = false;

            }
          })

          jQuery('#languageList a').click(function() {
            var selection = jQuery(this).html();
            jQuery('#currentLanguage').html(selection);
            jQuery('#languageList').hide();
            clickedLanguage = false;
          })

          // if code supported, link in the style sheet and call the
          // init function onload
          if (dw_scrollObj.isSupported()) {
            dw_Event.add(window, 'load', init_dw_Scroll);
          }

          /* Table row Hovereffect */
          if (jQuery('#hoverTable').length) {

            jQuery('.gc_content_oddRowColor').hover(
                function() {
                  jQuery(this).removeClass(
                      'gc_content_oddRowColor');
                  jQuery(this).addClass(
                      'gc_content_hoverRowColor');
                },
                function() {
                  jQuery(this).removeClass(
                      'gc_content_hoverRowColor');
                  jQuery(this).addClass(
                      'gc_content_oddRowColor');
                });

            jQuery('.gc_content_evenRowColor').hover(
                function() {
                  jQuery(this).removeClass(
                      'gc_content_evenRowColor');
                  jQuery(this).addClass(
                      'gc_content_hoverRowColor');
                },
                function() {
                  jQuery(this).removeClass(
                      'gc_content_hoverRowColor');
                  jQuery(this).addClass(
                      'gc_content_evenRowColor');
                });
          }
          ;

          /* Table Typenauswahl Dynamic Layout change */
          if (jQuery('.gc_content_typeSelectionTable').length) {

            /*
             * Nach Klick auf Tabellenzeile weiterleiten auf URL im
             * id Attribute der tr
             */
            jQuery('.gc_content_typeSelectionTable tbody tr td')
                .click(
                    function() {

                        var id = jQuery(this).parent().attr('id');
                        var idDan = jQuery(this).attr('dan');

                        if (id != 'top' && idDan != 'compareId') {
                            window.location.href = id;
                        } if (idDan == 'compareId') {
                            return true;
                        } if (id == 'top') {
                            window.scrollTo (0,0);
                        }
                      return false;
                    });

            // Change select background color after change, if not
            // default
            var defaultValue = 0;
            jQuery('.gc_content_typeSelectionTable select').each(
                function() {

                  name = this.name;

                  defaultValue = jQuery(this).find('option')
                      .index(
                          jQuery("option:selected",
                              this));

                  if (defaultValue != 0) {
                    jQuery(this).css('background',
                        '#ffffff');
                  } else {
                    jQuery(this).css('background',
                        '#DCE3ED');
                  }

                  if ('currency' == name) {
                      jQuery(this).css('background',
                      '#ffffff');
                  }

                });

            jQuery('.gc_content_typeSelectionTable select').change(
                function() {
                  defaultValue = jQuery(this).find('option')
                      .index(
                          jQuery("option:selected",
                              this));

                  if (defaultValue != 0) {
                    jQuery(this).css('background',
                        '#ffffff');
                  } else {
                    jQuery(this).css('background',
                        '#DCE3ED');
                  }
                  ;

                });
          }
          ;

          /* JQUERY UI TABS */
          // Home Tabs with Teaser
          if (jQuery('#teaserTabs').length) {
            jQuery(function() {
              jQuery("#teaserTabs").tabs();
              jQuery("#teaserTabs").show();
            });
          }
          ;

          // Tabs with Paging Function (ui.tabs.paging.js) for Product
          // Tables
          if (jQuery('.productTabs').length) {
            jQuery(function() {

              jQuery(".productTabs").tabs();
              jQuery(".productTabs").show();

              jQuery(".productTabs").tabs('paging', {
                nextButton : '',
                prevButton : '',
                follow : true
              });
            });
          }
          ;

          // Common Tabs Full Content width
          if (jQuery('.contentTabs').length) {
            jQuery(function() {
              jQuery(".contentTabs").tabs();
            });
          }
          ;

          // Smaller Tabsnavigation Full Content width
          if (jQuery('.contentTabsSmall').length) {
            jQuery(function() {
              jQuery(".contentTabsSmall").tabs();
            });
          }
          ;


          /* jQuery UI ACCORDION for catalogues */
          if (jQuery('.accordionCatalogues').length) {
            jQuery(".accordionCatalogues").accordion({
              autoHeight : false,
              collapsible : true,
              active : false
            });
          }



          /* jQuery UI ACCORDION */
          if (jQuery('.accordion').length) {
            jQuery(".accordion").accordion({
              autoHeight : false,
              collapsible : true,
              active : false
            });
          }

          /* Manual Accordion function over select form */
          if (jQuery('.accordionForm').length) {

            jQuery(".accordionForm").accordion({
              autoHeight : false,
              collapsible : true,
              active : false,
              disabled : true
            });

            /*
             * Open Accordion pane after choose item from select
             * form and change CSS styles
             */
            var prevSlide = '';
            jQuery(".accordionForm select").change(
                function() {

                  currentSlide = jQuery(this).parent()
                      .parent();

                  // Close previous slide
                  if (!jQuery(currentSlide).hasClass(
                      'ui-state-active')) {
                    if (prevSlide != '') {
                      jQuery(prevSlide).next().slideUp();
                      jQuery(prevSlide).removeClass(
                          'ui-state-active');
                      jQuery(prevSlide).removeClass(
                          'open')
                    }
                  }

                  jQuery(this).parent().parent().next()
                      .slideDown();
                  jQuery(this).parent().parent().addClass(
                      'ui-state-active');
                  prevSlide = currentSlide;

                });

            // Close active slide
            jQuery(".accordionForm a").click(
                function() {
                  jQuery(this).parent().next().css('display',
                      'none');
                  jQuery(this).parent().removeClass(
                      'ui-state-active');
                  open = false;
                });

          }
          ;

          /*
           * Image Gallery change Pics and Subtitle after click on
           * thumbnails
           */

          if (jQuery('.gc_content_gallery').length) {

            // Call Init Function
            jQuery('a.fbInline').click(function() {
              var thisId = jQuery(this).attr('href');
              initGallery(thisId);
            });

            function initGallery(gallery) {
              /* show first thumbnail as zoom image */
              var initImage = jQuery(gallery).find(
                  '.gc_content_galleryThumb:first a').attr(
                  'href');
              var initDescription = jQuery(gallery).find(
                  '.gc_content_galleryThumb:first span')
                  .text();

              jQuery(gallery).find('.gc_content_galleryZoom img')
                  .attr('src', initImage);
              jQuery(gallery)
                  .find('.gc_content_galleryZoom span').html(
                      initDescription);

              /* show first thumbnail as active with border */
              jQuery(gallery).find(
                  '.gc_content_galleryThumb:first').css(
                  'border', '2px solid #b6d742');
              jQuery(gallery).find(
                  '.gc_content_galleryThumb:first').css(
                  'padding', '5px');

            }
            ;

            // ImageSwap Gallery
            jQuery('.gc_content_galleryThumb a')
                .click(
                    function() {
                      var imageDescription = jQuery(
                          'span', this).text();
                      var imagePath = jQuery(this).attr(
                          'href');

                      jQuery('.gc_content_galleryThumb')
                          .css('border',
                              '1px solid #999999');
                      jQuery('.gc_content_galleryThumb')
                          .css('padding', '6px');

                      jQuery(this).parent().css('border',
                          '2px solid #b6d742');
                      jQuery(this).parent().css(
                          'padding', '5px');
                      jQuery(
                          '.gc_content_galleryZoom img')
                          .attr('src', imagePath);
                      jQuery(
                          '.gc_content_galleryZoom span')
                          .html(imageDescription);

                      return false;

                    });
          }
          ;

          /* NAVIGATION mit hoverIntent.js */

          function show() {
            jQuery(this).addClass("sfhover");
          }

          function hide() {
            jQuery(this).removeClass("sfhover");
          }

          function showPopup() {
            jQuery(this).addClass("popupSfhover");
          }

          function hidePopup() {
            jQuery(this).removeClass("popupSfhover");
          }

          /*
           * Main-Navi
           */
          jQuery("#gc_naviMain_Ul > li.gc_naviMain_firstLine")
              .hoverIntent({
                sensitivity : 1, // number = sensitivity
                          // threshold (must be 1 or
                          // higher)
                interval : 100, // number = milliseconds for
                        // onMouseOver polling interval
                over : show, // function = onMouseOver
                        // callback (required)
                timeout : 100, // number = milliseconds delay
                        // before onMouseOut
                out : hide
              // function = onMouseOut callback (required)
              });

          /*
           * Produkt-Navigation
           */

          jQuery(
              ".gc_navi_productFlInnerOne > div.gc_navi_productFlInnerTwo")
              .hoverIntent({
                sensitivity : 1, // number = sensitivity
                          // threshold (must be 1 or
                          // higher)
                interval : 200, // number = milliseconds for
                        // onMouseOver polling interval
                over : showPopup, // function = onMouseOver
                          // callback (required)
                timeout : 350, // number = milliseconds delay
                        // before onMouseOut
                out : hidePopup
              // function = onMouseOut callback (required)
              });

          jQuery("#gc_navi_product > li.gc_navi_productFirstLine")
              .hoverIntent({
                sensitivity : 1, // number = sensitivity
                          // threshold (must be 1 or
                          // higher)
                interval : 0, // number = milliseconds for
                        // onMouseOver polling interval
                over : show, // function = onMouseOver
                        // callback (required)
                timeout : 300, // number = milliseconds delay
                        // before onMouseOut
                out : hide
              // function = onMouseOut callback (required)
              });
        });
