
// prepare the form when the DOM is ready 
$(document).ready(function() { 
	
    $('#embed_code').css({
        'display': 'none'
    });

    $('#submit_comment').attr("disabled", "");
    $('#comment').attr("disabled", "");	
	
    $('#submit_favorite').click(function(){ 
        $('#submit_favorite').attr("value", "Adding...");
    });
	
    $('#delete_favorite').click(function(){ 
        $('#delete_favorite').attr("value", "removing...");
    });
	
    $('#submit_comment').click(function(){ 
        $('#submit_comment').attr("value", "Adding...");
    });

		
    //$('#submit_rating').attr("src", "http://a-real.tv/assets/image/add-32-neg.gif");
	
    // bouton de Like
    //$('#submit_rating').attr({
    //		type: 'image',
    //		src: 'http://a-real.tv/assets/image/add-32.png'
    //	});
	
    // bind form using ajaxForm 
    $('#htmlForm').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#ok', 
 		
        beforeSubmit: function(formData, jqForm, options){
			
            // formData is an array of objects representing the name and value of each field 
            // that will be sent to the server;  it takes the following form: 
            // 
            // [ 
            //     { name:  username, value: valueOfUsernameInput }, 
            //     { name:  password, value: valueOfPasswordInput } 
            // ] 
            // 
            // To validate, we can examine the contents of this array to see if the 
            // username and password fields have values.  If either value evaluates 
            // to false then we return false from this method. 
			
            for (var i=0; i < formData.length; i++) { 
                if (!formData[i].value) { 
                    alert('Hum, your comment is empty? Please, try again!');
                    return false; 
                } 
            } 
			
            return true;
        },
		
		
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() { 
            //$('#ok').before('Your comment is added, clic here if you want to see it now:');
            $('#comment').attr("disabled", "disabled");
            $('#submit_comment').attr("value", "Commented!");
            $('#submit_comment').attr("disabled", "disabled");
            $('#ok').fadeIn('fast');
			
        //$('#htmlForm').fadeOut('slow');
        //$('#ok').before("ok");
        } 
    }); 
	
	
	
    // bind form using ajaxForm 
    $('#ratingForm').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#ratingok', 
 		
        beforeSubmit: function(formData, jqForm, options){
			
            // formData is an array of objects representing the name and value of each field 
            // that will be sent to the server;  it takes the following form: 
            // 
            // [ 
            //     { name:  username, value: valueOfUsernameInput }, 
            //     { name:  password, value: valueOfPasswordInput } 
            // ] 
            // 
            // To validate, we can examine the contents of this array to see if the 
            // username and password fields have values.  If either value evaluates 
            // to false then we return false from this method. 
			
            for (var i=0; i < formData.length; i++) { 
                if (!formData[i].value) { 
                    alert('Hum, your comment is empty? Please, try again!');
                    return false; 
                } 
            } 
			
            return true;
        },
		
		
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() { 
            //$('#ok').before('Your comment is added, clic here if you want to see it now:');
            $('#rating').attr("disabled", "disabled");
            $('#submit_rating').attr("value", "Rated!");
            $('#submit_rating').attr("disabled", "disabled");
            //$('#ratingok').fadeIn('fast');
		   
            // Image en n et b
            var ratingVal = parseInt($('#liked').text());
            ratingVal ++;
		   
            $('#liked').html(ratingVal);
		   
            $('#submit_rating').attr("src", "http://a-real.tv/assets/image/add-16-neg.gif");
		   
        //$('#htmlForm').fadeOut('slow');
        //$('#ok').before("ok");
        } 
    }); 
	
	
	
    // bind form using ajaxForm 
    $('#favoriteForm').ajaxForm({ 
		
		
        // target identifies the element(s) to update with the server response 
        target: '#favoriteok', 
 		
        beforeSubmit: function(formData, jqForm, options){
			
            // formData is an array of objects representing the name and value of each field 
            // that will be sent to the server;  it takes the following form: 
            // 
            // [ 
            //     { name:  username, value: valueOfUsernameInput }, 
            //     { name:  password, value: valueOfPasswordInput } 
            // ] 
            // 
            // To validate, we can examine the contents of this array to see if the 
            // username and password fields have values.  If either value evaluates 
            // to false then we return false from this method. 
			
            for (var i=0; i < formData.length; i++) { 
                if (!formData[i].value) { 
                    alert('Hum, your comment is empty? Please, try again!');
                    return false; 
                } 
            } 
			
            return true;
        },
		
		
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() { 
            //$('#ok').before('Your comment is added, clic here if you want to see it now:');
            //$('#rating').attr("disabled", "disabled");
            $('#submit_favorite').attr("value", "Added!");
            $('#submit_favorite').attr("disabled", "disabled");

		   
        //$('#favoriteok').fadeIn('fast');
			
        //$('#htmlForm').fadeOut('slow');
        //$('#ok').before("ok");
        } 
    }); 
	
	
    $('#delfavoriteForm').ajaxForm({ 
		
		
        // target identifies the element(s) to update with the server response 
        target: '#favoriteok', 
 		
        beforeSubmit: function(formData, jqForm, options){
			
            for (var i=0; i < formData.length; i++) { 
                if (!formData[i].value) { 
                    alert('Hum, your quiery is empty? Please, try again!');
                    return false; 
                } 
            } 
			
            return true;
        },
		
		
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() { 
            //$('#ok').before('Your comment is added, clic here if you want to see it now:');
            //$('#rating').attr("disabled", "disabled");
            $('#delete_favorite').attr("value", "Removed!");
            $('#delete_favorite').attr("disabled", "disabled");
        //$('#favoriteok').fadeIn('fast');
			
        //$('#htmlForm').fadeOut('slow');
        //$('#ok').before("ok");
        } 
    }); 


    $('#vidForm').ajaxForm({ 
		
		
        // target identifies the element(s) to update with the server response 
        target: '#vidok', 
 		
        beforeSubmit: function(formData, jqForm, options){
			
            for (var i=0; i < formData.length; i++) { 
                if (!formData[i].value) { 
                    alert('Hum, your quiery is empty? Please, try again!');
                    return false; 
                } 
            } 
			
            return true;
        },
		
		
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() {
            $('#submit_modif').attr("value", "Modified!");
            $('#submit_modif').attr("disabled", "disabled");
			
        } 
    }); 
    
    
    $('#picForm').ajaxForm({ 
		
		
        // target identifies the element(s) to update with the server response 
        target: '#pic', 
 		
//        beforeSubmit: function(formData, jqForm, options){
//			
//            for (var i=0; i < formData.length; i++) { 
//                if (!formData[i].value) { 
//                    alert('Hum, your quiery is empty? Please, try again!');
//                    return false; 
//                } 
//            } 
//			
//            return true;
//        },
		
		
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() {
            $('#pic_modif').attr("value", "Modified!");
            $('#pic_modif').attr("disabled", "disabled");
			
        } 
    });
    
    function pic_modif(base_url,id){
        $('#video_pic').attr("value", base_url + "assets/image/screen/" + id + ".jpg");
        $('#video_local_pic').attr("value", 1);
    }
		
	
    $('#customize_button').click(function(){ 
        $('#embed').css({
            'height': '340px'
        });
        $('#embed_code').css({
            'display': 'block'
        });
    });



});
