var Site = {

	Init : function($) {
	},

	Behaviour: function($) {
		function collaspseAction() {
			$('#jl01').click(
				function(e){
					e.preventDefault();
					$('.list').hide();
					animatedcollapse.show('approach');
					dosIFR();
				}
			);
			$('#jl02').click(
				function(e){
					e.preventDefault();
					$('.list').hide();
					animatedcollapse.show('download');
					dosIFR();
				}
			);
			$('#jl03').click(
				function(e){
					e.preventDefault();
					$('.list').hide();
					animatedcollapse.show('news');
					dosIFR();
				}
			);
			$('#jl04').click(
				function(e){
					e.preventDefault();
					$('.list').hide();				
					animatedcollapse.show('contact');
					dosIFR();
				}
			);
		}

		if ($('body.home .list').size() > 1){
			Site.Effects($);
			collaspseAction();
		} else {
			$('body.base div.list').show();
		}

		Site.CntForm($);

	},

	Effects: function($) {
		function collapseInit() {
			animatedcollapse.addDiv('approach', 'fade=1,speed=800,group=listing,hide=1');
			animatedcollapse.addDiv('download', 'fade=1,speed=800,group=listing,hide=1');
			animatedcollapse.addDiv('news', 'fade=1,speed=800,group=listing,hide=1');
			animatedcollapse.addDiv('contact', 'fade=1,speed=800,group=listing,hide=1');
			animatedcollapse.init();
		}
		collapseInit();
	},

	CntForm: function($) {
		function checkForm(){
			var container = $('div.error');
			$("form#cntForm").validate({
					errorContainer: container,
					errorPlacement: function(error, element) {
					$('.valid').parent().find('p.validation').hide();
					element.parent().find('p.validation').show();
			},
			submitHandler: function(form) {
					jQuery("form#cntForm").fadeOut();
					jQuery(form).ajaxSubmit({
					success: function(responseText) {
							jQuery("div.error").after("<div class=\"success\"></div>");
							jQuery("div.success").html("<h4>Thanks</h4><p>Your message has been successfully sent over to us</p>");
							}
						});
					}
		        });
		}
		function CntForminit() {
			$('#contact .error').hide();
			$('.validation').hide();
			checkForm();		
		}
		CntForminit();
	},

	Settings: function($) {
		jQuery("a.popup").click(
			function(event) {
				event.preventDefault();
				window.open($(this).attr("href"));
			}
		);
	},
	
	Overlabel: function($) {
		jQuery("label[for='edmSignup']").overlabel();
	},
	
	ValidateEDM: function($) {
		jQuery("#edmsignupform").validate({
			errorClass: "error",
			validClass: "valid",
			highlight: function(element, errorClass, validClass) {
				$(element).closest('.validate').addClass(errorClass).removeClass(validClass);
			},
			unhighlight: function(element, errorClass, validClass) {
	 			$(element).closest('.validate').addClass(validClass).removeClass(errorClass);
			},
			rules: {
				edmSignup: {
					required: true,
					email: true
				}
			},
			messages: {
				edmSignup: {
					required: "We need your email address to contact you",
					email: "Your email address must be in the format of name@domain.com"
				}
			},
			invalidHandler: function(form, validator){		
				$(validator.invalidElements()[0]).focus();			
			},
			focusInvalid:false
		});
	},	

	FadeMsg: function($){
		setTimeout(function(){
			$("#edmsignup .msg").fadeOut("slow", function () {
				$("#edmsignup .msg").remove();
			});
		}, 5000);
	}

};


jQuery(document).ready(function($){
	Site.Init($);
	Site.Behaviour($);
	Site.Settings($);
	Site.Overlabel($);
	Site.ValidateEDM($);
	Site.FadeMsg($);
});
