jQuery(document).ready(function($) {
	"use strict";
    $(document).on("click", ".rockon_upload_image_button,#rockon_image_button,#rockon_audio_button", function() {

        jQuery.data(document.body, 'prevElement', $(this).prev());

        window.send_to_editor = function(html) {
            var imgurl = jQuery('img',html).attr('src');
			if(imgurl == undefined){
				console.log(html);
				var imgurl=$(html).attr("href");
				}
            var inputText = jQuery.data(document.body, 'prevElement');
            if(inputText != undefined && inputText != '')
            {
                inputText.val(imgurl);
            }

            tb_remove();
        };

        tb_show('', 'media-upload.php?type=image&TB_iframe=true');
        return false;
    });
	jQuery('.rockon_icon_setings li').click(function(){
		$(this).addClass('rockon_selected_icon').siblings().removeClass('rockon_selected_icon');
		jQuery('#rockon_service_iconfont').val($(this).text());
	});

    jQuery('#image-holder a').live('click',function(event){
        event.preventDefault();
        jQuery(this).parent().remove();
        return false;
    });
	
	jQuery('.rockon_event_date').live('focusin',function(event){
        event.preventDefault();
		$(this).datepicker();
    });
	jQuery('.rockon_event_time').live('focusin',function(event){
        event.preventDefault();
		$(this).timepicker({
			showPeriod: true,
			showLeadingZero: true
		});
    });
	jQuery('.rockon-select-sidebar').click(function(){
		jQuery('.rockon-select-sidebar').find('input').removeAttr('checked');
		jQuery('.rockon-select-sidebar').removeClass('rockon_chooseborder');
		jQuery(this).find('input').attr('checked','checked');
		jQuery(this).addClass('rockon_chooseborder');
	});
});
function WPRemoveThumbnail(nonce){
	var post_ID = 0;
	var term_ID = 0;
	if( jQuery('#wpfifc_taxonomies_edit_post_ID_id').length > 0 ){
		post_ID = jQuery('#wpfifc_taxonomies_edit_post_ID_id').val();
	}
	if( jQuery('#wpfifc_taxonomies_edit_term_ID_id').length > 0 ){
		term_ID = jQuery('#wpfifc_taxonomies_edit_term_ID_id').val();
	}
	/*if( post_ID < 1 || term_ID < 1 ){
		return;
	}*/
	jQuery.post( jQuery('#rockon_ajaxurl').val(), 
		{ action: "wpfifc-remove-image", 
		  post_id: post_ID, 
		  thumbnail_id: -1,
		  term_id: term_ID,
		  _ajax_nonce: nonce, 
		  cookie: encodeURIComponent(document.cookie)
		}, 
		function(str){
			alert(str);
			if ( str.indexOf('ERROR') != '-1' ) {
				alert( "Remove featured image failed." );
			} else {
				jQuery('.inside', '#postimagediv').html(str);
			}
		}
	 );
}