/****************************************
Mahnbescheid.com 
  ___               __                    __        
.'  _|.-----.-----.|__|.-----.-----.  .--|  |.-----.
|   _||  _  |__ --||  ||  _  |     |__|  _  ||  -__|
|__|  |_____|_____||__||_____|__|__|__|_____||_____|
a vision come(s) true (c) 2011 http://www.fosion.de     

*/

var fadetime = 500;
var   accordionOpenFirst = true;
var   accordionSpeed = 'medium';
 
 $(document).ready(function() {

	integrateFlowplayer();

	//lightbox jquery
    $("a[rel*=lightbox]").lightbox();
     
	Hyphenator.config({
		displaytogglebox : false,
		minwordlength : 5
	});
	Hyphenator.run();

	jQueryTypolightAccordion();
	gebuehrenRechner();
	registerInputToggle();
	animateEyecatcher();
	animateNonEyecatcher();
	exposeForms();
	animateBackgroundsCSS();
	
	
	preventEmptySend();
	
	
});



/*------------ functions ------------*/



function integrateFlowplayer()
{
	// check if there is a player
	if ($('#player').length != 0)
	{
		var videoFileUrl = 'http://www.mahnbescheid.com/tl_files/mahnbescheid/video/' + $('#player').html();
		var player = $f('player', "http://www.mahnbescheid.com/plugins/flowplayer/flowplayer-3.2.7.swf", {
		
		 	clip:  {
		 		autoPlay: true,
        		autoBuffering: true,
        		url: videoFileUrl
    		},
    		
			plugins:  {  
				controls:  {
					opacity: 0.6,
					backgroundColor: '#E8F0E8',
					backgroundGradient: 'none',			
					all:false,
					scrubber: true,
					volume:true,
					volumeSliderColor:'#53A953',
					mute:true,
					height: 20,
					fullscreen:false,
					buttonColor: 	'#53A953',
					buttonOverColor: 	'#ca000a',
					sliderColor: '#333333',
					progressColor: '#ca000a',
					bufferColor: '#53A953',
					autoHide: true,
					hideDelay:  500,
				}
			},
    		
    		
    		screen: {
				width: 340,
				height: 200, 
				top: 0
			}
			
		});
		
		player.load();
	}
}



function animateBackgroundsCSS()
{
	$('.toggler, .mod_newsmenu ul li ul li a').mouseenter(function() {
		$(this).animate({	
		  	backgroundColor: '#E8F0E8',
		  	color: '#666'//'#53A953'
		  },300);
		});
	$('.toggler,  .mod_newsmenu ul li ul li a').mouseleave(function() {
		$(this).animate({
			backgroundColor: '#53A953',
			color:'#fff'
	  	},200);
	});
}


function exposeForms()
{

	var form = $('#mahnbescheid_online, .emailform').bind("click keydown", function() 
	{
		$(this).expose({
					
			color: 	'#333',
			closeSpeed: 	'fast',
			loadSpeed: 	'slow',
			opacity: 	0.8,
			
			// when exposing is done, change form's background color
			onLoad: function() {
				form.css({backgroundColor: '#c7f8ff'});
			},

			// when "unexposed", return to original background color
			onClose: function() {
				form.css({backgroundColor: ''});
			}

		});
	});

}


function animateEyecatcher()
{
	$('.icons-big a .eyecatcher').mouseenter(function() {
	  $(this).animate({
		opacity: 0.65
	  }, 300, function() {
		// Animation complete.
	  });
	});
	
	
	$('.icons-big a .eyecatcher').mouseleave(function() {
	  $(this).animate({
		opacity: 1.0
	  }, 300, function() {
		// Animation complete.
	  });
	});
	
}


function animateNonEyecatcher()
{
	$('img.bt-icons').mouseenter(function() {
	  $(this).animate({
		opacity: 1.0
	  }, 300, function() {
		// Animation complete.
	  });
	});
		
	$('img.bt-icons').mouseleave(function() {
	  $(this).animate({
		opacity: 0.65
	  }, 300, function() {
		// Animation complete.
	  });
	});
	
}


