/*
////////////////////////////////////////////////////////////////
//
// Allgemeine JavaScript Funktionen
//
// Weblication CMS Strukturdesign Version 5.1.0.0
// erstellt durch Scholl Communications AG, 77694 Kehl, www.scholl.de
// erstellt mit Weblication Content Management Server, www.weblication.de
//
////////////////////////////////////////////////////////////////
*/

////////////////////////////////////////////////////////////////
//
// @method void wOpenURL(url)
//
// @desc Öffnet eine Seite
//
// @return void
//
////////////////////////////////////////////////////////////////

function wOpenURL(url){
  if(location.pathname.indexOf('/weblication/grid5/') != 0){
    top.location.href = url;
  }
}

////////////////////////////////////////////////////////////////
//
// @method void wOpenPopupURL(url, width, height, name)
//
// @desc Öffnet eine Seite in einem Popup
//
// @return void
//
////////////////////////////////////////////////////////////////

function wOpenPopupURL(url, width, height, name){

  var name = name || '';

  if(width == '' || width == ' ' || typeof(width) == 'undefined'){
    width = 786;
  }
  if(height == '' || height == ' ' || typeof(height) == 'undefined'){
    height = 677;
  }

  url = url.replace(/&amp;/g, '&');
  options = ',location=no, menubar=no,toolbar=no,resizable=no,scrollbars=yes,status=no';
  width   = parseInt(width);
  height  = parseInt(height);

  var posLeft = (screen.width / 2)  - (width  / 2);
  var posTop  = (screen.height / 2) - (height / 2);
  //alert(name);
  window.open(url, name, 'top='+posTop+',left='+posLeft+',width='+width+',height='+height+',' + options);
}

////////////////////////////////////////////////////////////////
//
// @method void wSendMailNospam(data)
//
// @desc Öffnet eine E-Mail zum Versenden
//
// @return void
//
////////////////////////////////////////////////////////////////

function wSendMailNospam(data){
  location.href = 'mailto:' + data.replace('|', '@');
}

////////////////////////////////////////////////////////////////
//
// @method void wEmbedNavpoint(id, url, mode)
//
// @desc Öffnet einen eingebetteten Navigationspunkt
//
// @return void
//
////////////////////////////////////////////////////////////////

