$(document).ready(function()
{
	 initAjax();
	 initArticle();
	 initOpenClose();
});
function initAjax()
{
	var buttons = $(".product-detail .tabs li a");
	$(buttons).each(function(i, el)
	{
		var _url = this.href;
		if($(this).hasClass("active"))
		{
			loadData(_url);
		}
		$(this).click(function(event)
		{
            event.preventDefault();
			loadData(_url);
			$(buttons).removeClass("active")
			$(el).addClass("active")
			return false;
		});
	});
}
function loadData(_url)
{
	var holder = $(".tabinfo");
	$.ajax({
		url: _url,
		dataType: "html",
		success: function(_html)
		{
			$(holder).css({"opacity": 0}).html(_html);
			setTimeout(function()
			{
					$(holder).animate({"opacity": 1});
					initOpenClose();
			}, 400);
		}
	});
}

function initArticle()
{
	$("a#open").unbind('click').bind('click', function(){
		var box = $(".holder-post")
		if (!$(this).hasClass("open")) {
			$(box).animate({
				"height": $(box).find(".holder-post-2").height()
			});
			$(this).addClass("open").find("span").text("Condense");
		}
		else {
			$(box).animate({
				"height": "170px"
			});
			$(this).removeClass("open").find("span").text("Read Full Transcript");
		}

		$(box).toggleClass("full-height");
		return false;
	});
}

function initOpenClose()
{
	$(".replies-list").hide();
	$(".hider").click(function(){

		var box = $(this).parent().next();
		$(this).parent().toggleClass("opened");
		if ($(this).parent().hasClass("opened")) {
			$(box).slideDown();
		}
		else {
			$(box).slideUp();
		}
		return false;
	});
}
