var content	= new Array();

content[0] = new Array("Construction", "images/searchMarkets/construction.gif");
content[1] = new Array("Data", "images/searchMarkets/data.gif");
content[2] = new Array("Electrical", "images/searchMarkets/electrical.gif");
content[3] = new Array("FM & Service Sales", "images/searchMarkets/fm.gif");
content[4] = new Array("HVAC", "images/searchMarkets/hvac.gif");
content[5] = new Array("Lighting", "images/searchMarkets/lighting.gif");
content[6] = new Array("Security", "images/searchMarkets/security.gif");
content[7] = new Array("Automation & Control", "images/searchMarkets/automation.gif");


/**
 * Ready function sorts out the image switcher on the form
 * Sorts out the form logic for the search
 *
 * @author   : Rob
**/
$(document).ready(function(){
	//Check that we always have a check box set
	checkCheckBoxes()
	
	//Vacancy slider
	setUpVacancySlider();
  
    //here we're doing the image switching for the search box
	setTimeout("imageLoop(0)",4000);
});




/**
 * Works as a loop, calling the change image function
 *
 * @author   : Rob
 * @param    : int, the index number of the content array
**/
function imageLoop(index) {
    thisIndex = index;
    if(thisIndex < content.length) {
        thisIndex = changeImg(thisIndex);
        thisIndex++;
        setTimeout("imageLoop(thisIndex)",4000);
    } else {
        setTimeout("imageLoop(0)",4000);
    }
}

/**
 * Does the actuall image switching
 *
 * @author   : Rob
 * @param    : int, the index of the content array
 * @return   : int, the index of the content array
**/
function changeImg(index){

    $('#fadeContainer').fadeOut("slow", function(){
        $('#fadeContainer').children("img").attr("src", content[index][1]);
        $('#fadeContainer').children("h3").text(content[index][0]);
    });

    $('#fadeContainer').fadeIn("slow");
    return index;
}


/**
 * Does the form logic
 *
 * @author : Rob
 * @retrun : int, The number of check boxes within the form that have been checked
**/
function checkCheckBoxes() {
	
	$(".chkContract").change(function() {
		var bool = false;
		
		$(".chkContract").each(function() {
			
			if($(this).attr("checked")) {
				//one of the boxes has been checked
				bool = true;
			}
		});
		
		//disable the check boxes
		if(!bool) {
			$("#cmdSearch").attr("disabled", "true");
		} else {
			$("#cmdSearch").removeAttr("disabled");
		}
	});
}

function setUpVacancySlider() {
	$("#slideToVacancies").click(function() {
		$.scrollTo($(".jobListing"), 800, {offset:-50});
	});
}

