jQuery(document).ready(function() {
    jQuery('.themeton_doma_form').submit(function() {
        jQuery('#ajax-loading').css('visibility','visible');
        var data = jQuery(this).serialize();
        jQuery.post(ajaxurl, data, function(response) {
            if(response == 1) {
                show_message(1);
                t = setTimeout('fade_message()', 2000);
            } else {
                show_message(2);
                t = setTimeout('fade_message()', 2000);
            }
            jQuery('#ajax-loading').css('visibility','hidden');
        });
        return false;
    });
    jQuery( ".size-slider" ).each(function (){
        var sz=$(this).parent().next().children("input").val();
        //$(this).parent().children(".size-resizer").css('font-size',sz+'px');
        jQuery(this).parent().next().children("span").html(sz+'px');
        //alert($(this).parent().attr("class"));
        $(this).slider({
            range: "min",
            value: sz,
            min: 8,
            max: 72,
            slide:function(event,ui){
                jQuery(this).parent().next().children("input").val(ui.value);
                //$(this).parent().children(".size-resizer").css('font-size',ui.value+'px');
                jQuery(this).parent().next().children("span").html(ui.value+'px');
            }
        });
    });
});
function show_message(n) {
    if(n == 1) {
        jQuery('#saved').html('<div id="message" class="updated fade"><p><strong>Saved</strong></p></div>').show();
    } else {
        jQuery('#saved').html('<div id="message" class="error fade"><p><strong>Didnt Saved</strong></p></div>').show();
    }
}

function fade_message() {
    jQuery('#saved').fadeOut(1000);
    clearTimeout(t);
}

var elementId;

function browseMediaWindow(param)
{
    window.original_send_to_editor = window.send_to_editor;
    window.custom_editor = true;
    var pID = jQuery('#post_ID').val();
    if(pID==undefined){
        pID=1;
    }
    window.send_to_editor = function(html){
        imgurl = jQuery('img',html).attr('src');
        if (elementId != undefined) {
            jQuery('#'+elementId).val(imgurl);
        } else {
            window.original_send_to_editor(html);
        }
        elementId = undefined;
        tb_remove();
    };
    elementId = param;
    formfield = jQuery('#'+param).attr('name');
    tb_show('Upload', 'media-upload.php?post_id=' + pID + '&type=image&TB_iframe=true',false);
}

window.original_send_to_editor = window.send_to_editor;
window.custom_editor = true;


