jQuery(document).ready(function($) {

    /*
	   *  Zeitstrahl
	   * * * * * * * * * * * * * * * * * * */
	   
    /* Ver 1*/
	  /*$('.slider').movingBoxes({
        startPanel: 1,        // start with this panel
        movingDistance: 428,  // panel distance to move
        curWidth: 214,        // panel width
        curImgWidth: 180,     // Image width
        curTitleSize: '15px', // Title font size
        curParSize: '11px',   // paragraph font size
        speed: 500            // time in milliseconds
    });*/


    /*
	   *  Twitter
	   * * * * * * * * * * * * * * * * * * */
	   
    /*$("#twitter-status").tweet({
       join_text: "auto",
       username: "BWEeV",
       count: 3,
       auto_join_text_default: "",
       auto_join_text_ed: "",
       auto_join_text_ing: "",
       auto_join_text_reply: "",
       auto_join_text_url: "",
       loading_text: "Tweet wird geladen..."
    });*/
  
  	if ( $("body").hasClass("slug-home") ) {
      var twitterStatus = $("body.slug-home .widget_twitter .teaser-content ul.twitter").length;
    	if(twitterStatus == 0) {
    	  $("body.slug-home .widget_twitter").css("display", "none");
      }
    }

  	var twitterStatus = $("body .twitter-inside .teaser-content ul.twitter").length;
  	if(twitterStatus == 0) {
  	  $("body .twitter-inside").css("display", "none");
    }
  
  
	  /*
	   *  Breite Bild mit Unterschrift
	   * * * * * * * * * * * * * * * * * * * */

    $(".bild-im-text-links").css("width", $(".bild-im-text-links a").outerWidth());

  
	  /*
	   *  ColorBox - Layer
	   * * * * * * * * * * * * * * * * * * * */
   	$("#ee-blog .overlay").colorbox({ /* EE-Blog */
    		width: "783",
    		initialWidth: "775",
    		innerWidth: "775",
    		opacity: 0.7,
    		current: "{current} von {total} Blog-Beiträgen",
    		previous: "zurück",
    		next: "weiter",
    		close: "schließen",
    		slideshowStart: "Slideshow starten",
    		slideshowStop: "Slideshow stoppen"
    });

   	$(".timeline-posts .overlay").colorbox({ /* Zeitstrahl */
    		width: "585",
    		initialWidth: "579",
    		innerWidth: "579",
    		opacity: 0.7,
    		current: "{current} von {total} Einträgen",
    		close: '<span class="arrow-blue">Fenster schließen</span>',
    		initialHeight: "395"
    });
    
    $(function() {
       $("#cboxClose").hover(function() {
            $(this).css({"text-decoration" : "underline"});
       },
       function(){
            $(this).css({"text-decoration" : "none"});
       })
    });
    

	  /*
	   *  Button Hover
	   * * * * * * * * * * * * * * * * * * * */
    $(function() {
       $("#searchform input#searchsubmit").hover(function() {
            $(this).css({"color" : "#FFFFFF", "background-color" : "#0C3963"});
       },
       function(){
            $(this).css({"color" : "#0C3963", "background-color" : "#EBF1F5"});
       })
    });


	  /*
	   *  EqualHeights
	   * * * * * * * * * * * * * * * * * * * */
    $("#HomepageWidgetsLeft ul li.widgetcontainer div.teaser-content").equalHeights();
    
  	var entryUtility = $(".entry-utility .entry-bookmarks").length;
  	if(entryUtility != 0) {
      $("body #content :not(.list-content) .hentry").addClass("equalHeights");
      $("body #secondary").addClass("equalHeights");
      $("body .equalHeights").equalHeights();
      $("body #content>.entry-utility").css({
  			"position" : "absolute",
  			"bottom" : "0",
  			"left" : "0",
  			"margin-bottom" : "0"
  		});
  		$("body :not(.list-content) .entry-utility").css({
        "bottom" : "10px",
        "left" : "0px"
      });
		}
		
  	/*var listContent = $(".list-content").length;
  	if(listContent != 0) {
      $(".list-content .hentry").equalHeights();
  	}*/
		
		
	  /*
	   *  Map Hover
	   * * * * * * * * * * * * * * * * * * * */
    $.fn.maphilight.defaults = {
    	fill: true,
    	fillColor: 'ffffff',
    	fillOpacity: 0.3,
    	stroke: false,
    	strokeColor: 'ff0000',
    	strokeOpacity: 1,
    	strokeWidth: 1,
    	fade: false,
    	alwaysOn: false,
    	neverOn: false,
    	groupBy: false
    }

		if ( $("body").hasClass("slug-home") ) {
      $(function() {
          $('#socialMediaImg').maphilight();
      });
    }


	  /*
	   * Aktuellen Meldungen Tabs
	   * * * * * * * * * * * * * * * * * * * */
	  if ( $("body").hasClass("slug-home") ) {
	  
      // Hintergrundbilder preloaden
      $latest_posts_array = $(".latest-posts .latest-posts-entry");

      for($i=0; $i < $latest_posts_array.size(); $i++) {
        $latest_posts_img = $($latest_posts_array[$i]).css("background-image").replace("url(","").replace(")","");
        preloadimage = new Image();
        preloadimage.src = $latest_posts_img;
      }
      
		  $("ul.latest-posts-navi li a").click( function(e) {

			  e.preventDefault();

			  var element = $(this).parent();
			  var oldId = $("ul.latest-posts-navi li.active").attr("id").replace("post_nav_", "");
			  var targetId	= $(element).attr("id").replace("post_nav_", "");

			  $("ul.latest-posts-navi li.active").removeClass("active");
			  $(element).addClass("active");

			  $("body.slug-home #post_entry_"+oldId).hide().removeClass("show");
			  $("body.slug-home #post_entry_"+targetId).fadeIn(300, function() { if ($.browser.msie){ this.style.removeAttribute('filter'); } }).removeClass("hide").addClass("show");
			  
        /* mehr Abstand nach unten, wenn Ueberschrift einzeilig */
        var titleHeight = $("#post_entry_"+targetId+" h2 a").height();
        //alert(titleHeight);
        if(titleHeight == 22) {
          $("#post_entry_"+targetId+" h2").css("bottom", "15px");
        }
        
		  }).eq(0).click();

    	// Enabling auto-advance.

    	var current=1;
    	function autoAdvance()
    	{
    		if(current==-1) return false;

    		$('ul.latest-posts-navi li a').eq(current%$('ul.latest-posts-navi li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
    		current++;
    	}

    	// The number of seconds that the slider will auto-advance in:
    	var changeEvery = 13;
    	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);

	  }
	  
	  
	  /*
	   * Artikelseite
	   * * * * * * * * * * * * * * * * * * * */
	   if ( $("body").hasClass("single") ) {
	   
	    /* mehr Abstand nach unten, wenn Ueberschrift einzeilig */
      $("body").load(function () {
        var titleHeight = $("#content h2").height();
        //alert(titleHeight);
        if(titleHeight == 27) {
          $("#content h2").css("padding-bottom", "13px");
        }
      }).eq(0).load();

    }
  
});
