$(document).ready(function(){

	$('.chat a').click(function(e) {
		/*
e.preventDefault();
		if ($('#lpButDivID-1326771461138').is(':visible')) {
			$('#lpButDivID-1326771461138').hide();
		}
		else {
			$('#lpButDivID-1326771461138').show();
		}
*/
	});
	
	$('#contact-submit').click(function(e) {
		e.preventDefault();
		if ($('input[name=name]').val() != '' &&
		    $('input[name=email]').val() != '' &&
		    validate_email($('input[name=email]').val())) {
		    $('#contact-form').hide();
			$('.ribbon .message').show();
			_gaq.push(['_trackPageview', thank_you_page]);
			$.post(
				template_dir+'/ajax.php', {
					name : $('input[name=name]').val(),
					email : $('input[name=email]').val(),
					phone : $('input[name=phone]').val(),
					action : 'contact'
					},
				function (data) {
				window.location = thank_you_page;
			});
			$('input[name=name]').val('');
			$('input[name=email]').val('');
			$('input[name=phone]').val('');
		}
	});

	$("input[type=text][holder!=''],input[type=password][holder!='']").each(function(){
            var field = $(this);
            var ffield = $(field).attr("id")+"__jquery_placeholder_passwordFakeField";
            //add holding class
            $(field).addClass("holder");
            //replace password fields with a fake field
            if ($(field).attr("type") == "password") {
                var newfield  = $("<input type='text' class='"+$(field).attr("class")+"' id='"+ffield+"' tabindex='"+$(field).attr("tabindex")+"' holder='"+$(field).attr("holder")+"' />").focus(function() {
                                    $(this).hide();
                                    $(field).show();
                                    $(field).focus();
                                }).keypress(function(event) {
                                    event.preventDefault();
                                });
                $(newfield).insertBefore(field);
                $(field).hide();
            }
            //bind focus event
            $(field).bind("focus",function() {
                $("#"+ffield).hide();
                $(field).show();
                if ($(field).hasClass("holder")) {
                    $(field).val("");
                    $(field).removeClass("holder");
                }
            });
            //bind blur event, if is a password field and value='' show the fakefield
            $(field).bind("blur",function() {
                if ($(field).val() == "") {
                    if ($(field).attr("type") == "password") {
                        $(field).hide();
                        $("#"+ffield).show();
                    }
                    else {
                        $(field).val($(field).attr("holder"));
                        $(field).addClass("holder");
                    }
                }
            });
            //bind change event, if value changed return to non holding state
            $(field).bind("change",function() {
                $(field).removeClass("holder");
            });
            //bind parent form submit, clean holding fields
            $(field).parents("form").submit(function() {
              $(this).find(".holder'").each(function() {
                if ($(this).val() == $(this).attr("holder")) { $(this).val(""); }
              });
            });         
    });
    setTimeout("__jquery_placeholder_goTitling()",100);
	
	// Placeholder Functionality
	/*
	$('[placeholder]').focus(function() {
		var input = $(this);
		if (input.val() == input.attr('placeholder')) {
	    	input.val('');
	    	input.removeClass('placeholder');
	    }
	    input.val('');
	}).blur(function() {
		var input = $(this);
		if (input.val() == '' || input.val() == input.attr('placeholder')) {
	    	input.addClass('placeholder');
	    	input.val(input.attr('placeholder'));
	  	}
	  	input.val('');
	}).blur();

	// IE Placeholder Fallback
	function elementSupportsAttribute(element, attribute) {
		var test = document.createElement(element);
		if (attribute in test) {
			return true;
		} else {
			return false;
		}
	};
	*/
	
	/*
	$('input[name=name]').attr('placeholder', 'Your name');
	$('input[name=email]').attr('placeholder', 'Email address');
	$('input[name=phone]').attr('placeholder', 'Phone number');
	*/
	
	/*
	$('input[name=name]').val('Your name');
	$('input[name=email]').val('Email address');
	$('input[name=phone]').val('Phone number');
	*/
	
	//$('input[type=text]').focus(function() { $(this).val(''); });
	
});

function __jquery_placeholder_goTitling() {
    $("input[type=text][holder!=''][value='']").each(function(){
        $(this).val($(this).attr("holder"));
        $(this).addClass("holder");
    });
}

function validate_email($email) {
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    if( !emailReg.test( $email ) ) {
    	return false;
    } else {
    	return true;
    }
}

