var dtbaker_wpetss = {
    popup_url : '',
    page_id : '',
    ticket_id : 0,
    ticket_account_id : 0,
    init_done : false,
    min_height : '60px',
    min_width: '80px',
    max_width : '250px',
    show_postits: true,
    init: function(){
        var t = this;
        if(t.init_done)return;
        jQuery('#dtbakerss').val('');

        jQuery('body').append('<a href="#" style="display:none;" id="wpetss_open_link">open</a>');
        jQuery('body').append('<div id="dtbaker_wpetss_inlinepopup" style="display:none;"></div>');
        jQuery("#wpetss_open_link").wpetssfancybox({
            'zoomSpeedIn'		: 600,
            'zoomSpeedOut'		: 100,
            'autoDimensions'	: true,
            'content'              : '#dtbaker_wpetss_inlinepopup',
            'href'              : '#',
            'type'              : 'inline',
            'easingIn'			: 'easeOutBack',
            'easingOut'			: 'easeInBack',
            'hideOnContentClick': false,
            'padding'			: 15,
            'onStart' : function(){
                jQuery('#dtbaker_wpetss_inlinepopup').show();
            },
            'onCleanup' : function(){
                jQuery('#dtbaker_wpetss_inlinepopup').html('');
                jQuery('#dtbaker_wpetss_inlinepopup').hide();
                t.opened=false;
            }
        });
        jQuery(".wpetss_open").parents('a').click(function(){
            return t.launch_popup();
        });
        
        t.init_done = true;
    },
    launch_popup: function(tac){
        var t=this;
        t.ticket_id = 0;
        jQuery('#dtbaker_wpetss_inlinepopup').load(t.popup_url+'?type=popup&tac='+tac,function(){
            jQuery('#dtbakerss').val('');
            t.close_popup();
            t.open_popup();
        });
        return false;
    },
    opened:false,
    open_popup: function(){
        if(this.opened)return;
        this.opened=true;
        jQuery('#wpetss_open_link').click();
    },
    close_popup: function(){
        this.opened = false;
        jQuery.wpetssfancybox.close();
    },
    edit: function(ticket_id){
        var t = this;
        t.init();
        t.ticket_id = ticket_id;
        
        jQuery('#dtbaker_wpetss_inlinepopup').load(t.popup_url+'?type=popup&ticket_id='+t.ticket_id,function(){
            //set_add_del('dtbaker_ticket_request_attachments');
            // set the form varialbes.
            jQuery('#dtbakerss').val('');
            //jQuery('#ticket_request_submit_form').attr('action',t.popup_url+'?type=save');
            //jQuery('#ticket_request_submit_form').append('<input type="hidden" name="ticket_id" value="'+t.ticket_id+'">');
            t.close_popup();
            t.open_popup();
        });
    }
};

jQuery(function(){
    // init the ticket request popup.
    dtbaker_wpetss.init();
});

function set_add_del(id){
    jQuery("#"+id+' .remove_addit').show();
    jQuery("#"+id+' .add_addit').hide();
    jQuery("#"+id+' .add_addit:last').show();
    if(jQuery("#"+id+" .dynamic_block").length==1){
    jQuery("#"+id+' .remove_addit').hide();
    }
}
function selrem(clickety,id){
    jQuery(clickety).parents('.dynamic_block').remove();
    set_add_del(id);
    return false;
}
function seladd(clickety,id){
    var box = jQuery('#'+id+' .dynamic_block:last').clone(true);
    jQuery('input',box).val('');
    jQuery('#'+id+' .dynamic_block:last').after(box);
    set_add_del(id);
    return false;
}