function wEmbedNavpoint(id, url, mode){

  if(typeof wEditor == 'object'){
    return false;
  }

  if($('#navpoint_' + id).data('hasLoaded') == '1'){
    $('#navEmbed_' + id).show();
  }
  else{
    if(mode == 'embed'){
      url = url.indexOf('?') == -1 ? url + '?viewmode=embed' : url + '&viewmode=embed';
      url = url.replace('[URL]', location.pathname + location.search);
      $.ajax({
        type: "GET",
        url: url,
        success: function(result){

          result = result.replace(/\n/g, '_wNL-').replace(/\s+id="[^"]+"/gim, '').replace(/_wNL-/g, "\n");

          $('#navpoint_' + id).data('hasLoaded', '1');
          $('#navEmbed_' + id).html(result);

          var navpointLeft = $('#navpoint_' + id).offset().left;

          $('#navEmbed_' + id).show();

          var layerLeft = $('#navEmbed_' + id).offset().left;

          var blockMainRight = $('#blockMain').offset().left + $('#blockMain').width();

          if(layerLeft < navpointLeft){
            $('#navEmbed_' + id).css('left', String(navpointLeft - layerLeft - 6) + 'px');
          }

          var layerRight = $('#navEmbed_' + id).offset().left + $('#navEmbed_' + id).width();

          if(layerRight > blockMainRight){
            $('#navEmbed_' + id).css('left', String(parseInt($('#navEmbed_' + id).css('left')) - (layerRight - blockMainRight)) + 'px');
          }

          jQuery('#navpoint_' + id).mouseout(function(){
            $('#navEmbed_' + id).hide();
          });

          jQuery('#navEmbed_' + id).mouseover(function(){
            $('#navEmbed_' + id).show();
          });

          jQuery('#navEmbed_' + id).mouseout(function(){
            $('#navEmbed_' + id).hide();
          });
        }
      });
    }
    else{
      url = url.indexOf('?') == -1 ? url + '?viewmode=blank&parentIframeId=navEmbedIframe_'+id : url + '&viewmode=blank&parentIframeId=navEmbedIframe_'+id;
      url = url.replace('[URL]', location.pathname + location.search);
      $('#navpoint_' + id).data('hasLoaded', '1');

      var iframeEmbed    = document.createElement('iframe');

      iframeEmbed.id          = 'navEmbedIframe_' + id;
      iframeEmbed.className   = 'navLevel1Embed';
      iframeEmbed.frameBorder = '0';
      iframeEmbed.scrolling   = 'no';
      iframeEmbed.src         = url;

      var embedContainer = document.getElementById('navEmbed_' + id);
      embedContainer.appendChild(iframeEmbed);

      var navpointLeft = $('#navpoint_' + id).offset().left;

      $('#navEmbed_' + id).show();

      var layerLeft = $('#navEmbed_' + id).offset().left;

      var blockMainRight = $('#blockMain').offset().left + $('#blockMain').width() - 2;

      if(layerLeft < navpointLeft){
        $('#navEmbed_' + id).css('left', String(navpointLeft - layerLeft - 6) + 'px');
      }

      var layerRight = $('#navEmbed_' + id).offset().left + $('#navEmbed_' + id).width();

      if(layerRight > blockMainRight){
        $('#navEmbed_' + id).css('left', String(parseInt($('#navEmbed_' + id).css('left')) - (layerRight - blockMainRight)) + 'px');
      }

      jQuery('#navpoint_' + id).mouseout(function(){
        $('#navEmbed_' + id).hide();
      });

      jQuery('#navEmbed_' + id).mouseover(function(){
        $('#navEmbed_' + id).show();
      });

      jQuery('#navEmbed_' + id).mouseout(function(){
        $('#navEmbed_' + id).hide();
      });

      //jQuery('.blockContentEmbed').attr('id', 'blockContent');
      //jQuery('.blockContentEmbedInner').attr('id', 'blockContentInner');
    }
  }
}

////////////////////////////////////////////////////////////////
//
// @method void wShowLayerBookmarklet()
//
// @desc Schlägt vor, diese Webseite als App abzulegen
//
// @return void
//
////////////////////////////////////////////////////////////////

