$(document).ready(function()
{	
	//$(document).pngFix(); 
	var oValidate = new validate(); 
	var emailriddlerarray=[105,110,102,111,64,109,97,97,116,99,111,100,101,46,110,108];
	var encryptedemail_id28='';  
	for (var i=0; i<emailriddlerarray.length; i++)
	 encryptedemail_id28+=String.fromCharCode(emailriddlerarray[i])
	$('#mail-link').attr('href', 'mailto:'+encryptedemail_id28);	 
	$('#submit-mail').click(function() 
	{
		mail(this);
		return false;
	});	
	$('.scroll-page').click(function() {
		var elementClicked = $(this).attr("href");
		var destination = $(elementClicked).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
		return false;
	}); 	
	
	$('#domain').focus(function (){
		$('.response', $('#domain-form fieldset')).slideUp('slow', function (){
			$(this).remove();
		})		
	})
	$('#domain').keyup(function (){
		if(oValidate.isDomain($(this).val()))
		{
			$(this).css('background', 'url("/images/bg-transparency.png") repeat scroll 0 0 #B4B7B2')
		}
		else 
		{
			$(this).css('background-color', '#CC9999')
		}	
				
	})
	$('#submit-domain').click(function() 
	{
		checkDomain()
		return false;
	})	
	fetchRss($('#rss-selector').val());
	$('#rss-selector').change(function() 
	{
		fetchRss(this.value);
	});
	$('#navigation-bar a').tooltip({
		track: true,
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    fade: 250
	});
	$('#slide-show').cycle({ 
	    fx:    'shuffle',
	    delay: 1000,
	    speed: 200,
	    shuffle: { 
	        top:  -230, 
	        left:  230 
	    }
	});

	if($.browser.opera)
	{		
		/* opera overflow hack */
		$('#header .box-2 .inner-box').css('width', ($('#header .box-2 .inner-box').width() - 116) + 'px');		
	}
	
});
function fetchRss(url)
{		
	$('#rss-response').html('<img id="mail-loading" src="/images/loadingAnimation.gif" alt="Laden..." />');
	$.get('/index/rss/?url='+url, function(data)
	{				
		$('#rss-response').html(data);
		$('#rss-response a').tooltip({
			track: true,
		    delay: 0, 
		    showURL: false, 
		    showBody: " - ", 
		    fade: 250
		});
	});		
}
function mail(submitButton)
{
	$('.message-box').remove();
	$('#mail-form p:not(last)').slideUp('fast', function () {
		$(this).remove();
	})
	showLoading($('#mail-form fieldset'));
	$.post("/contact", $('#mail-form').serialize(), function(data)
	{
		if(data != null)				 
			showMessage($('#mail-form fieldset'), data.message, data.result)
	}
	, 'json');			
}






function checkDomain()
{	
	resetDomain();	
}
function fetchDomain () 
{
	var container = $('#domain-form fieldset');
	$(container)				
		.append($(document.createElement('p'))		
		.html('<img src="/images/loadingAnimation.gif" alt="Laden..." />')
		.addClass('loading-box')
		.slideDown('fast', function (){			
			$.post('/index/domain', $('#domain-form').serialize(), function(data)
			{	
				if(data != null)						
					showMessage(container, data.message, data.result)
			}
			, 'json')
		})
	)
}
function showLoading(container)
{	
	if ( ! $('.loading-box', container).length)
	{
		var p = $(document.createElement('p'))		
			.html('<img src="/images/loadingAnimation.gif" alt="Laden..." />')
			.addClass('loading-box')
			.slideDown('fast');	
		$(container).append(p);
	}
}
function resetDomain(container)
{	
	var response = $('#domain-form fieldset .response'); 
	if ($(response).length > 0)
	{
		$(response).slideUp('fast', cdRemoveResponse);
	}
	else 
	{
		fetchDomain();
	}				
}
function showMessage(container, message, result)
{		
	$('.loading-box', container)	
		.slideUp('fast', function () {
			if ( ! $('.response', container).length)
			{	
				$(container).append($(document.createElement('p'))
					.addClass('response')
					.addClass(result?'success':'failure')
					.slideDown('fast')
					.html(message));
			}
		})					
		
}	

$.waitForNAnimations = function(numberOfAnimations,callback) 
{
	var count = 0;
	function cb() 
	{
		count++;
		if ( count == numberOfAnimations) {
			count = 0;
			callback();
		}
	}
	return cb;
}
cdRemoveResponse = $.waitForNAnimations(1, function () {
	removeLoading();
	fetchDomain();
});
function removeLoading() 
{
	$('#domain-form fieldset .response').remove()
	$('#domain-form fieldset .loading-box').remove();	
};








function imageSpace() 
{
 	$('img').each(function ()
 	{
 		var vspace = $(this).attr('vspace');		
 		if(vspace>0)
 		{			
 			$(this).removeAttr('vspace');
 			$(this).css('marginTop', vspace)	
 			$(this).css('marginBottom', vspace)
 		}
 		var hspace = $(this).attr('hspace');
 		if(hspace>0)
 		{
 			$(this).removeAttr('hspace');
 			$(this).css('marginLeft', hspace)	
 			$(this).css('marginRight', hspace)
 		}		
 		var align = $(this).attr('align');
 		switch (align)
 		{
 			case 'left':
 			case 'right':
 				$(this).css('float', align);break;
 			case 'absBottom':
 				$(this).css('vertical-align', 'bottom');break;
 			case 'absMiddle':
 				$(this).css('vertical-align', 'middle');break;
 			case 'baseline':
 				$(this).css('vertical-align', 'baseline');break;
 			case 'bottom':		
 				$(this).css('vertical-align', 'bottom');break;
 			case 'middle':
 				$(this).css('vertical-align', 'middle');break;
 			case 'textTop':
 				$(this).css('vertical-align', 'text-top');break;
 			case 'top':		
 				$(this).css('vertical-align', 'top');break;
 		}				
 	}) 	
}
 
