$(function(){
	// Bind clicks
	var state = 0;
	$('.service_element').click(function(e){
		if(state == 1) {
			$('.service_content_text').hide();
			$('.service_button').hide();
			$('#'+$(this).attr('id')+'_content').slideDown();
			$('.service_button').fadeIn();
		}
		if(state == 0) { 
			state = 1;
			mboxUpdate('Kwantic/Beta_Services_CTR');
			$('.service_button').fadeIn();
			$('#'+$(this).attr('id')+'_content').fadeIn();
			$('#service_content').slideDown('slow')			
			$('#service_content_closer').fadeIn();
		}
		//alert($(this).position().left)
		var c_pos = $('.content').position().left;
		var pos = $(this).position().left-c_pos+$(this).width()/2;
		$('#service_content_arrow').hide().css('margin-left',pos-12).fadeIn();
	})
	
	$('#service_content_closer').click(function(e) {
		
		$('#service_content').slideUp();
		$('.service_content_text').fadeOut();
		state = 0;
		e.preventDefault();
	})
	
	var state_2 = 0;
	$('.teaser_element').click(function(e){
		if(state_2 == 1) {
			$('.teaser_content_text').hide();
			$('.teaser_button').hide();
			$('#'+$(this).attr('id')+'_content').slideDown();
			$('.teaser_button').fadeIn();
		}
		if(state_2 == 0) { 
			state_2 = 1;
			mboxUpdate('Kwantic/Beta_Services_CTR');
			$('.teaser_button').fadeIn();
			$('#'+$(this).attr('id')+'_content').fadeIn();
			$('#teaser_content').slideDown('slow')			
			$('#teaser_content_closer').fadeIn();
		}
		//alert($(this).position().left)
		var c_pos = $('.content').position().left;
		var pos = $(this).position().left-c_pos+$(this).width()/2;
		$('#teaser_content_arrow').hide().css('margin-left',pos-12).fadeIn();
	})
	
	$('#teaser_content_closer').click(function(e) {
		
		$('#teaser_content').slideUp();
		$('.teaser_content_text').fadeOut();
		state_2 = 0;
		e.preventDefault();
	})

	$('#teaser_content_contact').click(function(e){
		window.location = '#contact';
	})
	$('#service_content_contact').click(function(e){
		window.location = '#contact';
	})
	// Contact form
	$('#submit').click(function(e){
		/*$.post("mail.php", $("form").serialize(),function(ret) {
			if(ret == '1') {
				$("form").html('<h1>Thank you! We will contact you shortly.</h1>');
				mboxUpdate('Kwantic/Beta_Form_Submission');
			}
			if(ret == '3') alert('Please fill all the fields!');
			if(ret == '2') alert('Something went wrong - we are investigating...');
		});*/
		if(!$('#company').val() || !$('#url').val() || !$('#message_field').val() || !$('#title').val() || !$('#first_name').val() || !$('#last_name').val() || !$('#mobile').val()) {
			alert('Please fill all the fields!');
			return false;	
		}
		//e.preventDefault();
	})
})