function wShowLayerBookmarklet(){

  if(/iPhone|iPod/.test(window.navigator.userAgent)){
    if(window.localStorage){
      if(typeof(window.localStorage['numberBookmarketShown']) == 'undefined' || Number(window.localStorage['numberBookmarketShown']) < 2){
        window.localStorage['numberBookmarketShown'] = String(Number(window.localStorage['numberBookmarketShown'] || 0) + 1);
        var bookmarkletInfo = document.createElement('div');

        bookmarkletInfo.id             = 'wBookmarkletInfo';
        bookmarkletInfo.style.width    = '100%';
        bookmarkletInfo.style.position = 'absolute';
        bookmarkletInfo.style.bottom   = '0';

        var bookmarkletInfoInner = document.createElement('div');
        bookmarkletInfoInner.style.color      = '#ffffff';
        bookmarkletInfoInner.style.border     = 'solid 4px #ffffff';
        bookmarkletInfoInner.style.margin     = '20px';
        bookmarkletInfoInner.style.padding    = '8px';
        bookmarkletInfoInner.style.overflow   = 'hidden';
        bookmarkletInfoInner.style.position   = 'relative';
        bookmarkletInfoInner.style.background = '#cddcf3 -webkit-gradient(linear, left top, left bottom, from(#B5C9D9), to(#6886B0)) no-repeat bottom';
        bookmarkletInfoInner.style.WebkitBorderRadius = '8px';
        bookmarkletInfoInner.style.WebkitBoxShadow    = '0 4px 6px #a0a0a0';

        bookmarkletInfo.appendChild(bookmarkletInfoInner);

        var bookmarkletInfoIcon = document.createElement('img');
        bookmarkletInfoIcon.style.margin = '8px';
        bookmarkletInfoIcon.style.position = 'absolute';

        var linkTags = document.getElementsByTagName('link');
        for(var i = 0; i != linkTags.length; i++){
          if(linkTags[i].getAttribute('rel') == 'apple-touch-icon'){
            bookmarkletInfoIcon.src = linkTags[i].getAttribute('href');
          }
        }

        bookmarkletInfoInner.appendChild(bookmarkletInfoIcon);

        var bookmarkletInfoCloser = document.createElement('img');
        bookmarkletInfoCloser.src = '/weblication/grid5/gui/images/style/bookmarklet_close.png';
        bookmarkletInfoCloser.style.margin = '-4px';
        bookmarkletInfoCloser.style.padding = '2px';
        bookmarkletInfoCloser.style.background = '#ffffff';
        bookmarkletInfoCloser.style.border = 'solid 1px #c0c0c0';
        bookmarkletInfoCloser.style.float  = 'right';

        bookmarkletInfoCloser.onclick = function(){document.getElementById('wBookmarkletInfo').parentNode.removeChild(document.getElementById('wBookmarkletInfo'));window.localStorage['numberBookmarketShown'] = '99'};
        bookmarkletInfoInner.appendChild(bookmarkletInfoCloser);

        var bookmarkletInfoText = document.createElement('div');
        bookmarkletInfoText.style.margin = '8px 8px 8px 100px';
        bookmarkletInfoText.style.position  = 'left';
        bookmarkletInfoText.style.backgroundColor  = 'none';
        bookmarkletInfoText.innerHTML    = 'Klicken Sie unten auf das "+" Zeichen und dann auf "Zum Home-Bildschirm hinzufügen", um diese Seiten als App abzulegen.';

        bookmarkletInfoInner.appendChild(bookmarkletInfoText);

        var bookmarkletArrow = document.createElement('div');
        bookmarkletArrow.style.height             = '23px';
        bookmarkletArrow.style.width              = '100%';
        bookmarkletArrow.style.marginTop          = '-23px';
        bookmarkletArrow.style.position           = 'absolute';
        bookmarkletArrow.style.zIndex             = '10';
        bookmarkletArrow.style.backgroundRepeat   = 'no-repeat';
        bookmarkletArrow.style.backgroundPosition = 'center';
        bookmarkletArrow.style.backgroundImage    = 'url(/weblication/grid5/gui/images/style/arrow_bookmarklet.png)';

        bookmarkletInfo.appendChild(bookmarkletArrow);

        document.body.appendChild(bookmarkletInfo);
      }
      else{
      }
    }
  }
}

