$().ready(function(){
	
	/*$('#offer li a').click(function(){
		
		var href = $(this).attr('href');
		
		var rollDown = function()
		{
			$('#offer div'+href+'.offer-content').slideDown(1000);
		}
		
		if($('#offer div.offer-content:visible').length > 0)
		{
			$('#offer div.offer-content').slideUp(1000);
			
			setTimeout(rollDown, 1000);
		}
		else
		{
			rollDown();
		}
		
	});*/
	
	$('#offer').tabs({
		fx: {height: 'toggle'}, selected: -1, collapsible: true
	});
	
	$('a.contact-open').click(function(){
		
		$('#overlay').show();
		$('#contact-window').slideDown(500);
		
	});
	
	$('a#contact-close, #overlay').click(function(){
		
		$('#contact-window').slideUp(500).delay(500);
		
		setTimeout("$('#overlay').hide();", 501);
		
		
		return false;
		
	});
	
	$('form#contact-form').submit(function(){
		
		$(this).find('input#contact-submit').hide();
		$(this).find('#submit-box p.sending').show();
		
		$(this).find('p.error').remove();
		
		$.ajax({
			async: true,
			url: '/ajax/contact',
			type: 'post', 
			dataType: 'json',
			data: {
				ajaxRequest:1,
				contact_submit: 1,
				name: $(this).find('input#name').val(),
				email: $(this).find('input#email').val(),
				category: $(this).find('select#category option:selected').val(),
				topic: $(this).find('input#topic').val(),
				text: $(this).find('textarea#text').val()
			},
			error: function(a,b,c)
			{
				alert("Przepraszamy wystąpił błąd. Skontaktuj się z nami pod adresem kontakt@zeno.pl.");
			},
			success: function(data)
			{
				if(data.systemError)
				{
					alert("Przepraszamy wystąpił błąd. Skontaktuj się z nami pod adresem kontakt@zeno.pl.");
				}
				
				if(!data.wasSent)
				{
					$.each(data.errors, function(fieldname, error){
						
						var div = $('form#contact-form #'+fieldname).parent();
						
						div.append('<p class="error">'+error+'</p>');	
						
					});
					
					$('form#contact-form').find('#submit-box p.sending').hide();
					$('form#contact-form').find('input#contact-submit').show();
				}
				else
				{
					$('form#contact-form').find('#submit-box p.sending').hide();
					$('form#contact-form').find('#submit-box p.sent').show();
				}
			}
		});
		
		return false;
		
	});
	
});

