(function($) {
  $.fn.toggler = function() {
    return this.each(function() {
		var obj = $(this);
      	var img = $(this).children('img').attr('alt');
		var old = $('#gallery #images li.current');
		if ($(this).hasClass('current')) {
			return false;
		}
		function setCurrent() {
			$('#gallery #thumbs li.current').removeClass('current');
			$(obj).addClass('current');
		}
		function loadNewImage() {
			$(old).removeClass('current');
			$('#gallery #images li#image-'+img).fadeIn('normal');
			$('#gallery #images li#image-'+img).addClass('current');
		}
		setCurrent();
		$('#gallery #images li.current').fadeOut('normal', loadNewImage);
    });
  }
})(jQuery);
$(document).ready(function() {
	$('#splash').append('<div id="loader"></div>');
	$(window).load(function () {
	  	var timeout = 6000;
		var items = $('#gallery #thumbs li').size();
		var i = 0;
		function rotate() {
			$('#gallery #thumbs li#thumb-'+i).toggler();
			if (i == items) { i = 1; } else { i++; }
			$.doTimeout('loop', timeout, function(){ rotate(); });
		}
		rotate();
		$('#gallery #thumbs li').click(function() { 
			$(this).toggler(); 
			i = $(this).children('img').attr('alt');
		});
		
		$("a[rel='no-click']").click(function() {
			return false;
		});
		
		$("a[rel='no-click']").click(function() {
			$('.drop').children('#dropdown').slideDown();
		});
		
		$('.close').click(function() {
			$('#dropdown').hide();
			return false;
		});
		$('.bottom-bars').hover(
	    	function () {
				$(this).stop();
	      		$(this).removeClass('bottom-bars').addClass('alternate');
				$(this).animate({ top: "-20px" }, 'normal');
	    	}, 
	    	function () {
				$(this).stop();
	      		$(this).removeClass('alternate').addClass('bottom-bars');
				$(this).animate({ top: "0px" }, 'normal');
	    	}
	  	);
		$('.contact img').animate({ left: "0px" }, 2000);
		$('.about img').animate({ right: "0px" }, 2000);
		$('.business img').animate({ right: "0px" }, 2000);
		$('.solutions img').animate({ right: "0px" }, 2000);
		$('.professional img').animate({ left: "0px" }, 2000);
		$('.careers img').animate({ left: "0px" }, 2000);
		$('.events img').animate({ right: "0px" }, 2000);
		$('body').find('#loader').fadeOut();
	});
	$('input, textarea').focus(function() {
		$(this).val('');
	});
	$('#buttons-login button').click(function() {
		$('#error-login').addClass('show');
		return false;
	});
	$('#error-login span a').click(function() {
		$('#error-login').removeClass('show');
		return false;
	});
});
