/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function(){
    $('body').addClass('hasJS');
	var Revealer = function(relativeParent,absoluteChild,speed) {
		var revealHeight = absoluteChild.height();
		relativeParent.height(revealHeight);
		relativeParent.addClass('hidden');
		this.toggleReveal = function() {
			if (!relativeParent.parent().find(':animated').length) {
				if (relativeParent.css('display')!='none' ) {
	        		relativeParent.animate({height:0}, speed, function() {
						relativeParent.hide();
					});
				} else {
	        		relativeParent.height(0).show().animate({height: revealHeight}, speed);
				}
			}
		};
	};

	$('#contact').after($('#contact-form'));
    $('#submit').removeAttr('disabled');

	var contactForm = new Revealer(
		$('#contact-form .flow'),				// the relatively positioned container
		$('#contact-form .flow .contents'),		// the absolutely positioned child
		300										// the speed of the animation
	);
    var subscribeForm = new Revealer(
		$('#subscribe_form .flow'),				// the relatively positioned container
		$('#subscribe_form .flow .contents'),		// the absolutely positioned child
		300										// the speed of the animation
	);

	$('.contact-link').live('click',function(){
	    $('html, body').animate({scrollTop:0}, 'fast');
        contactForm.toggleReveal();
		return false;
	});
    
    $('.subscribe-link').live('click',function(){
	    
        subscribeForm.toggleReveal();
		return false;
	});

	$('#contact-form button[type="reset"]').live('click',function(){
        contactForm.toggleReveal();
		return false;
    });
    $('#subscribe_form button[type="reset"]').live('click',function(){
        subscribeForm.toggleReveal();
		return false;
    });
    $('#contact-form form').live('submit',function(){
		var values = $(this).serialize();
        $('#submit').attr('disabled', 'disabled');
        $('#submit').html('Posielam...');
		$.post('/contact.html',values,function(markup) {
			$('#contact-form .contents').html(markup);
            
		},'html');
		return false;
	});
	$('#subscribe_form form').live('submit',function(){
		var values = $(this).serialize();
        $('#sf_submit').attr('disabled', 'disabled');
        $('#sf_submit').html('Posielam...');
		$.post('/newsletter/subscribe',values,function(markup) {
			$('#subscribe_form .contents').html(markup);
            var revealHeight = $('#subscribe_form .flow .contents').height();
             $('#subscribe_form .flow').height(revealHeight);
            
		},'html');
		return false;
	});
});


