$(document).ready(function(){
	$('#aNotification').bind('click',function(e){
		var tmpKats = $('#tmpKats').html();
		var tmpKeyword = $('#tmpKeyword').html();
		$.ajax({
			type: "POST",
			url: "http://" + window.location.hostname + "/ajax_php/benachrichtigung.php",
			data: {kats: tmpKats, keyword: tmpKeyword},
			dataType: "html",
			beforeSend: function(){
				window.scrollTo(0,0);
				$('#detLayer, div[class=detLayer]').customFadeIn("fast");
				$('#detLayerFormLoad').customFadeIn('fast');
			},
			success: function(html){
					$('#detLayerFormLoad').customFadeOut('fast');
					$('#detLayerContentNotification').html(html).customFadeIn("fast", function(){
					fnBindNotificationFormHandel();
				});
			}
		});
	});
	
	function fnBindNotificationFormHandel()
	{
		$('a[id=aLayerClose]').each(function(i){
			$(this).bind('click', function(e){
				$('#detLayer, div[class=detLayer]').customFadeOut("fast");
				$('#detLayerContentNotification').customFadeOut();
			});
		});
		var options = { 
				beforeSubmit:  showRequestState,
				success:       fnBindNotificationFormHandel,  
				target:	'#detLayerContentNotification',
				url: 		'http://' + window.location.hostname + '/ajax_php/benachrichtigung.php'
		};
		$('#frmRequest').ajaxForm(options); 
	}
	
	function showRequestState(formData, jqForm, options) { 
		
		if($("*").index($('#msg_error')[0])!="-1"){
			$('#msg_error').customFadeOut('fast', function(){
				$('#anfrageAction').customFadeIn('slow');
			});	
		}else{
			$('#anfrageAction').customFadeIn('slow');
		}
    return true; 
	}

	(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	})(jQuery);
});