﻿function LoadPreviousJob ( ) {
    //assume only used on homepage for now
    LoadJob ( 'Previous', 'Homepage' );
}

function LoadNextJob ( ) {
    //assume only used on homepage for now
    LoadJob ( 'Next', 'Homepage' );
}

function LoadJob ( direction, featuredJobGroupId ) {
    
    //Hide the detail panel to 0
    $('Detail').fade(0);
    //Set the loading background image
    $('Loading').set('style', 'background-image: url(/Lib/Img/Loading.gif);');
    
    var jobTitle = $('JobTitle').getElement('a');
    
    //This code will send a data object via a GET request and alert the retrieved data.
    var jsonRequest = new Request.JSON({url: "/Handlers/GetJob.ashx", onComplete: function(job){
        
        $('Sector').set('text', job.FirstCustomPropertySector);
        jobTitle.set('text', job.JobTitle);
        $('Location').set('text', job.FirstCustomPropertyLocation);
        if ( job.Salary != '' ) 
        {
            $('Salary').set('text', '(' + job.Salary + ')');
        }
        else
        {
            $('Salary').set('text', '');
        }
        
        //don't bother fading the 'view more details' link in and out - is better when it stays static.  But still need to update the url...
        var viewMoreDetails = $('ViewMoreDetails').getElement('a');
        viewMoreDetails.set('href', job.EncodedUrl);
        
        setCurrentJobId(job.JobId);
        //set the id in the hidden field so that next can be request for next time
        
        //Get rid of loading image and fade job back in
        
        //Do little pause first for half a second before fading everything back in because we always want to show the loading bar, even on a very fast server/connection
        setTimeout("fadeBackIn();", 750);
        
    }}).get({'jid': getCurrentJobId(), 'direction': direction, 'fjgi': featuredJobGroupId});
}

function fadeBackIn() 
{
    $('Loading').set('style', 'background-image: none;');
    $('Detail').fade(1);
}

function getCurrentJobId () 
{
    var currentJobId = $("CurrentJobId").getElement('input');
    return currentJobId.get('value');
}

function setCurrentJobId (value) 
{
    var currentJobId = $("CurrentJobId").getElement('input');
    currentJobId.set('value', value);
}