

if (!ChildCareJobs)
{
	var ChildCareJobs = {};
}

ChildCareJobs.FeaturedEmployerSlider = 
{
	rsimagesRSS: [{"id":1414,"jobSearchLink":"searchresults.aspx?order=date&keywords=&category=&type=&position=&country=&state=&city=&emp=1414&pg=1","imageUrl":"imageNew.aspx?employerId=1414&w=215&h=135","alternateText":"KU Children\u0027s Services\n129 York Street, Sydney, NSW\nEstablished in 1895, KU Children\u0027s Services is Australia\u0027s leading provider of high quality, not for profit early childhood education and care.\r\n\r\nWit..."}],

	nIndexImages: 0,
	_currentlyShownImage: null,

	buildimages: function(divContainer, employer) {
		// 2010-mar-29 markg: this uses jquery to build the dom elements, avoiding any XSS attacks by manually building up strings
		var div = $(document.createElement('div'));

		div
			.attr({ id : employer.id })
			.hide()
			.css("margin-left", "2px")
			.append(
				$(document.createElement('a'))
					.attr({ href : employer.jobSearchLink })
					.append(
						$(document.createElement('img'))
							.attr({ border: "0", src: employer.imageUrl, alt: employer.alternateText })
					)
			);

		employer.div = div;

		divContainer.append(div);

		if (this._currentlyShownImage)
		{
			this.slideimages(div);
		}
		else
		{
			div.show();
			
			this._currentlyShownImage = div;
		}
	},

	/// <summary>
	/// 2010-mar-29 markg: takes in a jquery object of the new images to show after the current image has faded
	/// </summary>
	slideimages: function(newImageToShow)
	{
		var slider = this;
		var fimages = this._currentlyShownImage;

		if (fimages)
		{
			fimages.fadeOut(600, function() {
				slider._currentlyShownImage = newImageToShow;

				newImageToShow.show();
			});
		}
	},

	loadimages: function()
	{
		if (this.rsimagesRSS.length > 0) {
			if (this.nIndexImages >= this.rsimagesRSS.length) {
				this.nIndexImages = 0;
			}

			var employer = this.rsimagesRSS[this.nIndexImages];

			var elSlider = employer.div;

			if (elSlider)
			{
				this.slideimages(elSlider);
			}
			else
			{
				this.buildimages($('#featuredEmployersSlider'), employer);
			}

			this.nIndexImages++;
		}
	}
}

$(function() {
	ChildCareJobs.FeaturedEmployerSlider.loadimages();
	window.setInterval(function() {ChildCareJobs.FeaturedEmployerSlider.loadimages();}, 5000);
});
