$(function() {    	
     // tabs
	
     $('.tabs a').amTabs();
     
     // mediaelement     	 
     $('video').mediaelementplayer();
     
     $('#dekoboko_name, #dekoboko_subject, #dekoboko_email, #dekoboko_message').addClass('litegray'); 
     
     // form validation name
     $('#dekoboko_name, #dekoboko_subject, #dekoboko_message').focus(function() {
     	if ($(this).val() == $(this).attr('title')) {
     		$(this).val("");
     	}	
     	$(this).removeClass('form-error').removeClass('litegray').addClass('darkgray');
     });
     
     $('#dekoboko_name, #dekoboko_subject, #dekoboko_message').blur(function() {
     	$(this).removeClass('darkgray').addClass('litegray');
     	var id = $(this).attr('id');
     	var fieldname;
     	switch (id) {
     		case "dekoboko_name":
     			fieldname = "Name";
     			break;
     		case "dekoboko_subject":
     			fieldname = "Subject";
     			break;
     		case "dekoboko_message":
     			fieldname = "Message"
     			break;	
     	}
     	if (($(this).val().length <= 0) || ($(this).val() == $(this).attr('title'))) {
     		$(this).next('span.response').text(fieldname + ' is required').fadeIn('slow');
          	$(this).addClass('form-error').val($('#' + id).attr('title'));
     	}
     	else {
     		$(this).next('span.response').text(fieldname + ' looks good!').fadeIn('slow');
     	}
     });   
     
     // form validation email     
     $('#dekoboko_email').focus(function() {
     	if ($(this).val() == $(this).attr('title')) {
     		$(this).val("");
     	}
     	$(this).removeClass('form-error').removeClass('litegray').addClass('darkgray');
     });
     
     $('#dekoboko_email').blur(function() {
     	$(this).removeClass('darkgray').addClass('litegray');
     	if(validateEmail('dekoboko_email')) {
          	$(this).next('span.response').text('Email looks good!').fadeIn('slow');
      	}
      	else {
          	$(this).next('span.response').text('Invalid email address').fadeIn('slow');
          	$(this).addClass('form-error');
          	if ($(this).val().length <= 0) {
          		$(this).val($(this).attr('title'));
          	} 
      	}
  	 });
  	 
  	 // expand textarea as user types 
  	 $('#dekoboko_message').inputexpander();
  	 
  	 // rounded corners for ie
     //$('.thumbnail img, #medium_image img, .slide_image').corner("4px");
  	 
});

function validateEmail(email){
	var a = document.getElementById(email).value;
   	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
    if(filter.test(a)) {
        return true;
    }
    else{
        return false;
    }
}
