$(document).ready(function(){
	//$("SELECT").selectbox();
	
	$('INPUT.auto-hint').each(function(i, el){
        if($(this).val() == ''){
            $(this).val($(this).attr('title'));
        }
        $(el).focus(function(){
            if ($(this).val() == $(this).attr('title')) {
                $(this).val('');
            }       
        });
        $(el).blur(function(){
            if ($(this).val() == '') {
                $(this).val($(this).attr('title'));
            }
        });
    });
	$('.menu LI A').each(function(){
		if ($(this).attr('title')) {
			$(this).parent('LI').addClass($(this).attr('title'));
		}
	});
	$('#slider').cycle({ 
		fx:     'fade', 
		speed:   1000, 
		timeout: 5000, 
		pause:   1 
	});
	$('div.wpcf7-response-output').replaceWith('');
	$('.wpcf7').prepend('<div class="wpcf7-response-output wpcf7-display-none"></div>');
	//initContactForm();
});

function initContactForm(){
	$('form#quote').submit(function(){
		
        emptyForm('quote', true);
		var form = $(this);
		var formData = $(this).serialize();
		var error = '';
        
        $('#error_contact').slideUp('normal');
			$.ajax({
                type: 'POST', url: form.attr('action'), data: formData, 
                success: function ( responseData ){
                    if((error = Process(responseData)) != ''){
                        $('#error_contact').html(error);
                        $('#error_contact').css('color','#AD0910');
                        $('#error_contact').css('font-weight','bold');
                        $('#error_contact').slideDown('normal');
                        emptyForm('quote', false);
                    } else{
                        document.getElementById('quote').reset(); 
						window.location = 'http://sandbox.htmlblender.com/bbmandarin/success.html';						
                        $('#error_contact').html('Thank You');
                        $('#error_contact').css('color','green');
                        $('#error_contact').slideDown('normal');                        
                    }
                }
            });		
        
		return false;
	});
}
function emptyForm(id, flag){    
        $('#' + id + ' input, #'+id+' textarea').each(function(){
            if (flag){
                if($(this).val() == $(this).attr('title')){
                    $(this).val('');
                }
            } else {
                if($(this).val() == ''){
                    $(this).val($(this).attr('title'));
                }
            }
        });
}

function Process(str){
	list = str.split(':');
	if(list[0].toLowerCase() != 'done'){
		return list[1];
	} else {
		return '';
	}
}
