﻿jQuery(document).ready(function() {

  /////////////////////
  // MEGA NAVIGATION
  function addMega(){
    $(this).addClass("hovering");
    }
  function removeMega(){
    $(this).removeClass("hovering");
    }
  var megaConfig = {
    interval: 5,
    sensitivity: 15,
    over: addMega,
    timeout: 50,
    out: removeMega
  };
  
  // $("li.mega").hoverIntent(megaConfig)
  
  /////////////////////
  // VIEW
  $(".view_content").hide();
	$("ul.views li.button:first").addClass("active").show();
	$(".view_content:first").show();
  
	$("ul.views li.button").click(function() {
    $("ul.views li.button").removeClass("active");
    $(this).addClass("active");
    $(".view_content").hide();
    var activeView = $(this).find("a").attr("href"); 
    $(activeView).fadeIn();
    return false;
	});
  
  //////////////////////
  // TOOLTIP

  $('.tooltip').CreateBubblePopup({
	position : 'top',
	align	 : 'center',
	width	 : '280',
	innerHtml: 'Leer',
	innerHtmlStyle: {
	    color:'#FFFFFF', 
		'text-align':'center'
		},							
	themeName: 	'all-orange',
	themePath: 	'fileadmin/thueringer-staedte/template/gfx/bubble'
		
  });

  $('.tooltip').each(function(index) {
	  	all = $(this).attr('id');
	  	id = all.split('a');
	  	text = $('#b'+id[1]).html();
	  	$(this).SetBubblePopupInnerHtml(text);
	  	//$(this).hover(function(){$('.tooltip').fadeOut(100);});

	});

  /////////////////////
  // HIGHLIGHTS
    
  function imgResize(w, h,img) {
		var maxWidth = w;
		var maxHeight = h;
		var ratio;
		var width = $(img).width();
		var height = $(img).height();
		
		if(width > maxWidth) {
			ratio = maxWidth/width;
			$(img).css("width", maxWidth);
			$(img).css("height", height * ratio);
			height = height * ratio;
			width = width * ratio;
		}
		if(height > maxHeight) {
			ratio = maxHeight/height;
			$(img).css("height", maxHeight);
			$(img).css("width", width * ratio);
			width = width * ratio;
		}
	}
  
  $('.overview .small img').each(function() {
    imgResize(100,75, this)
  });
  
  $("div.overview:first").addClass("extended");
  
  $('.overview').click(function(){
    $(".overview").removeClass("extended");
    $(this).addClass("extended");
	});
  
  ////////////////////////
  // SCROLLER
  
  $('a[href*=#]').click(function() {

      // skip SmoothScroll on links inside sliders or scroll boxes also using anchors or if there is a javascript call
      if($(this).parent().hasClass('scrollable_navigation') || $(this).attr('href').indexOf('javascript')>-1) return;

      // duration in ms
      var duration=1000;

      // easing values: swing | linear
      var easing='swing';

      // get / set parameters
      var newHash=this.hash;
      var oldLocation=window.location.href.replace(window.location.hash, '');
      var newLocation=this;

      // make sure it's the same location      
      if(oldLocation+newHash==newLocation)
      {
         // get target
         var target=$(this.hash+', a[name='+this.hash.slice(1)+']').offset().top;

         // adjust target for anchors near the bottom of the page
         if(target > $(document).height()-$(window).height()) target=$(document).height()-$(window).height();         

         // set selector
         if($.browser.safari) var animationSelector='body:not(:animated)';
         else var animationSelector='html:not(:animated)';

         // animate to target and set the hash to the window.location after the animation
         $(animationSelector).animate({ scrollTop: target }, duration, easing, function() {

            // add new hash to the browser location
            window.location.href=newLocation;
         });

         // cancel default click action
         return false;
      }
   });


  
});
