////////////////////////////////////////////////////////////////
//
// @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)
//
// @desc Öffnet eine Seite in einem Popup
//
// @return void
//
////////////////////////////////////////////////////////////////

function wOpenPopupURL(url, width, height){

  var name = '';
  
  if(width == '' || width == ' '){
    width = 786;
  }
  if(height == '' || height == ' '){
    height = 677;
  }
  
  url = url.replace(/&amp;/g, '&');
  options = ',location=no, menubar=no,toolbar=no,resizable=no,scrollbars=no,status=no';
  width   = parseInt(width);
  height  = parseInt(height);

  var posLeft = (screen.width / 2)  - (width  / 2);
  var posTop  = (screen.height / 2) - (height / 2);
  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('|', '@');
}

function wEmbedNavpoint(id, url, mode){

  if(typeof wEditor == 'object'){
    return false;
  }
 
  if(mode == 'embed'){ 
    if($('#navpoint_' + id).data('hasLoaded') == '1'){             
      $('#navEmbed_' + id).show();                                    
    }
    else{        
      //jQuery('#navpoint_' + id).mouseout(function(){
      //  $('#navEmbed_' + id).hide();
      //});
       
      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('#navEmbed_' + id).mouseover(function(){
            $('#navEmbed_' + id).show();
          });
          
          //jQuery('#navEmbed_' + id).mouseout(function(){
          //  $('#navEmbed_' + id).hide();
          //});
        }
      });
    }  
  }
  else{ 
    if($('#navpoint_' + id).data('hasLoaded') == '1'){
      $('#navEmbed_' + id).show();
      try {

        $('#navEmbedIframe_' + id).height(frames['navEmbedIframe_' + id].$('#blockContent').height() + 50);
        $('#navEmbed_' + id).height(frames['navEmbedIframe_' + id].$('#blockContent').height() + 50);

      } catch (e){}
                           

    }
    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.name      = '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();        
                      
      //if(layerLeft < navpointLeft){
        $('#navEmbed_' + id).css('left', String(navpointLeft - layerLeft - 16) + 'px');
      //}
      
      var layerRight = $('#navEmbed_' + id).offset().left + $('#navEmbed_' + id).width();
                   
      if(layerRight > blockMainRight){
        $('#navEmbed_' + id).css('marginLeft', String(- (layerRight - blockMainRight) - 37) + '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();
      //});
    }       
  }  
}  

$(document).ready(function(){
  if (typeof(wEditor) == 'undefined'){

    $('li.navLevel1, li.navLevel1OpenDescendantSelected, li.navLevel1OpenSelected, li.navLevel1Selected').mouseenter(function(){

      $left   = $(this).position().left;
      $width  = $(this).width();
      $right  = $left+$width;

      $parentToAppend = $(this);

      $navText      = $(this).find('span').html();
      $navId        = $(this).find('a').attr('id');
      $href         = $(this).find('a').attr('href');
      $plainId      = $navId.substring($navId.indexOf('_')+1, $navId.length);


      $('div.navLevel1Embed').each(function(){
        $navEmbedId   = ($(this).attr('id'));
        $plainEmbedId = $navEmbedId.substring($navEmbedId.indexOf('_')+1, $navEmbedId.length);
        $navPointId   = 'navpoint_'+$plainEmbedId;

        if($plainEmbedId != $plainId){
          $(this).hide();
          $itemToRemove = $('#append'+$navPointId);
          $itemToRemove.remove();
        }
      })

      $appendContent = '<div class="navLevel1Hover" id="append'+$navId+'"><div class="left">&#160;</div><div class="middle"><a href="'+$href+'">'+$navText+'</a></div><div class="right">&#160;</div></div>';


      if($('#append'+$navId).length < 1){
        appendedContent = $($parentToAppend).append($appendContent);
        $('#append'+$navId).css('width',$width+10);
        $('#append'+$navId).css('left',$left);
        $('#append'+$navId).css('top','0');
        $('#append'+$navId).find('.middle').css('width',$width);

        $('#append' + $navId).bind('mouseout',function(){
          $navId   = $(this).attr('id');

          if($('#'+$navId).length > 0){
            $itemToRemove = $('#'+$navId);
            $itemToRemove.remove();
          }
          $('#navEmbed_' + $plainId).hide();
        })
      }
    })

    $('div.navLevel1Embed').mouseout(function(){
      $(this).hide();

      $navEmbedId   = ($(this).attr('id'));
      $plainEmbedId = $navEmbedId.substring($navEmbedId.indexOf('_')+1, $navEmbedId.length);
      $navPointId   = 'navpoint_'+$plainEmbedId;

      $itemToRemove = $('#append'+$navPointId);
      $itemToRemove.remove();
    })
  }
  
  $('ul.listFaq > li.listEntry > div.entryText > div.teaser > a.readMore').hover(

    function(){
      $(this).css('color','#018093');
    },
  
    function(){
      $(this).css('color','#666');
    }
  )
  
  $('ul.listFaq > li.listEntry > div.entryText > h2.listEntryTitle').hover(

    function(){
      $(this).css('color','#018093');
    },

    function(){
      $(this).css('color','#333');
    }
  )
  
  $('ul.listFaq > li.listEntry > div.entryText > h2.listEntryTitle, ul.listFaq > li.listEntry > div.entryText > div.teaser > a.readMore, ul.listFaq > li.listEntry > div.entryText > div.fullText > a.close').click(function(){
    $currentTag = $(this)[0].tagName;

    if ($currentTag != 'A'){
      $textElement = $(this).parent().attr('id');
      $headline    = $(this);
    } else {
      $textElement = $(this).parent().parent().attr('id');
      $headline    = $(this).parent().parent().find('h2.listEntryTitle');
    }

    if ($('#'+$textElement).find('.fullText').css('display') != 'block'){
      //$('#'+$textElement).find('.teaser').css('display','none');
      $('#'+$textElement).find('.fullText').css('display','block');
      $($headline).css('color','#018093');
    } else {
      //$('#'+$textElement).find('.teaser').css('display','block');
      $('#'+$textElement).find('.fullText').css('display','none');
      $($headline).css('color','#333');
    }
  })

  $('div.faqNavigation > div.openAll').click(function(){
    $('ul.listFaq > li.listEntry').each(function(i){
      $(this).find('.fullText').css('display','block');
    })
  })

  $('div.faqNavigation > div.closeAll').click(function(){
    $('ul.listFaq > li.listEntry').each(function(i){
      $(this).find('.fullText').css('display','none');
    })
  })
  
  
})

//window.onerror = return true;
