
function installSearchEngine() {
  if(window.external && ('AddSearchProvider' in window.external)) {
    // Firefox 2 and IE 7, OpenSearch
    window.external.AddSearchProvider('http://syndication.teledir.de/opensearch/vorwahlnummern/opensearch.xml');
  }
  /*
  else if(window.sidebar && ('addSearchEngine' in window.sidebar)) {
    // Firefox <= 1.5, Sherlock
    window.sidebar.addSearchEngine('search-plugin.src', 'search-icon.png', 'Search Plugin', '');
  }
  */
  else {
    // No search engine support (IE 6, Opera, etc).
    alert('Dein Browser unterstützt diese Suchplugin nicht!');
  }
  return false;
}

function go(t) {
  var f = document.getElementById('go');
  if(f) {
    f.action = t;
    f.submit();
  }
}

$(function() {

$.get('http://' + location.host + '/wp-content/themes/structure/sidebar-iframe.php', function(data) {
  $('#sidebar').prepend(data);
  /*
   * cheapest prices
   */
  $('table.cheaplistinner table').hover(function() {
    this.style.backgroundColor = '#f5f5f5';
  },function() {
    this.style.backgroundColor = '#ffffff';
  });
  $('#sidebar .texttabs').texttabs();
  // sidebar
  $('.tabs-block div.tabbed ul.tabs li a').click(function(){
    var thisClass = this.className.slice(0, 2);
    $('.tabs-block div.tabbed div').hide();
    $('.tabs-block div.' + thisClass).show();
    $('.tabs-block div.tabbed ul.tabs li a').removeClass( 'tab-current');
    $(this).addClass('tab-current');
  });
  // setting the tabs in the sidebar hide and show, setting the current tab
  $('#home-categories div.c, div.tabbed div').hide();
  $('#home-categories div.post, #home-categories div.entry, div.t' + page_index ).show();
  $('#home-questions div.q1, #home-categories div.c1').show();
  $('div.tabbed ul.tabs li.t' + page_index + ' a').addClass('tab-current');
  $('div.tabbed ul.tabs li.c1 a').addClass('tab-current');
  $('div.tabbed ul li a').css('cursor', 'pointer');
  $('#home-questions div.tabbed ul.tabs li.q1 a').addClass('tab-current');
});

 
/*
 * tarif übersicht
 */
$('table.list tbody tr:odd, table.tarifrechner_serps_dsl tbody tr:odd' ).css('background-color', '#f7f7f7');

$('.tarife-details tbody tr.tr0, .tarife-details tbody tr.tr1').live('mouseover', function() {
  $(this).toggleClass('highlight');
});
$('.tarife-details tbody tr.tr0, .tarife-details tbody tr.tr1').live('mouseout', function() {
  $(this).toggleClass('highlight');
});
$('table.serps tbody tr, table.list tbody tr, table.tarifrechner_serps_dsl tbody tr, table.tarifrechner_serps_handy tbody tr').live('mouseover', function() {
    $(this).toggleClass('highlight');
});
$('table.serps tbody tr, table.list tbody tr, table.tarifrechner_serps_dsl tbody tr, table.tarifrechner_serps_handy tbody tr').live('mouseout', function() {
    $(this).toggleClass('highlight');
});
/*
 * searchbox
 */
// rel = index of text
var search_texts = ['Teledir durchsuchen ...', 'Fragen und Antworten durchsuchen ...'];
var search_index = 0;
$('.q').click(function() {
  search_index = parseInt($(this).attr('rel'));
  if(this.value == search_texts[search_index]) {
    this.value = '';
  }
});
$('.q').blur(function() {
  search_index = parseInt($(this).attr('rel'));
  if(this.value == '') {
    this.value = search_texts[search_index];
  }
});
$('.q').mouseover(function() {
  search_index = parseInt($(this).attr('rel'));
  if(this.value == search_texts[search_index]) {
    this.value = '';
  }
	this.focus();
});
$('.q').mouseout(function() {
  search_index = parseInt($(this).attr('rel'));
  if(this.value == '') {
    this.value = search_texts[search_index];
  }
});
$('#search-form').submit(function() {
  var q = $('#search-form .q').val();
  if(q == search_texts[0] || q == '') {
    alert('Bitte gib eine Suchanfrage ein!');
    $('#search-form .q').val('').focus();
    return false;
  }
  
  return true;
});
/*
 * collapsible
 */
$('.collapsible-more').click(function() {
  $(this).hide();
  if($(this).hasClass('ajax')) {
    $('> span', this.parentNode.parentNode).load('http://' + location.host + '/wp-content/plugins/local/ajax.php?method=' + this.rel + '&lat=' + $(this).attr('lat') + '&lon=' + $(this).attr('lon')).show();
  }
  else {
    $('> span', this.parentNode).show();
  }
  
  return false;
});

$('.collapsible-less').click(function() {
  $('> a', this.parentNode.parentNode).show();
  $(this).parent().hide();
  return false;
});
var tooltip = '';
/*
 * tooltips
 */
$('.tooltip').live('mouseover', function(e) {
  tooltip = this.title;
	this.title = '';
  //$('<p id="tooltip"></p>').html(tooltip).css({'top':(e.pageY - 10) + 'px','left':(e.pageX + 20) + 'px'}).appendTo( 'body' ).fadeIn( 'fast' );
  var el = $('<p id="tooltip"></p>').html(tooltip).appendTo('body');
  
  var y = e.pageY - 10;
  var x = e.pageX + 20;

  if(y + el.outerHeight(true) > $(window).scrollTop() + $(window).height()) {
    y -= el.outerHeight(true) + 10;
  } 
  
  if(x + el.outerWidth(true) > $(window).scrollLeft() + $(window).width()) {
    x -= el.outerWidth(true) + 20;
  }
  
  el.css({'top':y + 'px','left':x + 'px'}).show();
});
$('.tooltip').live('mouseout', function() {
//function(){
  this.title = tooltip;		
	$('#tooltip').remove();
});
(function($) {
$.fn.texttabs = function() {

var settings = $.extend({}, $.fn.texttabs.defaults, arguments[0] || {});

return $(this).each(function(i) {
  this.id = 'texttabs-' + i;
  var that = this;
  // initially add active class to the first tab
  $('> a:nth(' + settings.tab + ')', this).addClass('texttabs-button-active');
  // add classnames to the tab buttons
  $('> a', this).addClass('texttabs-button');

  $('> a', this).each(function(i) {
    // add id to tab button
    this.id = 'texttabs-button-' + i;
    // add click handler to tab button
    this.onclick = function() {
      var index = this.id.split('-')[2];
      // hide all but the clicked
      $('> div', that).hide(); //filter('eq(' + index + ')').hide();
      // show tab
      $('> div:nth(' + index + ')', that).show();
      // remove active class from all button 
      $('> a', that).removeClass('texttabs-button-active');
      // add active class to the clicked button
      $('> a:nth(' + index + ')', that).addClass('texttabs-button-active');
      return false;
    }
  });

  $('> div', this).each(function(i) {
    // add ids to the tabs
    this.id = 'texttabs-tab-' + i;
    // initially hide all but the first tab
    $(this).addClass('texttabs-tab');
    if(i != settings.tab) {
      $(this).hide();
    }
  });
});

}

// default settings
$.fn.texttabs.defaults = {
  // initially active tab
  tab: 0 
};

$('.texttabs').texttabs();

})(jQuery);

/**
 * tabbing
 */
 /*
$('.texttabs').each(function(i) {
  this.id = 'texttabs-' + i;
  var that = this;

  $('> a', this).each(function(i) {
    this.id = 'texttabs-button-' + i;
    this.className = 'texttabs-button';
    
    if(i == 0) {
      $(this).addClass('texttabs-button-active');
    }
    
    this.onclick = function() {
      $('> div', that).hide();
      $('> a', that).removeClass('texttabs-button-active');
      var index = this.id.split('-')[2];
      $('#texttabs-tab-' + index, that).show();
      $('#texttabs-button-' + index, that).addClass('texttabs-button-active');
      return false;
    }
  });
  
  $('> div', this).each(function(i) {
    this.id = 'texttabs-tab-' + i;
    this.className = 'texttabs-tab';
    if(i > 0) {
      this.style.display = 'none';
    }
  });
});
*/

// category
$('#home-categories div.tabbed ul.tabs li a').click(function(){
  var categoryClass = this.className.slice(0,2);
  $('#home-categories div.tabbed div.c').hide();
  $('#home-categories div.' + categoryClass).show();
  $('#home-categories div.tabbed ul.tabs li a').removeClass('tab-current');
  $(this).addClass('tab-current');
});
// questions
$('#home-questions div.tabbed ul.tabs li a').click(function(){
  var i = this.className.substr(1,1);
  $('#home-questions div.q'+(i==1?2:1)).hide();
  $('#home-questions div.q' + i).show();
  $('#home-questions div.tabbed ul.tabs li a').removeClass('tab-current');
  $(this).addClass('tab-current');
});
// top tarife sidebar
if(window.location.hash && window.location.hash == '#internet') {
  $('#texttabs-button-1').click();
}


});