jQuery.fn.setViewmode = function(viewmode){

  jQuery.each($(this), function(x){
    var hrefNew = this.getAttribute('href');
    var anchor  = '';
    if(/#[^#]+$/.test(hrefNew)){
      anchor  = hrefNew.replace(/.*#/, '');
      hrefNew = hrefNew.replace(/#.*/, '');
    }

    hrefNew = hrefNew.indexOf('?') != -1 ? hrefNew + '&viewmode=' + viewmode: hrefNew + '?viewmode=' + viewmode;

    if(anchor != ''){
      hrefNew += '#' + anchor;
    }

    this.setAttribute('href', hrefNew);
  });
}

jQuery.fn.addAnalytics = function(viewmode){
  jQuery.each($(this), function(x){
    var href= this.getAttribute('href');
    this.setAttribute('onclick', 'pageTracker._trackPageview(\'' + href + '\');');
  });
}

function showModalLayer(obj) {

  // versuch das div hinter die zugaenge zu haengen um eine korrekte positionierung zu erreichen
  $('#' + obj).after($('#layer_' + obj));

// click zum schließen registrieren, bei click funktion nochmal aufrufen (toggelt dann sowieso)

  var shown = $('#layer_' + obj).css('display');
  if (shown == "none") {$('#layer_' + obj).css('display','block');$('blockMainOuter').bind('click', modalDimmer(obj));} else {$('#layer_' + obj).css('display','none');$('blockMainOuter').unbind('click');  }
}

modalDimmer = function (zz) {
    alert(zz);
}


////////////////////////////////////////////////////////////////
//
// Initialisieren der Seite
//
////////////////////////////////////////////////////////////////

jQuery(document).ready(function(){
  if(typeof wInitBrowseEdit == 'function'){
    wInitBrowseEdit();
  }
  if(typeof wEditor == 'undefined'){
    jQuery("a.box").fancybox({"type": "iframe", "width": 560, "height": '80%', "titlePosition": "inside", "transitionIn" : "none", "transitionOut" : "none", "hideOnContentClick": true, "zoomOpacity": true, "zoomSpeedChange": 200, "zoomSpeedIn": 400, "zoomSpeedOut": 400, "overlayShow": false, "overlayOpacity": 1});
    jQuery("a.box").setViewmode('blank');

    jQuery("a.navLevel1PMimage").fancybox({"type": "image", "autoDimensions": true, "padding": 20, "titlePosition": "inside", "transitionIn" : "none", "transitionOut" : "none", "hideOnContentClick": true, "zoomOpacity": true, "zoomSpeedChange": 200, "zoomSpeedIn": 400, "zoomSpeedOut": 400, "overlayShow": true, "overlayOpacity": 0.4});
    jQuery("a.navLevel1PMimage").setViewmode('blank');


    if(typeof pageTracker != 'undefined'){
      jQuery("a.pdf, a.download").addAnalytics();
    }

// JM Style Manipulation bei Doppelüberschriften //
// $('.elementHeadline').next('.elementHeadline').children('h5').css('margin-top','0');

// JM eTracker EventClicker //
    if (typeof et_et != 'undefined') {
      // alle externen Links tracken

      jQuery.each($("a"), function(x){
        var href= this.getAttribute('href');
        if (href) {
          if (href.substring(0,4).toLowerCase() == 'http' ) {
            this.setAttribute('onclick', 'ET_Event.click(\'' + href + '\');  ;');
          }
        }
      });

    }


// erste lösung
//    $('div#navigationMeta a#onlinezugaenge').click(function(){
//      showModalLayer('onlinezugaenge');
//    });


  }

// jquery modal test

// --------------------------------------------------------
//  OnlineZugänge Meta

    $('div#navigationMeta a#onlinezugaenge').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        var modalId      = '#onlinezugaenge';
        var modalIdlayer = '#layer_onlinezugaenge';

        // Elemente umhängen
        $('#mask').appendTo('body');
        $(modalIdlayer).appendTo('body');

        $(modalIdlayer).css('top', 21);
        $(modalIdlayer).css('left', eval($(window).width() / 2 + 309) );
        $(modalIdlayer).css('width', '184' );

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});

        //transition effect
        $('#mask').fadeTo(100,0.1);

        //transition effect

        $(modalIdlayer).fadeIn(100);
    });

    //if close button is clicked
    $('.content .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .content').hide();
    });

    //if mask is clicked
    $('#mask').click(function () {
        $(this).fadeTo(200,0);
        $(this).hide();
        $('.content').hide();
    });


// --------------------------------------------------------
//  OnlineZugänge Links

    $('a#a_onlinezugaengelinks').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        var modalIdlayer = '#layer_onlinezugaengelinks';

        // Elemente umhängen
        $('#mask').appendTo('body');
        $(modalIdlayer).appendTo('body');

        $(modalIdlayer).css('top', 485);
        $(modalIdlayer).css('left', eval($(window).width() / 2 - 493) );
        $(modalIdlayer).css('width', 238 );

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});

        //transition effect
        $('#mask').fadeTo(100,0.1);

        //transition effect

        $(modalIdlayer).fadeIn(100);
    });

    //if close button is clicked
    $('.content .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .content').hide();
    });

    //if mask is clicked
    $('#mask').click(function () {
        $(this).fadeTo(200,0);
        $(this).hide();
        $('.content').hide();
    });




