var animateBlock = function(el, hiddenEl, exec, attr) {
	jQuery.easing.def = attr.easeType;
	
	if (attr.containerHeight == undefined) {
		attr.containerHeight = 0;
	}
	
	var h = $(el).height() + attr.containerHeight;
	
	$(exec).click(function() {
		$(el).animate({
			bottom: -h
		},{ queue:false,
			duration:attr.time - 300,
			complete:function() {
				$(hiddenEl).show(100).animate({ bottom:0 }, {duration:attr.time});
			}
		});
		
		return false;
	});
	
};

function hideAll (speed) {
	
	
	$('#item-1').hide(speed);
	$('#item-2').hide(speed);
	$('#item-3').hide(speed);
	$('#item-4').hide(speed);
	$('#item-5').hide(speed);
	$('#item-6').hide(speed);
}

$(document).ready(
	function() {
		$('#commercial-lending a:first').attr('id', 'click-animate');
		$('#hidden-item a:first').attr('id', 'click-close');
		
		animateBlock('#commercial-lending', '#hidden-item', '#click-animate',{easeType: 'easeInOutExpo', time:1500});
		animateBlock('#hidden-item', '#commercial-lending', '#click-close',{easeType: 'easeInOutExpo', containerHeight: 20, time:1500});
		
		hideAll("");	
		
		$("a#line-1").click(function () {
			hideAll("fast");	
			$('#item-1').show("slow");
			return false;
		});
		
		$("a#line-2").click(function () {
			hideAll("fast");	
			$('#item-2').show("slow");
			return false;
		});
		
		$("a#line-3").click(function () {
			hideAll("fast");	
			$('#item-3').show("slow");
			return false;
		});
		
		$("a#line-4").click(function () {
			hideAll("fast");	
			$('#item-4').show("slow");
			return false;
		});
		
		$("a#line-5").click(function () {
			hideAll("fast");	
			$('#item-5').show("slow");
			return false;
		});
		
		$("a#line-6").click(function () {
			hideAll("fast");	
			$('#item-6').show("slow");
			return false;
		});
		
		$("p.hideAll").click(function () {
			hideAll("fast");	
			return false;
		});
		
		
		// Generic functions to get/set cookie
			function setCookie(c_name,value,expiredays) {
				var exdate=new Date();
				exdate.setDate(exdate.getDate()+expiredays);
				document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
			}
			
			function getCookie(c_name) {
				if (document.cookie.length>0) {
					c_start=document.cookie.indexOf(c_name + "=");
					if (c_start!=-1) {
						c_start=c_start + c_name.length+1;
						c_end=document.cookie.indexOf(";",c_start);
						if (c_end==-1) c_end=document.cookie.length;
						return unescape(document.cookie.substring(c_start,c_end));
					}
				}
				return "";
			}
			
		// 10th Anniversary lightbox routine
			function showAnniversaryLightbox() {
				var c = getCookie('10thAnniversaryPopup');
				if (c!=null && c!="") {
					// Already visited...don't show lightbox
				} else {
					c='Celebrate!';
					if (c!=null && c!="") {
						// No cookie...show lightbox, set cookie
						setCookie('10thAnniversaryPopup',c,365);
						
		//				var s = $.slimbox('index.aspx_files/deploy/assets/images/10th_anniversary.png', 0, {
		                var s = $.slimbox('/assets/images/10th_anniversary.png', 0, {
							resizeDuration : 200,
							captionAnimationDuration : 0
						});
					}
				}				
			}
			
			showAnniversaryLightbox();

		
		
	}
);

function showAnniversaryLightboxOnClick() {
    var s = $.slimbox('/assets/images/10th_anniversary.png', 0, {
		resizeDuration : 200,
		captionAnimationDuration : 0
	});
}
		
