var imgIn = '/assets/gfx/build/btn_expand.gif';
var imgInAlt = ' + Expand';
var imgOut = '/assets/gfx/build/btn_hide.gif';
var imgOutAlt = ' - Hide';

function initJobslide() {
	//var descriptions = $$('#candidate-results dl dd div.description');
	var descriptions = $$('dl.results dd div.description');
	//var links = $$('#candidate-results dl dd div.candidate-expand');
	var links = $$('dl.results dd div.candidate-expand');
	
	descriptions.each( function(description, i) {
		var tmp = (i + 1);
        //for each element create a slide effect
        window['mySlide' + tmp] = new Fx.Slide('canddesc' + tmp)

        //and store it in the array

		var a = document.createElement('a');
		var img = document.createElement('img');
		a.setAttribute('src','#');
		a.setAttribute('id','link' + tmp);
		img.setAttribute('src',imgIn);
		img.setAttribute('alt',imgInAlt);
		a.appendChild(img);
		links[i].appendChild(a);
		
		$('link' + tmp).addEvent('click', function(e){
			e = new Event(e);		
			var theId = this.id;
			theId = theId.replace('link','');	
			window['mySlide' + theId].slideIn();
			e.stop();
			setCloseSlide(this.parentNode.id);
		})	
        //collapse all of the list items
        window['mySlide' + tmp].hide();

	});
}
function setOpenSlide(o) {
	var obj = $get(o.replace('candexpand','canddesc'));
	var theId = o.replace('candexpand','');
	var link = $get(o);
	var a1 = link.childNodes[0];
	var img = document.createElement('img');
	var a = document.createElement('a');
	
	link.removeChild(a1);
	a.setAttribute('src','#');
	a.setAttribute('id','link' + theId);
	img.setAttribute('src',imgIn);
	img.setAttribute('alt',imgInAlt);
	a.appendChild(img);
	link.appendChild(a);
	
	$('link' + theId).addEvent('click', function(e){
		e = new Event(e);		
		var theId = this.id;
		theId = theId.replace('link','');	
		window['mySlide' + theId].slideIn();
		e.stop();
		setCloseSlide(this.parentNode.id);
	})	
}
function setCloseSlide(o) {
	var obj = $get(o.replace('candexpand','canddesc'));
	var theId = o.replace('candexpand','');
	var link = $get(o);
	var a1 = link.childNodes[0];
	var img = document.createElement('img');
	var a = document.createElement('a');
	
	link.removeChild(a1);
	a.setAttribute('src','#');
	a.setAttribute('id','link' + theId);
	img.setAttribute('src',imgOut);
	img.setAttribute('alt',imgOutAlt);
	a.appendChild(img);
	link.appendChild(a);
	
	$('link' + theId).addEvent('click', function(e){
		e = new Event(e);		
		var theId = this.id;
			theId = theId.replace('link','');	
		window['mySlide' + theId].slideOut();
		e.stop();
		setOpenSlide(this.parentNode.id);
	})	
}
