$(function(){
    //OVER class on all inputs
    $("input").focus(function(){
         $(this).addClass('over');
    });
    $("input").blur(function(){
         $(this).removeClass('over');
    });
    
    if($.cookie('player') == 'off') $("a#switch").text('ON');
    $("a#switch").toggle(
        function(){
            $(this).text('ON');
            $("#sound_player").jPlayer("stop");
            $.cookie('player', 'off', { path: '/'});
        }, 
        function(){
            $(this).text('OFF');
            $("#sound_player").jPlayer("play");
            $.cookie('player', 'on', { path: '/'});
        }
    );
    $('#sound ul li a').click(function(){
        var new_track = $(this).attr('href');
        
        $('#sound ul li a').removeClass('active');
        $(this).addClass('active');
        $("a#switch").text('OFF');
        $("#sound_player").jPlayer("setFile", MUSIC_URL+new_track).jPlayer("play");
        $.cookie('player', 'on', { path: '/'});
        return false;
    });

});


//send ajax EMAIL CONTACT
function sendMail(form_id) {
var params = $("form#"+form_id).serialize();
	$.post(PROJECT_URL + "sendmail.php", params ,
		function (data) {
			show_error(data);
		}
	);
}
function show_error(msg){
    showError(msg);
}
function show_message(msg){
    alert(msg);
}
// param: text is array like ['message 1', 'message 2', 'message 3'] or string like 'message1'
function showError(text, hide){
    $('#messages_cont').hide();
    $('#errors_cont').hide();
    
    // clear the li elements and fill with text
    $('#display_errors ul').empty();
 	
    if (typeof text == 'string'){
    	$('#display_errors ul').append('<li>' + text + '</li>');
    }
    else{
	    for(key in text){
	    	$('#display_errors ul').append('<li>' + text[key] + '</li>');
	    }
    }

    $('#display_errors_cont').fadeIn('slow');
    $('#errors_icon').fadeIn('slow');
    $('#errors_cont').fadeIn('slow');
    
    if (hide) setTimeout("hideError();", 3500);
}

function hideError(){
	$('#display_errors_cont').fadeOut('slow');
	$('#errors_icon').fadeOut('slow');
	$('#errors_cont').fadeOut('slow');
}

function showMessage(text, hide){
    $('#messages_cont').hide();
    $('#errors_cont').hide();
    
    // clear the li elements and fill with text
    $('#display_messages ul').empty();
 	
    if (typeof text == 'string'){
    	$('#display_messages ul').append('<li>' + text + '</li>');
    }
    else{
	    for(key in text){
	    	$('#display_messages ul').append('<li>' + text[key] + '</li>');
	    }
    }

    $('#display_messages_cont, .ui-icon-close, #messages_cont').fadeIn('slow');
    
    if (hide) setTimeout("hideMessage();", 3500);
}

function hideMessage(){
	$('#display_messages_cont, .ui-icon-close, #messages_cont').fadeOut('slow');
}
