$(document).ready(function() {
	$('a.wordhints').colorbox();
});
var webConfig = {};

var WebApi = {
	// default text dictionary 
	defTextDic : ['Straße und Ort, PLZ oder Ort', 'Vorname', 'Nachname', 'E-Mail', 'Suche', 'Name*',
		'E-Mail*','Betreff*', 'Geburtsdatum (TT.MM.JJJJ)*', 'Postleitzahl*', 'Adresse*', 'Nachname*',
		'Vorname*', 'Ort*', 'Ort', 'E-Mail Adresse*', 'PLZ eingeben', 'Name des Empfängers*', 
		'E-Mail Adresse des Empfängers*', 'Ihr Name*', 'Ihre E-Mail*', 'E-Mail Addresse des Empfängers*',
		'Telefon','Ort oder Postleitzahl'], 
	
	initDefaultValueOfField:function(fields)
	{
		$.each($(fields), function() {
			var label = $("label[for='" + $(this).attr("id") + "']");
			if (label.hasClass('dynform') && $(this).val() != '') { 
				label.hide(); 
			}
		});

		$(fields).keyup(function(){
			var label = $("label[for='" + $(this).attr("id") + "']");
			if (label.hasClass('dynform')) {
				if ($(this).val() != '') {
					label.hide();
				} else {
					label.show();
				}
			}
		});

		if ($(this).attr('type') != 'password') {
		$(fields).focusin(function(){
			var index = WebApi.defTextDic.indexOf($(this).val());
			if (index > -1) {
				$(this).attr('data-defaultText',WebApi.defTextDic[index]);
				$(this).attr('value','');
			} 
		});
		$(fields).focusout(function() {
			if ($(this).attr('data-defaultText') != '' && $(this).attr('value') == '') {
				$(this).attr('value',$(this).attr('data-defaultText'));
			}
		});
		}
	},
	
	colorboxForm:function(selector, callback) {
		if (typeof callback == 'undefined')
			callback = function(){};
		var form = $(selector);
		WebApi.initDefaultValueOfField($('input', form));
		$('input[type="submit"]', form).click(function(){
			var form = $(this.form);
			$.colorbox({
				href:form.attr('action'),
				data:form.serializeArray(),
				onComplete: function() {
					WebApi.colorboxForm(selector, callback);
					callback();
				}
			});
			return false;			
		});
	},
	
	loadFacebookFanbox:function()
	{
		// $('#fb-frame').attr('src',webConfig.fbb_src);
		$('.box-facebook').html('<iframe id="fb-frame" src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FAv%25C3%25A8ne-Deutschland%2F160632553984079&width=285&colorscheme=light&show_faces=true&border_color&stream=true&header=false&height=595" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:285px; height:595px;" allowTransparency="true"></iframe>');
	},
	
	bindConfirmation:function()
	{
		$('a.confirm').click(function(){
			return confirm('Sind Sie sicher?');
		});
	},
	
	bindSlideToggle:function()
	{
		$('a.link-expand').click(function () {
			$(this).parent().next('.div-expand').slideToggle();
			return false;
		});
	},
	
	showPreloader:function(el)
	{
		el = $(el);
		pos = el.position();
		var preloader = $("<div/>");
		preloader.attr('class','preloader');
		preloader.css('top', pos.top);
		preloader.css('left', pos.left);
		preloader.css('width', el.width());
		//var height =  el.height() > 0 ? el.height() : 50;
		preloader.css('height', el.height());
		$('body').append(preloader);
		return preloader;
	},
	
	printPage:function() 
	{
	   if (!window.print){
	      alert("Your browser can't print");
	      return 0;
	   }
	   window.print();
	}

};

$(document).ready(function() {
	WebApi.initDefaultValueOfField($('input:text'));
	WebApi.loadFacebookFanbox();
	WebApi.bindConfirmation();
	WebApi.bindSlideToggle();
	
	$('.print').click(function(){
		WebApi.printPage();
		return false;
	});
	
	if(!FlashDetect.installed){
		$('#logo-flash').remove();
		$('#logo-no-flash').show();	
	} 
});
