var savedJobsPanel;
var savedJobsPanelNoJs;
var jobId;
var entryTypeId

var savedjobs = {

	init : function(job_id, entry_type_id){
	    savedJobsPanel = jQuery("#savedjob");
	    savedJobsPanelNoJs = jQuery("#savedjobnojs");
	    savedJobsPanelNoJs.css('display', "none");
	    jobId = job_id;
	    entryTypeId = entry_type_id;
	    savedJobsPanel.click(function(e) {
	        savedjobs.toggle();
	    });
	},
	
	status : function(){
	    //Make an async request to see the status of the current job
	    var postVars ='jobid='+jobId+'&entrytypeid='+entryTypeId;
        if (window.location.href.indexOf('https') >= 0)
            postVars = postVars + '&RequiresSecure=1';
		jQuery.post('/global/savedjobs/ajax_job_status.aspx', postVars, savedjobs.drawResults);
	},
	
	toggle : function(){
	    //Make an async request to toggle the status of the current job
	    var postVars = 'jobid='+jobId+'&entrytypeid='+entryTypeId;
        if (window.location.href.indexOf('https') >= 0)
            postVars = postVars + '&RequiresSecure=1';
		jQuery.post("/global/savedjobs/ajax_job_toggle.aspx", postVars, savedjobs.drawResults);
	},
	
	drawResults : function(o){
		savedJobsPanel.html(o);
		savedJobsPanel.css('display', "block");
		
		//Bind the saved jobs.. so it will track again
		$(document).ready(function() {
            $('div#savedjob a').bind('click.savedJob', function() {
                var className = $(this).attr("class");
                if (className != "remove")
                {                
                    //get on document data.. if not this will error after ajax is run
                    var jData = jQuery.data(document.body, "googleTrack");
                    if (jData)
                    {
                        google.trackEvent(jData.jobArea + '_Job', 'Saved_Job_Click', jData.shortName);
                    }
                }
                
            });        
        });
	},
		
	fail : function(){
	}
}