// --------------------------------------------------------
//  Kontaktzuuns

    $('div#navigationMeta a#kontaktzuuns').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        var modalIdlayer = '#layer_kontaktzuuns';

        // Elemente umhängen
        $('#mask').appendTo('body');
        $(modalIdlayer).appendTo('body');

        $(modalIdlayer).css('top', 21);
        $(modalIdlayer).css('left', eval($(window).width() / 2 - 200) );

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});

        //transition effect
        $('#mask').fadeTo(100,0.1);

        //transition effect

        $(modalIdlayer).fadeIn(100);

    });

    //if close button is clicked
    $('.content .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .content').hide();
    });

    //if mask is clicked
    $('#mask').click(function () {
        $(this).fadeTo(200,0);
        $(this).hide();
        $('.content').hide();
    });

// --------------------------------------------------------
//  3SG Layer

    $('a#a_3sg').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        var modalIdlayer = '#layer_3sg';

        // Elemente umhängen
        $('#mask').appendTo('body');
        $(modalIdlayer).appendTo('body');

        $(modalIdlayer).css('top', 388);
        $(modalIdlayer).css('left', eval($(window).width() / 2 - 493) );

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});

        //transition effect
        $('#mask').fadeTo(100,0.1);

        //transition effect

        $(modalIdlayer).fadeIn(100);

    });

    //if close button is clicked
    $('.content .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .content').hide();
    });

    //if mask is clicked
    $('#mask').click(function () {
        $(this).fadeTo(200,0);
        $(this).hide();
        $('.content').hide();
    });








// ----- Jalousien vorbereiten ------
$( ".jalousie" ).accordion({ collapsible: true, active: false, clearStyle: true, animated: false});  // erlaubt das schließen aller elemente

$(".jalousie .wglButton").removeClass('ui-corner-all ui-accordion-header ui-helper-reset ui-state-default ui-accordion-content ui-widget-content ui-corner-bottom');
$(".jalousie .wglButton").css({"display":"", "height":""});
$(".jalousie .beButtonDeleteRow").css({"position":"absolute", "right":"70px"});
$(".jalousie .beButtonEditRow").css({"position":"absolute", "right":"90px"});


$('.accordion .head').click(function() {
    $(this).next().toggle('slow');
    return false;
  }).next().hide();

$( ".jalousie").bind("accordionchangestart", function(event, ui) { ui.newHeader.find('.kopfrechts').html('schließen'); ui.newHeader.find('.kopfrechts').css('background-image','url(/final-wGlobal/wGlobal/layout/images/backgrounds/arrow-up.gif)'); } );
$( ".jalousie").bind("accordionchangestart", function(event, ui) { ui.oldHeader.find('.kopfrechts').html('zeigen'); ui.oldHeader.find('.kopfrechts').css('background-image','url(/final-wGlobal/wGlobal/layout/images/backgrounds/arrow-down.gif)'); } );


// wenn jalousie in der druckvorschau ist, alle contents anzeigen
if ($('#printButton').css('position') == 'absolute') {$('.jalousie .jalousiecontent').show();}
//$('.jalousie .jalousiecontent').css('display','block');


// ---- Position des Overlay bei Fensteränderungen neu setzen

$(window).resize(function() {
        // --- Kontakt neupos
        var modalIdlayer = '#layer_kontaktzuuns';
        $(modalIdlayer).css('top', 21);
        $(modalIdlayer).css('left', eval($(window).width() / 2 - 200) );

        // --- Zugänge Meta neupos
        var modalIdlayer = '#layer_onlinezugaenge';
        $(modalIdlayer).css('top', 21);
        $(modalIdlayer).css('left', eval($(window).width() / 2 + 309) );

        // --- Zugänge links
        var modalIdlayer = '#layer_onlinezugaengelinks';
        $(modalIdlayer).css('top', 485);
        $(modalIdlayer).css('left', eval($(window).width() / 2 - 493) );


        // - falls geöffneter layer, auch die abdunklung resizen
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
        $('#mask').css({'width':maskWidth,'height':maskHeight});




});











});
