var animating;
var maxheight,normalheight;
var reserved=0;
var interval=10;
$(document).ready(function(){
	maxheight=$("#homebanner_1").height()-reserved;
	normalheight=$("#homebanner_top_1").height();
	
	$(".homebanner_top").hover(
		function(e){
			animating=e.currentTarget.id;
			var id = e.currentTarget.id.replace("homebanner_top_","");
			$("#homebanner_top_"+id).animate({
						height: maxheight+"px"
					},{
						duration: "fast",
						step: function (now,fx){
							var r = (maxheight-now);
							if (r<reserved)r=reserved;
							$("#homebanner_bottom_"+id).height( ((maxheight+reserved)-now)+"px");
						},
						complete: function(){
							$("#homebanner_bottom_"+id).height(reserved+'px');
							$("#homebanner_top_"+id).height(maxheight+'px');
						}
					}
				);
		},
		function(e){
			var id = e.currentTarget.id.replace("homebanner_top_","");
			$("#homebanner_top_"+id).animate({
						height: normalheight+"px"
					},{
						duration: "fast",
						step: function (now,fx){
							$("#homebanner_bottom_"+id).height( ((maxheight+reserved)-now)+"px");
						},
						complete: function(){
							$("#homebanner_bottom_"+id).height(normalheight+"px");
							$("#homebanner_top_"+id).height(normalheight+"px");
						}
					}
				);
		}
	);
	$(".homebanner_bottom").hover(
		function(e){
			animating=e.currentTarget.id;
			var id = e.currentTarget.id.replace("homebanner_bottom_","");
			$("#homebanner_top_"+id).animate({
						height: reserved+"px"
					},{
						duration: "fast",
						step: function (now,fx){
							var r = ((maxheight+reserved)-now);
							//if (r<reserved)r=reserved;
							$("#homebanner_bottom_"+id).height( r+"px");						
						},
						complete: function(){
							$("#homebanner_top_"+id).height(reserved+'px');
							$("#homebanner_bottom_"+id).height(maxheight+'px');
						}						
					}
				);
		},
		function(e){
			var id = e.currentTarget.id.replace("homebanner_bottom_","");
			$("#homebanner_top_"+id).animate({
						height: normalheight+"px"
					},{
						duration: "fast",
						step: function (now,fx){
							$("#homebanner_bottom_"+id).height( ((maxheight+reserved)-now)+"px");
						},
						complete: function(){
							$("#homebanner_bottom_"+id).height(normalheight+"px");
							$("#homebanner_top_"+id).height(normalheight+"px");
						}
					}
				);
		}
	);
	
});

	function grow(g,s){
		var gh = g.height();
		var sh = s.height();

		gh+=interval;
		sh-=interval;
		if (gh>maxheight) gh=maxheight;
		if (sh<0) sh=0;
		g.height(gh+"px");
		s.height(sh+"px");
		
		if (gh<maxheight) {
			setTimeout(grow,500,g,s);
		}
	}

	function shrink(g,s){
		var gh = g.height();
		var sh = s.height();
		gh+=interval;
		sh-=interval;
		if (gh>maxheight) gh=maxheight;
		if (sh<0) sh=0;		
		
		if (sh>normalheight) {
			gh++;
			sh--;
			g.height(gh+"px");
			s.height(sh+"px");
			setTimeout(shrink,500,g,s);
		}
	}

