
//calculate height for parent based off the tallest element
function checkParentHeight(boundingBox, slider) {
	var firstItemHeight = $(".info").height();						
	var secondItemHeight = $(slider+" .panel").eq(1).height();		
	var sliderHeight =  firstItemHeight + secondItemHeight;
	$(slider).height = sliderHeight;
	$(boundingBox).animate({
	   height: firstItemHeight,
	   opacity: 1.0
	}, 500);
}

function checkHeight() { 
	checkParentHeight("#description_inner", "#slider");
}

function checkCurrentHeight(target, parent) {
	var thisHeight = $(target).height();
	var parentHeight = $(parent).height();
	//alert(thisHeight+","+parentHeight)
	if (parentHeight < thisHeight) {
	$(parent).animate({
		height: thisHeight
	});
	} else if (parentHeight > thisHeight) {
		$(parent).animate({
			height: thisHeight
		});
	}
}


/*SEND FRIEND FORM*/
function resetForm(form) {
	$(form).each(function(){
		this.reset();
	});
}
function showForm() {
	$('.sendFriendForm').show().animate({opacity: 1.0}, 500);
	$('.success').fadeOut("slow").remove();
	checkCurrentHeight(".sendFriend","#description_inner");
	resetForm('.sendFriendForm');
}
function hideForm() {
	$('.loader').animate({opacity: 0}, 500).remove();
	$('.sendFriendForm').hide();
	$('.sendFriend').append('<div class="success"><h1>Success!!</h1><p><strong>Your email was sent!</strong></p> <p><span class="show_form" onclick="showForm();">Click here</span> if you would like to send another email to a friend</p></div>');
	checkCurrentHeight(".sendFriend","#description_inner");
}		


$(document).ready( function() {
	
	//wrap elements into div in order to control via js						
	$('.detail .panel').wrapAll('<div id="description_inner"><div id="slider"></div></div>');
	//add js button
	$('.description .product_extras').prepend('<p class="send_to_friend"><a href="#"><img src="/Content/images/products/detail/send_friend-btn.gif" alt="Send to Friend" /></a></p>');
	
	checkHeight();
	
	//hide show form
	$('.send_to_friend').toggle(
	  function () {
		$(this).addClass("selected");
		var margin = "-"+ $(".info").height()+"px";
		checkCurrentHeight(".sendFriend","#description_inner");
		$('#slider').animate({ marginTop: margin }, 600);
		$('.info').animate({ opacity: 0 }, 585);
		$('.sendFriend').animate({ opacity: 1.0 }, 585);
		
		var image = $(this).find('img');
		$(image).animate({ marginTop: "-30px" }, 500);
		
	  },
	  function () {
		$(this).removeClass("selected");
		checkCurrentHeight(".info","#description_inner");						
		$('#slider').animate({ marginTop: "0" }, 600);
		$('.info').animate({ opacity: 1.0 }, 585);
		$('.sendFriend').animate({ opacity: 0 }, 585);
		var image = $(this).find('img');
		$(image).animate({ marginTop: "0" }, 500);
	  }
	);
	
	
	//product list/gallery hover function
	$(".product").hover(function() {
		$(this).addClass("active");
	}, function() {
		$(this).removeClass("active");
	})	

});




