$(document).ready(function(){ 
	
	$('.images').cycle();
	//variables
	var contain = $('#main');
	var section = contain.children('.accordion');
	var section_name = $('.accordion h1');
	var pagecontent = $('.accordion .content');
	
	var s_minheight = 31;
	var s_maxheight = 507;

	//startup	
	expand(section.eq(0));

	
	//events
	section_name.click(function(){
		expand($(this).parent());
		return false;
	});
	
	//show/hide
	$('a.showhide').click(function(){

	var current = $(this).html();

		if (current == "show text") {
			$(this).parent().children('.content').slideDown();
			$(this).html("hide text");		
		} else {
			$(this).parent().children('.content').slideUp();
			$(this).html("show text");
		}
		return false;
	});

	
	
	
	
	//expand section elements
	function expand(element){
		if(!element.hasClass('current')){
			
			//out
			$('.current')
			.animate({
				height: s_minheight
			},{queue: false})
			.children('.showhide').hide()
			.parent().children('h1').children('.arrow')
			.css({width: 4, backgroundPosition: "right"});
			
			
			$('.current').removeClass('current');
			
			
			//in
			element
			.animate({
				height: s_maxheight
			},{queue: false})
			.addClass('current')
			.children('.showhide').show()
			.parent().children('h1').children('.arrow')
			.css({width: 7, backgroundPosition: "left"});
			
				
		}
	}
	
	$('#enquire').submit(function(){
				var e_name = $('#form input').eq(0).val();
				var e_tel = $('#form input').eq(1).val();
									  
				$.post("media/php/mail.php",{name: e_name, telephone: e_tel}, function(data){
					if(data == "complete") {
						
						$('#return').html('your name and telephone were send successfully');
											
					} else {
						
						
						$('#return').html("There was a problem with your submission");						
					}
		});
		return false;
	});

	

});
