$(document).ready(function() {

/*
* Tadas Juozapaitis ( kasp3rito@gmail.com )
*/
(function($){
	$.fn.vTicker = function(options) {
	var defaults = {
		speed: 700,
		pause: 4000,
		showItems: 2,
		animation: '',
		mousePause: true
	};
	var options = $.extend(defaults, options);
	moveUp = function(obj, height){
		obj = obj.children('ul');
    	first = obj.children('li:first').clone(true);
    	obj.animate({top: '-=' + height + 'px'}, options.speed, function() {
        	$(this).children('li:first').remove();
        	$(this).css('top', '0px');
        });
		if(options.animation == 'fade')
		{
			obj.children('li:first').fadeOut(options.speed);
			obj.children('li:last').hide().fadeIn(options.speed);
		}
    	first.appendTo(obj);
	};

	return this.each(function() {
		obj = $(this);
		maxHeight = 0;
		obj.css({overflow: 'hidden', position: 'relative'})
			.children('ul').css({position: 'absolute', margin: 0, padding: 0})
			.children('li').css({margin: 0, padding: 0});
		obj.children('ul').children('li').each(function(){
			if($(this).height() > maxHeight)
			{
				maxHeight = $(this).height();
			}
		});
		obj.children('ul').children('li').each(function(){
			$(this).height(maxHeight);
		});
		obj.height(maxHeight * options.showItems);		
    	interval = setInterval('moveUp(obj, maxHeight)', options.pause);
		if(options.mousePause)
		{
			obj.bind("mouseenter",function(){
				clearInterval(interval);
			}).bind("mouseleave",function(){
				interval = setInterval('moveUp(obj, maxHeight)', options.pause);
			});
		}
	});
};
})(jQuery);

	// Summer Pass
   var popOut = "#popout"; // Name of the popout container.
   var adBox = "#adbox"; // Name of the animated bit of the ad.
   var adWidth = $(adBox).width() + $("#cap").width(); // Width of the ad container.
   var adCookie = "ad-example"; // Name of the cookie to be set.

   function openAd() {
      $(popOut).width(adWidth+"px");
      $(adBox).animate({marginLeft: "0"},1200)
      $.cookie(adCookie, null);
   }
   
   function closeAd() {
      $(adBox).animate({marginLeft: "-"+adWidth+"px"},1200,"linear",
         function(){ $(popOut).width($("#cap").width() + "px"); }
      );
      $.cookie(adCookie,'closed',{expires: 7});
   }

   $("#open").click(function() {
      if(!$.cookie(adCookie)) {
         closeAd();
      } else {               
         openAd();
      }
      return false;
   });

   $("#close").click(function() {
      closeAd();
      return false;
   });   
      if(!$.cookie(adCookie)) {
      $(popOut).animate({opacity: 1.0}, 1500, "linear", openAd);
   }


	//Animate the group and corporate forms to slide open and closed
	$('#birthday').hide();
	$('.formtoggle').click(function(){
		$('#birthday').slideToggle();
	});

	$('#investment').hide();
	$('.investmentformtoggle').click(function(){
		$('#investment').slideToggle();
	});

$('.newsitem').vTicker({

   speed: 500,
   pause: 6000,
   showItems: 1,
   animation: 'fade',
   mousePause: false
});

if ($(".newsitem li").length){
    $("body").addClass("home-page");
}

$('#slider').nivoSlider({pauseTime: 5000});	

	$('a.lightbox').lightBox();
	
		//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
		});

});

