/*
	CLIENTSIDE
	
	Set up the hover UI and click events for the list of vacancies
*/
function vacancy_Page()
{
	this.load = function()
	{
		$('#__jsConsole').append('Client script loaded. ');
				
		$('.vacancy_result_container').bind('mouseenter', this.vacancyOver );
		$('.vacancy_result_container').bind('mouseleave', this.vacancyOut );
		$('.vacancy_result_container').bind('click', this.vacancyClick );
		
		this.animDuration = 750;
				
		// No search, default page
		if(this.queryString == null) 
		{
			if($.support.opacity)
				this.animateJobs();
			else // IE8 in strict supports neither opacity or it's own filters, so we just pop them into place
				this.popupJobs();
		}
	}
	
	this.animateJobs = function()
	{	
		if(typeof(this.animNext) == 'undefined')
			this.animNext = 0;
		else
			this.animNext++;

		var $this = this;
		$('.vacancy_result_container').eq(this.animNext).animate({opacity:1}, {duration:this.animDuration, complete: function() { $this.animateJobs(); } });
	}
	
	this.popupJobs = function()
	{
		if(typeof(this.animNext) == 'undefined')
			this.animNext = 0;
		else
			this.animNext++;
		
		var $this = this;
		
		var o = $('.vacancy_result_container').eq(this.animNext);
		
		// Have to check whether we have reached the last vacancy container or infinite loop will happen
		if(o.length > 0)
		{
			o.css('visibility', 'visible');
		
			setTimeout(function() { $this.popupJobs(); }, this.animDuration);			
		}
	}
	
	this.vacancyOver = function(e)
	{
		$(this).addClass('vacancy_result_container_hover'); 
	}

	this.vacancyOut = function(e)
	{
		$(this).removeClass('vacancy_result_container_hover'); 
	}
	
	this.vacancyClick = function(e)
	{
		document.location = $(this).find('a.vacancy_link').attr('href'); 
	}
}

HUI.MAIN(vacancy_Page);