/*
*************************************************

FOUR24, VERSION 5
JavaScript Functions (requires jQuery)

Created by the ridiculous Dan Mall
http://www.danielmall.com/

*************************************************
*/


/*-------------------------------------------    
    Global Variables
-------------------------------------------*/


/*-------------------------------------------    
    Initial Actions
-------------------------------------------*/

function init() {
    
    initBookingToggle();
    initSubmitRollovers();
    initialValueNewsletter();
    validateContactForm();
    createMP3Player();
       
}

// this runs EVERYTHING
$(document).ready(function() { init(); });



/*-------------------------------------------    
    Custom Functions
-------------------------------------------*/

/** 
*   Hides/shows booking fields in contact form
*   
*   @author Dan Mall <dan@danielmall.com>
*   @version 1.0
*   @copyright Dan Mall
*
*/

function initBookingToggle(){
	
	$('#contact_subject').change(function(){
	    if($(this).val() == 'booking'){
	        $('#booking').slideDown('normal');
	    }else{
	        $('#booking').slideUp('normal');
	    }
	});
	
}


/** 
*   Adds rollover states to "submit" buttons
*   
*   @author Dan Mall <dan@danielmall.com>
*   @version 1.0
*   @copyright Dan Mall
*
*/

function initSubmitRollovers(){
	
	$('#send-btn').mouseover(function(){	    
	    $(this).attr('src', '/i/widgets/send-over.gif');
	}).mouseout(function(){
	    $(this).attr('src', '/i/widgets/send.gif');
	});
	
	$('#sign-up').mouseover(function(){	    
	    $(this).attr('src', '/i/widgets/submit-over.gif');
	}).mouseout(function(){
	    $(this).attr('src', '/i/widgets/submit.gif');
	});
	
}



/** 
*   Makes the label an initial value
*   
*   @author Dan Mall <dan@danielmall.com>
*   @version 1.0
*   @copyright Dan Mall
*
*/

function initialValueNewsletter(){
	
    $('#uytd-uytd').focus(function(){
        $(this).prev().fadeOut('normal');
    }).blur(function(){
        if($(this).val() == ''){
            $(this).prev().fadeIn('normal');
        }
    });
	
}

/** 
*   Validates the Contact Form
*   
*   @author Dan Mall <dan@danielmall.com>
*   @version 1.0
*   @copyright Dan Mall
*
*/

function validateContactForm(){
    
    var errors = false;
	
	$('form[action="/sendmail/"]').submit(function(){
	    $(this).find('.required').each(function(){
	        if($(this).val() == ''){
	            $(this).addClass('required-alert');
	            errors = true;
	        }else{
	            $(this).removeClass('required-alert');
	        }
	    });
	    
	    if(errors){
	        return false;
        }
	});
	
}


/** 
*   Inserts MP3 player on Home page
*   
*   @author Dan Mall <dan@danielmall.com>
*   @version 1.0
*   @copyright Dan Mall
*
*/

function createMP3Player(){
    
    //$('body#home #ablaze').append('<div id="mp3-player">&nbsp;</div>');
    $('body#home #ablaze-debut h2').after('<div id="mp3-player">&nbsp;</div>')
    
    var flashvars = { 
        overColor: '#e67817',
        playlistPath: '/s/playerMultiple/playlist.xml' 
    }
    swfobject.embedSWF("/s/playerMultiple/playerMultiple.swf", "mp3-player", "192", "95", "9.0.0","expressInstall.swf", flashvars, {}, {});
	
}



/** 
*   JavaScript alerts a message from Flash
*   
*   @author Dan Mall <dan@danielmall.com>
*   @version 1.0
*   @copyright Dan Mall
*
*/

function outputMessage(s){
	alert(s);
}


