/**
 * Identifier for JS enabled CSS
 */
$(function() {
  $("body").addClass('jsEnabled');
});

/**
 * Rounded Images Fix for Mizilla Firefox as jQuery Plugin
 */
jQuery.fn.mozRoundedImages = function() {
  if ($.browser.mozilla) {
    return this.each(function() {
      var elem = $(this);
      var hasBorderRadius = elem.css('-moz-border-radius') != '' && elem.css('-moz-border-radius') != '0px';
      hasBorderRadius = hasBorderRadius ? true : elem.css('-moz-border-radius-topleft') != '' && elem.css('-moz-border-radius-topleft') != '0px';
      hasBorderRadius = hasBorderRadius ? true : elem.css('-moz-border-radius-topright') != '' && elem.css('-moz-border-radius-topright') != '0px';
      hasBorderRadius = hasBorderRadius ? true : elem.css('-moz-border-radius-bottomleft') != '' && elem.css('-moz-border-radius-bottomleft') != '0px';
      hasBorderRadius = hasBorderRadius ? true : elem.css('-moz-border-radius-bottomright') != '' && elem.css('-moz-border-radius-bottomright') != '0px';
      if(hasBorderRadius) {
        var width = elem.width();
        var height = elem.height();
        var src = elem.attr('src');
        elem
          .attr('src', '/html/css/img/spacer.gif')
          .attr('width', width)
          .attr('height', height)
          .css('background-image','url('+src+')');
      }
    });
  }
  return this;
}

$(function() {
  $('.teaserBox:first img, .teaserBox:last img, .teaserBoxHorizontal img').mozRoundedImages();
})

/**
 * FAQ
 */
$(function() {
  if (typeof jQuery.fn.accordion == 'function') {
      $(".faq").accordion({
          autoHeight: false,
          change: function(event, ui) {
              if (typeof ET_Event !== 'undefined') {
                  ET_Event.click('FAQ: ' + ui.newHeader.text());
              }
          }
      });
  }
});

/**
 * Accordion for Sidebar
 */
$(function() {
  if (typeof jQuery.fn.accordion == 'function') {
      $(".accordion").accordion({autoHeight: false});
  }
});

/**
 * Chore Text
 */
$(function() {
    $('.choreText.hidden').each(function() {
        var elem = $(this);
        var link = $('<a class="choreLink hidden" href="#"></a>')
            .text('Pflichttexte anzeigen')
            .click(function() {
                if (elem.hasClass('hidden')) {
                    elem.removeClass('hidden').show();
                    $(this).removeClass('hidden').text('Pflichttexte ausblenden');
                } else {
                    elem.addClass('hidden').hide();
                    $(this).addClass('hidden').text('Pflichttexte anzeigen');
                }
                return false;
            });
        elem.hide().before(link);
    });
})

/**
 * Appliance
 */
$(function() {
    var show = function() {
        if (!$.browser.msie) {
            $(this).fadeIn(350, 'swing');
        } else {
            $(this).show();
        }
    };
    var hide = function() {
        if (!$.browser.msie) {
          $(this).fadeOut(350);
        } else {
            $(this).hide();
        }
    };
    var links = $('dl.appliance')
      .find('dd:not(:first)')
        .hide()
      .end()
      .find('dt')
        .filter(':first')
          .addClass('active')
        .end()
        .click(function() {
          var link = jQuery(this);
          if (link.is(':not(.active)') && typeof ET_Event !== 'undefined') {
            ET_Event.click('Anwendungsgebiete: ' + link.text());
          }
          link.not('.active')
          .addClass('active')
          .siblings('dt')
            .removeClass('active')
          .end()
          .siblings('dd:visible')
            .each(hide)
          .end()
          .next('dd')
            .each(show);
      });
      if (location.hash != '') {
          links.filter('.'+location.hash.slice(1)).click();
      };
});

/**
 * Package Sizes
 */
$(function() {
  if (!$.browser.msie) {
      $('#content .package').each(function(index, elem) {
          var set = $(this).find('.glow')
                        .add($('.packageSizes li:eq(' + index + ')'));
          if (!$.browser.msie) {
              set.css({
                  'display': 'block',
                  'opacity': 0
              });
          }
          $(this).hover(function() {
              set.stop().animate({opacity: 1});
          }, function() {
              set.stop().animate({opacity: 0});
          });
      });
  }
});

/**
 * Effect Stage Player
 */
$(function() {
  if(typeof flowplayer !== 'undefined' && $('BODY').hasClass('effectStage') && $('.effectPlayerContainer').size() > 0) {
  	var teasers = $('.effectTeaser');
    var links = teasers.find('a');
    var flashembedConf = {
        src: "/html/flash/flowplayer.commercial-3.0.7.swf",
        wmode: 'opaque',
        onFail: function() {
            var container = this.getContainer();
            jQuery(container).html('<p class="noFlash">Sie benötigen eine aktuelle Version des <a href="http://get.adobe.com/de/flashplayer/">Flashplayers</a>.</p>');
        }
    };
    var player = flowplayer("effectPlayerContainer", flashembedConf, {
        clip: {
            url: links.filter(':first').attr('href'),
            onStart: function(clip) {
                if (typeof ET_Event !== 'undefined') {
                    var file = clip.completeUrl.match(/(.*)[\/\\]([^\/\\]+)\.\w+$/);
                    ET_Event.videoStart(file[2]);
                }
            },
            onFinish: function(clip) {
                if (typeof ET_Event !== 'undefined') {
                    var file = clip.completeUrl.match(/(.*)[\/\\]([^\/\\]+)\.\w+$/);
                    ET_Event.videoStop(file[2]);
                }
            }
        },
        plugins: { controls: null },
		key: '#@3799af1ca4270f44787' 
    });
    links.click(function(){
        player.play($(this).attr("href"));
        return false;
    });
	if (location.hash != '') {
		var className = 'effectTeaser' + location.hash.charAt(1).toUpperCase() + location.hash.slice(2);
		var curClip = teasers.filter('.'+className).find('a').click();
	};
  }
});
