// JavaScript Document
jQuery(function($){
	var imageCount=0;

	if ($('.home').size()>0 ||  $('#full-screen-image img').size()<=1) {
		$('.transition-controls').hide()
	}

	$('#full-screen-image img').preload({
		onRequest:function(){
			if(imageCount==0){
				$('#full-screen-image').append('<div class="loading">&nbsp;</div>');
			}
			imageCount++;
		},
		onFinish:function(){
			$('.loading').fadeOut(function(){
				$(this).remove();
			})
			$('#full-screen-image').find('img:first').fadeIn(1500, function(){
				runImages();
			})
		}
	});		

	if ($('#full-screen-image').size()>0) {
		$('#full-screen-image').fullSizeImage({
			repositionImage : true,
			overlayLine:false,
			offset : null,
			position : 'fixed'
		});
	};
	function runImages(){
		if ( $.browser.msie ) {
			$('.loading, #loading').remove();
		}
		if ($('#full-screen-image img').size()>1) {
			
			$('.show-more').click(function(){
				if ($('#more-text:not(":visible")').size() > 0) {
					$('#more-text').slideDown();
					$('.show-more').attr('value','Hide Text?')
				} else {
					$('#more-text').slideUp();
					$('.show-more').attr('value','Show More Text?')
				};
			})

			$('#full-screen-image').children('img:not(":first")').hide();
			
			function changeImage() {
				$('#full-screen-image').children('img:visible').fadeOut(1500);
				if ($('#full-screen-image').children('img:visible').next('img').size()>0) {
					$('#full-screen-image').children('img:visible').next('img').fadeIn(1500);
				} else {
					$('#full-screen-image').children('img:first').fadeIn(1500);
				};
			}

			function prevImage() {
				$('#full-screen-image').children('img:visible').fadeOut(1500);
				if ($('#full-screen-image').children('img:visible').prev('img').size()>0) {
					$('#full-screen-image').children('img:visible').prev('img').fadeIn(1500);
				} else {
					$('#full-screen-image').children('img:last').fadeIn(1500);
				};
			}

			$('#next').click(function(e){
				e.preventDefault();
				clearInterval(timer);

				changeImage();
				timer = setInterval(changeImage, 6000);
			})

			$('#prev').click(function(e){
				e.preventDefault();
				clearInterval(timer);

				prevImage();
				timer = setInterval(changeImage, 6000);
			})

			$('#pause').click(function(e){
				e.preventDefault();
				if (timer==false) {
					timer = setInterval(changeImage, 6000);
				} else {
					clearInterval(timer);
					timer = false;
				};
			})
			var timer = setInterval(changeImage, 6000);
			
		} else {
			$('.transition-controls').hide()
		};
	}
		   
  
	//Fade in client logos
	  $("ul.column li").css("display","none"); //hide
		  $("ul.column li").each(function (i){
				var me = $(this);
				setTimeout(function(){ $(me).fadeIn(1000); }, (200 * i));
     });
						  
	function smartColumns() { //Create a function that calculates the smart columns

     //Reset column size to a 100% once view port has been adjusted
		$("ul.column").css({ 'width' : "100%"});
	
		var colWrap = $("ul.column").width(); //Get the width of row
		var colNum = Math.floor(colWrap / 260); //Find how many columns of 260px can fit per row / then round it down to a whole number
		var colFixed = Math.floor(colWrap / colNum); //Get the width of the row and divide it by the number of columns it can fit / then round it down to a whole number. This value will be the exact width of the re-adjusted column
	
		$("ul.column").css({ 'width' : colWrap}); //Set exact width of row in pixels instead of using % - Prevents cross-browser bugs that appear in certain view port resolutions.
		$("ul.column li").css({ 'width' : colFixed}); //Set exact width of the re-adjusted column	
	
	}	
	
	smartColumns();//Execute the function when page loads
	
	$(window).resize(function () { //Each time the viewport is adjusted/resized, execute the function
		smartColumns();
	});

	
(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
		var ah = $(this).height();
		var ph = $(this).parent().height();
		var mh = (ph - ah) / 2;
	$(this).css('padding-top', mh);
	});
};
})(jQuery);

	$('h3.head').click(function() {
		var state = $(this).next().is(':visible');
	    if(state == true)
		{
			$(this).next().slideDown(500);
		}
		
		else
		{
			 $('.vacancy-content').each(function()
			{
				if($(this).is(':visible'))
				{
					$(this).slideUp(500);	
				}
			});
			$(this).next().slideToggle(500);
		}
		
		
		
		return false;
	}).next().hide();


	function checkHeader() {
		if ($(window).width()<960) {
			$('#header').width(960);
		} else {
			if($.browser.msie && $.browser.version == 8)
			{
				$('#content-wrapper').css('overflow','visible');
				$('#header').width('100%');
			}
			else if($.browser.msie && $.browser.version == 6)
			{
				$('#content-wrapper').css('overflow','visible');
				$('#header').width('100%');
			}
			else
			{
				$('#header').width($('#content').innerWidth());
			}
		};
	}


	if($('.clients').size()>0){
		setTimeout(checkHeader,2000);
	} else {
		checkHeader();
	}

	$(window).bind('resize',checkHeader);

	if ($.browser.msie && $.browser.version.substr(0,1)<8) {
		$('#login-overlay, #content-wrapper, #landing-page').height($(window).height())
	}

	if ($('.home').size()>0) {
		if ($.cookie("homeCookie")==null) {
			$.cookie('homeCookie', '1');

		} else {
			$('#landing-page').remove();
		};
	};
	
	//Set option width for ie7
	/*
	if($.browser.version.substr(0,1) == 7 || $.browser.version.substr(0,1) == 6) {
     $('#login-nature-of-enquiry').fixSelect(200);
	}
	*/
});