function jQueryTypolightAccordion()
{

     // hide all
      $('.ce_accordion .accordion').hide();

      // open first accordion item
      if ( accordionOpenFirst ) {
         $('.ce_accordion:first').find('.toggler').toggleClass('opened').end()
          .find('.toggler ~ .accordion').slideDown();
      }

      // add onclick event for toggler
      $('.ce_accordion .toggler').click(function() {
         if ( $(this).parent().find('.toggler ~ .accordion').is(":hidden") ) {
            $('.toggler ~ .accordion').slideUp(accordionSpeed);
          //  $('.accordion').fadeOut(fadetime);
            
            $(this).parent().find('.toggler').toggleClass('opened').end()
               .find('.toggler ~ .accordion').slideDown(accordionSpeed);
         } else {
            $('.toggler ~ .accordion').slideUp(accordionSpeed);
         }
      });
}


function gebuehrenRechner()
{
	$('#spinner').fadeOut(0);
	// on change update the values
	$('#calculat0r').change(function() {
		
		fadeGebuehren(true, fadetime);
		$('#spinner').fadeIn(fadetime);
		
		var data_array;
		$.ajax({
			  url: 'dn-calcservice.php',
			  type: 'POST',
			  data: {init:  $('#calculat0r').val()},
			  success: function( rdata ) 
			  {
				data_array = eval(rdata);
				
			  },
			  complete: function()
			  {
					
					$('#field_2').text(data_array[0]).delay(100);
					$('#field_3').text(data_array[1]).delay(200);
					$('#field_4').text(data_array[2]).delay(300);
					$('#field_5').text(data_array[3]).delay(400);
					$('#field_6').text(data_array[4]).delay(500);
					$('#field_7').text(data_array[5]).delay(600);
					
					//$('#spinner').removeClass('ajax-loading');
					fadeGebuehren(false, fadetime);
					$('#spinner').fadeOut(fadetime);
			  }
			});
	});
}	


function fadeGebuehren(fadeout,time)
{
	for (var i=2;i<=7;i++)
	{
		if(fadeout)
		{	
			$('#field_'+i).fadeOut(time);
		}
		else{
			$('#field_'+i).fadeIn(time);
		};
	}
}

function registerInputToggle()
{
	extendJqueryToggleValue();
	
	// contact Form
	$('#ctrl_1').toggleValue('Ihr Name');
	$('#ctrl_2').toggleValue('Ihre Email Adresse');
	$('#ctrl_3').toggleValue('Ihre Nachricht oder Frage zum Mahnbescheid');
	

	$('#ctrl_298').toggleValue('eMail oder Telefonummer');

	//phone form
	$('#ctrl_156').toggleValue('Ihr Name u. Telefonnummer');
	
	$('#ctrl_5').toggleValue('Ihre Suche');
}


function preventEmptySend()
{
  	// submit form
    $('#f19').submit(function() {
	  if($('#ctrl_298').val() == 'eMail oder Telefonummer')
	  {
	  	$('#ctrl_298').animate({	
		  	color: '#53A953'
		  },200).delay(100);	  
	  	$('#ctrl_298').animate({	
		  	color: '#000000'
		  },200).delay(100);
	  	return false;
	  }else{return true;}
	});
		
	// telefonform links
	$('#f12').submit(function() {
	  if($('#ctrl_156').val() == 'Ihr Name u. Telefonnummer')
	  {
  	  	$('#ctrl_156').animate({	
		  	color: '#53A953'
		  },200).delay(100);	  
	  	$('#ctrl_156').animate({	
		  	color: '#000000'
		  },200).delay(100);
	  
	  	return false;
	  }else{return true;}
	});
}

// extend jQuery for toggeling with input fields
function extendJqueryToggleValue(){
	var $j = jQuery;
	$j.fn.extend({
		toggleValue : function (defaultText) 
		{
			return this.each(function() 
			{
				$j(this).focus(function() 
				{
					if ($j(this).val() == defaultText) 
					{
						$j(this).val('');
					}
					$j(this).blur(function () 
					{
						if ($j.trim($j(this).val()) == '') 
						{
							$j(this).val(defaultText);
						}
					});
				});
			});
		}
	});
}





