//KALENDER

$(function(){
    $('img.lazy').show().jail({effect:"fadeIn", placeholder: "/template/images/blank.jpg"});
 });


function cale(){
        $('.date_has_event').each(function () {
		// options
		var distance = 10;
		var time = 250;
		var hideDelay = 300;

		var hideDelayTimer = null;

		// tracker
		var beingShown = false;
		var shown = false;

		var trigger = $(this);
		var popup = $('.events ul', this).css('opacity', 0);

		// set the mouseover and mouseout on both element
		$([trigger.get(0), popup.get(0)]).mouseover(function () {
			// stops the hide event if we move from the trigger to the popup element
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// don't trigger the animation again if we're being shown, or already visible
			if (beingShown || shown) {
				return;
			} else {
				beingShown = true;

				// reset position of popup box
				popup.css({
					bottom: 10,
					left: -76,
					display: 'block' // brings the popup back in to view
				})

				// (we're using chaining on the popup) now animate it's opacity and position
				.animate({
					bottom: '+=' + distance + 'px',
					opacity: 1
				}, time, 'swing', function() {
					// once the animation is complete, set the tracker variables
					beingShown = false;
					shown = true;
				});
			}
		}).mouseout(function () {
			// reset the timer if we get fired again - avoids double animations
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// store the timer so that it can be cleared in the mouseover if required
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				popup.animate({
					bottom: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					// once the animate is complete, set the tracker variables
					shown = false;
					// hide the popup entirely after the effect (opacity alone doesn't do the job)
					popup.css('display', 'none');
				});
			}, hideDelay);
		});
	});
}



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




if(!Modernizr.input.placeholder){

	$("input").each( function() {
		if($(this).val()=="" && $(this).attr("placeholder")!="") {
			$(this).val($(this).attr("placeholder"));
			$(this).focus( function() {
				if($(this).val()==$(this).attr("placeholder"))
					$(this).val("");
			});
			$(this).blur( function() {
				if($(this).val()=="")
					$(this).val($(this).attr("placeholder"));
			});
		}
	});
}




//Youtube 

$(".FancyVideo").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'none',
			'overlayOpacity'  :   '0.8',
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});




        //QueryLoader.selectorPreload = "#header";
        //QueryLoader.init();



$('#flowtabs li').hover(function(){
        var pos= $(this).position();
        $(this).find('ul').css({'marginTop' : pos.top+'px'});
        $(this).trigger('click');
        $(this).find('ul').stop().animate({'marginRight' : '230px', 'right' : '25px', 'opacity' : '1.0'},300);
},function(){
    $(this).find('ul').stop().css('display' , 'block').animate({'marginRight' : '0px', 'right' : '30px', 'opacity' : '0.0'},400);
});


//FANCYBOX


//function stopscroller(){
//var countsponsor = $('#sponsoren').find('items').length;
//var apil = $("#sponsoren").data("scrollable");
//apil.stop();
//}
//function startscroller(){
//    var countsponsor = $('#sponsoren').find('items').length;
//
//var apil = $("#sponsoren").data("scrollable");
//apil.play();
//}

    $('.fancy').fancybox({'transitionIn'    :   'elastic',
                          'transitionOut'   :   'elastic',
                          'overlayOpacity'  :   '0.8',
                          'opacityColor'    :   '#000',
						  'titlePosition'	:	'inside',
//                          'onStart'         :   function(){
//                                                    if( countsponsor == 0)stopscroller()
//                                                },
//                          'onClosed'        :   function(){
//                                                    if( countsponsor == 0) startscroller()
//                                                },
                          'opacity'         :   'true'});
    


//GÄSTEBUCH
    $('#sid_guestbook').slideUp(0);
    $('#gb_wrap').prepend('<div id="gb_insert" class="right"><a style="display: block; cursor: pointer;"><img src="template/images/insert_entry.png" alt="" /> Eintrag hinzufügen</a></div>');

    var error = $('#error ul').find('li');
    if(error.length > 0 ) $('#sid_guestbook').slideDown(0);

    $('#gb_insert').toggle(function(){
        $('#sid_guestbook').slideDown(600);
        $('#gb_insert').html('<a style="display: block; cursor: pointer;">&uarr; verbergen</a>');
    },function(){
        $('#sid_guestbook').slideUp(600);
        $('#gb_insert').html('<a style="display: block; cursor: pointer;"><img src="template/images/insert_entry.png" alt="" /> Eintrag hinzufügen</a>');
    });

    
//SPONSORENSLIDESHOW
//        var divs = $('#sponsoren').find('.items').find('div');

//        if(divs.length > 1){
//            $("#sponsoren").scrollable({speed: 3500, circular: true, keyboard: false }).autoscroll(9000);

//        }





//Kalender
cale();



$('#events').find('a.nav').click(function(e){
   e.preventDefault();

   var id = $(this).attr('id');

   var monat = $('#events').find('table').parent('div').attr('class');
   if(id == 'right') monat = parseInt(monat) + 1;
   if(id == 'left') monat = parseInt(monat) - 1;   

   var year = $('#events').find('.month').text();
   year = year.substring(year.length -4, year.length);
  
   if(monat > 12){
		 monat = 1;
	     year++;
	}
   if(monat < 1){
		 monat = 12;
		 year--;
	}


	if(id == 'today') {
       var amon = new Date();
       monat = parseInt(amon.getMonth()) + 1;
	   year = parseInt(amon.getFullYear());
   }


//   $.ajax({
//       type: "GET",
//       url: "index.php",
//       data: "&id=1002&monat="+monat,
//       success: function(msg){
//         $('#events').find('table').parent('div').replaceWith(msg);
//       }
//    });


   $.get("index.php?id=1002", {monat: monat, year: year}, function(cal){
       $('#events').find('table').parent('div').replaceWith(cal);
       cale();
   });
});

});


// Bilderupload

$(document).bind('cbox_closed', function(){
    document.location.href = document.location.href;
});


