$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		animSpeed:500,
		pauseTime:10000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
    controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){
		  changeText();
		}
	});
});

String.prototype.replaceAll = function(pcFrom, pcTo){
    var c = this;
    while (c.indexOf(pcFrom) > -1)
        c = c.replace(pcFrom, pcTo); 
    return c;
};

replacess_counter = 0;
function replacess(json) {
  got_location = false;

  yqlgeo.get(json.ip, function(o) {
    if(!got_location) {
      got_location = true;
      if(o.place && o.place.country.code == "CH") {
        $("body *").replaceText( 'ß', "ss");
      } else {
        if(replacess_counter < 5) {
          replacess_counter++;
          got_location = false;
          window.setTimeout("replacess({ip: \""+json.ip+"\"})", 1000);
        }
      }
    }
  });
}
$(window).ready(function() {
jQuery.ajax({dataType: 'jsonp', jsonpCallback: 'replacess', url: "http://jsonip.appspot.com/"});
});




function changeText() {
  var active;
  active = $('a.nivo-control.active').index();
  
  var num_slides
  num_slides = $('#slider > img').size();
  activate = active + 2;
  deactivate = active + 1;
  if (activate > num_slides) {
    activate = 1;
    deactivate = num_slides;
  }

  $("#slide"+deactivate).fadeOut(1000);  
  $("#slide"+activate).fadeIn(400, function() { $(this).siblings(":not(#slide"+deactivate+")").hide()});
  
}

$(document).ready(function() {
   $(".main-content a[title]").tooltip();
  
  // add a flap to each h3 in content
   $(".main-content h3").each(function() {
     $(this).before('<span class="horizontal-flap" id="flap-' + $(this).html().toLowerCase().replaceAll('und ', '').replaceAll(' ','-').replaceAll('&','').replaceAll('ä;','ae').replaceAll('ö','oe').replaceAll('ü','ue').replaceAll('  ','').replaceAll(',','').replaceAll('′','').replaceAll(':','').replaceAll('?','').replaceAll('.','').replaceAll('!','') + '"></span>');
   });
   
   // add a hr in front of every flap except the first
    $(".horizontal-flap").before('<hr />');
    $("hr").first().hide();
//   
//   $("#pricing-overview .product").hover(function() {
//     $(this).animate({ 
//         marginTop: "-12px"
//       }, 200 ); 
//   });
//   $("#pricing-overview .product").mouseleave(function() {
//     $(this).animate({ 
//         marginTop: "0px"
//       }, 200 ); 
//   });
   
   //stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
   if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
   {
        $("#page-footer").css("position", "static");
   };
 });
