//function noError(){return true;}
//window.onerror = noError;



 
 
var minicalTimeoutID = 0;
var eventTimeoutID = 0;
var eventPopup = null;
var maxEventsPerDay = 10;

 

$(document).ready(function(){

  // Jquery Startseite
     if ( $('body.home').length ) {
    // 3D Carousel
    $("#ec-carousel a").css("visibility", "visible");
    if($("#ec-carousel a").length > 1) {
		$("#ec-carousel").CloudCarousel( { 
		reflHeight: 0,
		reflGap:1,
		//titleBox: $('#da-vinci-title'),
		//altBox: $('#da-vinci-alt'),
		buttonLeft: $('#but1'),
		buttonRight: $('#but2'),
		yRadius:60,
		xRadius:270,
		xPos: 310,
		yPos: 30,
		speed:0.10,
		FPS:30,
		bringToFront : false,
		mouseWheel:true,
		autoRotate: 'yes',
    autoRotateDelay: 6500
	});
	}
	
	// Newsletter abonnieren
	$(".newsletter a.btn_newsletterabo").fancybox({
	'showCloseButton'	: true,
	'autoDimensions'	: true,
	'titlePosition' 		: 'inside',
	'transitionIn'	: 'elastic',
	'transitionOut'	: 'elastic',
	'type'				: 'iframe'
});
	

	
	// Teaser Carousel

  /* All Teaser Wraps
  	$('.tcontainer.scroll .tcwrap').infiniteCarousel({
		displayTime: 6000,
		textholderHeight : .25,
		displayThumbnails: 0,
		autoplay : 0
	});*/
	
	//News
  
  if($("#news .tcarousel ul li").length > 1) {
	$('#news.tcontainer.scroll .tcwrap').infiniteCarousel({
		displayTime: 6000,
		textholderHeight : .25,
		displayThumbnails: 0,
		autoplay : 0
	});
	}else{
  	$("#news .tcarousel").css("overflow", "hidden");
	  $("#news .tcarousel a").css("margin-left", "8px");
  }
	
	
	
	//Events 
  if($("#events .tcarousel ul li").length > 1) {
	$('#events.tcontainer.scroll .tcwrap').infiniteCarousel({
		displayTime: 6000,
		textholderHeight : .25,
		displayThumbnails: 0,
		autoplay : 1
	});
	}else{
   	 $("#events .tcarousel").css("overflow", "hidden");
	   $("#events .tcarousel a").css("margin-left", "8px");
  }
	
		//Fotos 
  if($("#photos .tcarousel ul li").length > 1) {
   $("#photos .tcarousel").css("overflow", "scroll");
	 $('#photos.tcontainer.scroll .tcwrap').infiniteCarousel({
		displayTime: 6000,
		textholderHeight : .25,
		displayThumbnails: 0,
		autoplay : 0
	});
	}else{
	
	 $("#photos .tcarousel").css("overflow", "hidden");
	 $("#photos .tcarousel a").css("margin-left", "8px");
  }
	
	
	//Sportnews
  if($("#vorwort .tcarousel ul li").length > 1) {
	$('#vorwort.tcontainer.scroll .tcwrap').infiniteCarousel({
		displayTime: 6000,
		textholderHeight : .25,
		displayThumbnails: 0,
		autoplay : 0
	});
	}else{
   $("#vorwort .tcarousel").css("overflow", "hidden");
	 $("#vorwort .tcarousel a").css("margin-left", "8px");
  }
  
  //Sportnews
  if($("#gemeinden .tcarousel ul li").length > 1) {
	$('#gemeinden.tcontainer.scroll .tcwrap').infiniteCarousel({
		displayTime: 6000,
		textholderHeight : .25,
		displayThumbnails: 0,
		autoplay : 0
	});
	}else{
   $("#gemeinden .tcarousel").css("overflow", "hidden");
	 $("#gemeinden .tcarousel a").css("margin-left", "8px");
  }
  
  
  //Projekte
  if($("#projekte .tcarousel ul li").length > 1) {
	$('#projekte.tcontainer.scroll .tcwrap').infiniteCarousel({
		displayTime: 6000,
		textholderHeight : .25,
		displayThumbnails: 0,
		autoplay : 0
	});
	}else{
   $("#gprojekte .tcarousel").css("overflow", "hidden");
	 $("#projekte .tcarousel a").css("margin-left", "8px");
  }
	
	
  } 
 
 
     // Newsletter abonnieren
    $(".newsletter a.btn_newsletterabo").fancybox({
        'showCloseButton': true,
        'autoDimensions': true,
        'titlePosition': 'inside',
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'type': 'iframe'
    });

    
    // Social Icons
    $("div.socialicons").jsocial({
        highlight: true,
        buttons: "facebook,misterwong,digg,delicious", 
				imagedir: "fileadmin/templates/frontend/img/social/", 
				imageextension: "gif", 
			  blanktarget: true
      });
      
      

    
        if ($("#ed_photogallery").length) {
        
        $("#ed_photogallery a[rel=example_group]").fancybox({
            'showCloseButton': true,
            'autoDimensions': true,
            'titlePosition': 'inside',
            'transitionIn': 'elastic',
            'transitionOut': 'elastic'
        });
    }
    
    
    // Was suche ich ?
    $(".tx_mh_branchenbuch-overview a.b_sel").click(function(event){
        linktext = $(this).text();
        $(".tx_mh_branchenbuch-searchform form #keyword3").attr('value', linktext);
    });
    
    // Wo soll gesucht werden ?
    $(".tx_mh_branchenbuch-list a.linkwho").click(function(event){
        linktext = $(this).text();
        $(".tx_mh_branchenbuch-searchform form #keyword2").attr('value', linktext);
    });
    
      // Activate Fanybox for Content
    
    if ($(".ed_content a").length) {
        $(".ed_content a.fancybox").fancybox({
            'showCloseButton': true,
            'autoDimensions': true,
            'titlePosition': 'inside',
            'transitionIn': 'elastic',
            'transitionOut': 'elastic'
        });
    }
    
        //Datepicker for Eventtip
    if ($(".ed_content .tx-powermail-pi1_formwrap_259").length) {
    
        $.datepicker.setDefaults($.datepicker.regional['de']);
        $(".tx-powermail-pi1_formwrap_259 #powermaildiv_uid8 input").datepicker({
            dateFormat: 'dd.mm.yy'
        });
        $(".tx-powermail-pi1_formwrap_259 #powermaildiv_uid18 input").datepicker({
            dateFormat: 'dd.mm.yy'
        });
        // Load uniform
        $(".tx-powermail-pi1_formwrap_259 form select").uniform();
        //$(".tx-powermail-pi1_formwrap_259 input").uniform();
		 //$.mask.definitions['~']='[+-]';
		 $.mask.rules.H = /([0-1][0-9]|2[0-3])/;  // 24 hours
         $.mask.masks.time = 'H:59';
		 $("#uid19, #uid20").setMask("29:59").keypress(function() {
  var currentMask = $(this).data('mask').mask;
  var newMask = $(this).val().match(/^2.*/) ? "23:59" : "29:59";
  if (newMask != currentMask) {
    $(this).setMask(newMask);
  }
});

    }
    
    
    
    // jquery for Events
    
    if ( $('body.events').length ) {
    
        // Load uniform
    $(".activate_uniform .searchformwrap select").uniform();
    $(".activate_uniform .searchformwrap input").uniform();
    
    //Datepicker
    $.datepicker.setDefaults($.datepicker.regional['de']);
    $(".searchformwrap input#dateselect_from").datepicker({
        dateFormat: 'dd.mm.yy'
    });
    $(".searchformwrap input#dateselect_to").datepicker({
        dateFormat: 'dd.mm.yy'
    });
    
    $(".daybody_content .evententry a").hover(showEventPopup, hideEventPopup);
    $(".daybody_content .evententry .tooltip").hover(stopEventPopupTimeout, hideEventPopup);

    

     
    // 3D Carousel
    $("#ec-carousel").CloudCarousel({
        reflHeight: 0,
        reflGap: 1,
        //titleBox: $('#da-vinci-title'),
        //altBox: $('#da-vinci-alt'),
        buttonLeft: $('#but1'),
        buttonRight: $('#but2'),
        yRadius: 60,
        xRadius: 270,
        xPos: 310,
        yPos: 30,
        speed: 0.10,
        FPS: 30,
        bringToFront: false,
        mouseWheel: true,
		  gotoActiveClass : true
    });
    

    
   }
   
   
    // jquery for Albums
    if ( $('body.pid101').length ) {
    
    $("div.jm-gallery-image-entry a[rel=gal_group]").fancybox({
        'showCloseButton': true,
        'autoDimensions': true,
        'titlePosition': 'inside',
        'transitionIn': 'elastic',
        'transitionOut': 'elastic'
    });
    
    }



     
function showEventPopup (evtObj)
{
	if (eventPopup != null)
	{
		stopEventPopupTimeout ();
		eventPopup.hide ();
	}
	
	eventPopup = $(this).next();
	eventPopup.show();
	
	var pos = $(this).position();
	pos.top -= -20;
	pos.left += 70;
	eventPopup.css ("top", pos.top);
	eventPopup.css ("left", pos.left);
	eventPopup.css ("z-index", "9999");

	// align on screen	
	//var diff = eventPopup.offset().top + eventPopup.height () - $(window).height() - $(window).scrollTop();
	//if (diff > 0)
	//{
	//	eventPopup.css("top", pos.top - diff);
	//}

	//diff = pos.left + eventPopup.width() - 600;
	//if (diff > 0)
	//{
	//	eventPopup.css("left", pos.left - diff);
	//}
	
// Position the tooltip. 


 //var tPosX = evtObj.pageX - 5;
 //var tPosY = evtObj.pageY + 20; 
 //eventPopup.css({top: tPosY, left: tPosX}); 

}

function hideEventPopup (evtObj)
{
	eventTimeoutID = setTimeout (doHideEventPopup, 100);

}

function doHideEventPopup ()
{
	eventPopup.hide ();
}

function stopEventPopupTimeout ()
{
	clearTimeout (eventTimeoutID);
}


 });
