// JavaScript Document

$(function() {
	
	$(".comment-textContainer p").truncate({
	  width: 'auto',
	  after: '&hellip;',
	  center: false,
	  addclass: 'highlight', // adds class
	  addtitle: true // adds title attribute with original content
	});
	
	$(".postsContainer ul.tabPanes").tabs(".postsContainer .postContent-Container > div", 
		{
			effect: "fade"
		}
	);
	
	$("span.radio").each(function() {
		if ($(this).children("input").is(":checked")){
			$(this).addClass("checked");
		}
		$(this).click(function() {
			if ( $(this).hasClass("checked") ) {
				$(this).removeClass("checked");
				$(this).children("input").attr("checked", false);
			} else {
				var radioGroup = $(this).children("input").attr("name");
				$("input[type='radio'][name='"+radioGroup+"']:checked").attr("checked", false).parent().removeClass("checked");
				$(this).addClass("checked");
				$(this).children("input").attr("checked", true);
			}
		});
	});
	
	$(".shareText").click(function() {
		var ulParent = $(this).parent().parent();
		if (ulParent.hasClass("open")) {
			ulParent.stop().animate({
				height: 9
			}, 300, function() { $(this).removeClass("open").addClass("closed"); }
			);
		}
		else {
			var ulTotalHeight = 0;
			ulParent.children("li").each(function() { ulTotalHeight += $(this).outerHeight(true); });
			ulParent.stop().animate({
				height: ulTotalHeight
			}, 300, function() { $(this).removeClass("closed").addClass("open"); }
			);
		}
	});
	
	$(".bannerContainer .bannerWrapper").cycle({
		slideExpr: ".bannerContent",
		next: ".bannerContainer .rightArrow",
		prev: ".bannerContainer .leftArrow",
		fx: "scrollHorz",
		cleartypeNoBg: true,
		timeout: 10000,
		speed: 2000
	});
	
	$(".supportedbygfiContainer .sliderContainer .sliderWrapper").cycle({
		slideExpr: ".sliderItem",
		next: ".supportedbygfiContainer .rightArrow",
		prev: ".supportedbygfiContainer .leftArrow",
		fx: "fade"
	});
	
	$("#header .search-dropdown > a").hover(function() {
		var listHeight = 0;
		var subMenu = $(this).parent().children("div.search-dropdownlist");
		
		/* subMenu.find("li").each(function() {
			listHeight += $(this).outerHeight();
		}); */
		
		listHeight = subMenu.children("ul").outerHeight();
		
		subMenu.stop().animate({
			height: listHeight
		});
		
		$(this).parent().mouseleave(function() {
			$(this).unbind("mouseleave");
			$(this).children("div").stop().animate({
				height: 0
			});
		});
	});
	
	$("#header .search-dropdown .search-dropdownlist li a").click(function() {
		var categoryText = $(this).text();
		var category = $(this).next().val();
		$("#searchCategoryType").val(category).prev().text(categoryText);
	});
	
	
});
