var footLoad = false;
function showFooterDiv(href){
	$('.Div').hide();
	$('#contactTable').hide();
	
	var tmp = href.split('#');
	$('#' + tmp[1]).show().children().show();
	if(tmp[1] == 'contact'){
		$('#contactTable').show();
	}
	if(tmp[1] == 'about'){
		$("#about ul a.cur").removeClass("cur");
		$("#about ul li:first-child a").addClass("cur");
		$('#about-2').hide();
		$('#img', '#about').hide();
	}
	if(home){
		$('.Div').addClass("ishome").css('height', 346);
	}else{
		$('.Div').removeClass("ishome").css('height', 404);
	}
}
$(document).ready(function(){
	$('.menuLink, .showImg').click(function(){
		$('.Div, #contactTable').hide()
	});
	$('#footer ul li a').click(function(){
		if(footLoad == false){
			var tmp = this;
			$.get('/footer', function(data){
				$('#content').append(data);
				showFooterDiv(tmp.href);
				footLoad = true;
			});
		}else{
			showFooterDiv(this.href);
		}
		return false;
	});
	$('.close').live('click', function () {
		$(this).parent().hide();
		$('#contactTable').hide();
		return false;
	});
	$('#contactTable input.send').live('click', function(){
		if(test()){
			var d = '';
			$('input:not(.send), textarea', '#contactTable').each(function(i){
				d += this.name + '=' + this.value + '&';
			});
			$.post('/send', d, function(a){
				if(a == 1){
					$('input:not(.send), textarea', '#contactTable').each(function(i){
						this.value = '';
					});
					$('.i_3').css('background-image', 'url(/_graphics/input4.png)');
				}
			});
		}
		return false;
	});
	$('#contactTable input:not(.send)').focusout(function(){
		test();
	});
	$('#about ul li a').live('click', function(){
		var tmp = this.href.split('#');
		$('#about div').hide();
		$('#about ul li a').removeClass('cur');
		if(tmp[1] == 'about-2'){
			$('#about #img').show();
		}
		$(this).addClass('cur');
		$('#' + tmp[1]).show();
	});
});
function test(){
	var r = true;
	$('span.error').hide();
	$('#contactTable input:not(.send)').each(function(i){
		if(this.name == 'f_name' && this.value == ''){
			$('span.error:eq(0)').show();
			r = false;
			return false;
		}
		if(this.name == 'l_name' && this.value == ''){
			$('span.error:eq(1)').show();
			r = false;
			return false;
		}
		if(this.name == 'email'){
			var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
			if(!reg.test(this.value)){
				$('span.error:eq(2)').show();
				r = false;
				return false;
			}
		}
	});
	return r;
}
