$(document).ready(function(){

	if($("form.validate").length) {

		$("form.validate").submit(function() {

			$(".alert", this).removeClass("alert");

			var msg = '';
			var valid = true;
			var email_pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/i;

			//$(this).find(".required").each(function() {
			$(this).find(".required").not('span,p,div').each(function() {
				var value = $(this).val();
				if(value == "" || ($(this).prop("title") && value == $(this).prop("title")) || ($(this).is(".email") && !email_pattern.test(value))) {
					valid = false;
					var label = $(this).prev("label").text() || $(this).prop("title");
					msg += '\n-  '+label.replace(/[\*|:]/gi, "")+' is mandatory!';
					$(this).addClass("alert");
				}
			});

			if(!valid) {

				if(msg != '') {
					alert('Please fill in the following mandatory fields. Thank you.'+msg);
					$(".alert:first", this).focus();
					return false;
				}

				return false;
			}
		});

		$("form.validate input, form.validate textarea").bind("focus", function(){
			$(this).addClass("focus");
			if($(this).val() == $(this).attr("title")) {
				$(this).val("");
			}
		});

		$("form.validate input, form.validate textarea").bind("blur", function(){
			$(this).removeClass("focus");
			if($(this).val() == "") {
				$(this).val($(this).attr("title"));
			}
		});

		$("form.validate .submit").click(function(e){
			e.preventDefault();
			$(this).closest("form").submit();
		});

	}

	if($("hr").length) {
		$("hr").replaceWith('<div class="hr"></div>');
	}
	
	$("#twitter").load($("#twitter").attr("rel"));

});

// Contact custom select

	$(document).ready(function(){	

		if (!$.browser.opera) {
    
			// select element styling
			$('select.select').each(function(){
				var title = $(this).attr('title');
				//if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
				title = $('option:selected',this).text();
				$(this)
					.css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
					.after('<span class="select">' + title + '</span>')
					.change(function(){
						val = $('option:selected',this).text();
						$(this).next().text(val);
						})
			});

		};
		
	});
