/* hide the panes on the homepage */

$(document).ready(function() {
	
	$('.jshide').hide();
	
	/* init search text */
	if( $("#search-tec").attr("value") == "" ){
		$("#search-tec").attr("value", "Search this site...");
	}
	/* remove default search text */
	$("#search-tec").focus(function(){
		if( $(this).attr("value") == "Search this site..." ){
			$(this).attr("value", "");
		}
	});
	/* add default search text */
	$("#search-tec").blur(function(){
		if( $(this).attr("value") == "" ){
			$(this).attr("value", "Search this site...");
		}
	});
	/* check search text before submitting */
	$(".search-btn").click(function(){
		if( $("#search-tec").attr("value") == "Search this site..." ){
			$("#search-tec").attr("value", "");
		}
	});			

	/* init subscribe text */
	if( $(".subscribe-email").attr("value") == "" ){
		$(".subscribe-email").attr("value", "Email");
	}
	/* remove subscribe search text */
	$(".subscribe-email").focus(function(){
		if( $(this).attr("value") == "Email" ){
			$(this).attr("value", "");
		}
	});
	/* add subscribe search text */
	$(".subscribe-email").blur(function(){
		if( $(this).attr("value") == "" ){
			$(this).attr("value", "Email");
		}
	});
	/* check subscribe text before submitting */
	$(".subscribe-btn").click(function(){
		if( $(".subscribe-email").attr("value") == "Email" ){
			$(".subscribe-email").attr("value", "");
		}
	});			

	/* init add collection text */
	if( $(".add-collection").attr("value") == "" ){
		$(".add-collection").attr("value", "Add collection...");
	}
	/* remove subscribe search text */
	$(".add-collection").focus(function(){
		if( $(this).attr("value") == "Add collection..." ){
			$(this).attr("value", "");
		}
	});
	/* add subscribe search text */
	$(".add-collection").blur(function(){
		if( $(this).attr("value") == "" ){
			$(this).attr("value", "Add collection...");
		}
	});
	/* check subscribe text before submitting */
	$(".collection-btn").click(function(){
		if( $(".add-collection").attr("value") == "Add collection..." ){
			$(".add-collection").attr("value", "");
		}
	});			
	// knowing triangle :: HOMEPAGE
	$("ul#js-knowing-triangle li").hover(function() {
		$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
		$(this).find('img').stop() /* stop animation queue buildup*/
			.animate({
				width: '140px', /* Set width back to default */
				height: '140px' /* Set height back to default */
			}, { duration: 400, queue: false });		
		if ($(this).hasClass('item-0')){
			$(this).animate({
				top:'15px',
				left: '15px'
			}, { duration: 400, queue: false });
		} else if ($(this).hasClass('item-1')){
			$(this).animate({
				top:'15px',
				right: '15px'
			}, { duration: 400, queue: false });
		} else if ($(this).hasClass('item-2')){
			$(this).animate({
				bottom:'20px',
				left: '88px'
			}, { duration: 400, queue: false });
		};
		// display description
		var currentText = $(this).find('.js-knowing-triangle-desc').html();
		$('#js-knowing-triangle-item-description').html( currentText ).fadeIn(200);
		$('#js-knowing-triangle-description').addClass('hide');
		
		} , function() {
		$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
		$(this).find('img').stop()  /* stop animation queue buildup*/
			.animate({
				width: '114px', /* Set width back to default */
				height: '114px' /* Set height back to default */
			}, { duration: 400, queue: false });
		if ($(this).hasClass('item-0')){
			$(this).animate({
				top:'20px',
				left: '20px'
			}, { duration: 400, queue: false });
		} else if ($(this).hasClass('item-1')){
			$(this).animate({
				top:'20px',
				right: '20px'
			}, { duration: 400, queue: false });
		} else if ($(this).hasClass('item-2')){
			$(this).animate({
				bottom:'20px',
				left: '102px'
			}, { duration: 400, queue: false });
		};
		$('#js-knowing-triangle-item-description').hide();
		$('#js-knowing-triangle-description').removeClass('hide');
	});
	
	// homepage news and events tab
	$("ul.js-tabs").tabs("div.panes > div");


	// knowing triangle :: WIDGET
	$("ul#js-widget-triangle li").hover(function() {
		$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
		$(this).find('img').stop() /* stop animation queue buildup*/
			.animate({
				width: '90px', /* Set width back to default */
				height: '90px' /* Set height back to default */
			}, { duration: 400, queue: false });		
		if ($(this).hasClass('item-2')){
			$(this).animate({
				left: '45px'
			}, { duration: 400, queue: false });
		};
} , function() {
		$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
		$(this).find('img').stop()  /* stop animation queue buildup*/
			.animate({
				width: '78px', /* Set width back to default */
				height: '78px' /* Set height back to default */
			}, { duration: 400, queue: false });
		if ($(this).hasClass('item-2')){
			$(this).animate({
				left: '50px'
			}, { duration: 400, queue: false });
		};
	});

	var currentTallest = 0;
	$('.mainnav a').each(function(){
		if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
	});
	if ($.browser.msie && $.browser.version == 6.0) { $(this).css({'height': currentTallest}); }
	$('.mainnav a').css({'min-height': currentTallest}); 
	
	$('.button').hover(function(){
			$(this).parent().addClass('hover');
		}, function(){
			$(this).parent().removeClass('hover');
	});

	// advanced search select all js
	$('.js-checkall').click(function () {	
		$(this).parents('fieldset').find(':checkbox').attr('checked', this.checked);
	});

	$('.download-group li').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
	});
	$('.download-group li').bind('click',function(){
 		window.location = $(this).find('a').attr('href');
	});
	/* homepage help circle */
	$('.circlemap').attr('src', '/extension/eztec/design/eztec/images/site/blank.gif');
	$('.clink').hover(function () {
		var areaName = $(this).attr('name');
		if (areaName == 'workshops'){
			$('.circle').css({'background-position': '-292px 0'}); 
		} else if(areaName == 'webinars'){
			$('.circle').css({'background-position': '-584px 0'}); 
		} else if(areaName == 'consult'){
			$('.circle').css({'background-position': '-876px 0'}); 
		} else if(areaName == 'research'){
			$('.circle').css({'background-position': '-1168px 0'}); 
		} else if(areaName == 'ask'){
			$('.circle').css({'background-position': '-1460px 0'}); 
		}
	}, function(){
		$('.circle').css({'background-position': '0 0'}); 
	});
	
	$('.close').click(function(){
		$(this).parent().fadeOut('slow');
		return false;
	});
	/* supersleight PNG fix */
	if ($.browser.msie && $.browser.version == 6.0) {
		$("img, .roundabout-bg .controls .js-ui").supersleight({shim: '/extension/eztec/design/eztec/images/site/blank.gif'});
	};
	
	// close my collections share section
	$('.my_collections_form .cancel').click(
		function() {
			$(this).parents('div.email-share').slideToggle('fast');
		}
	);
	if($('.collapsible').length){
		RelatedContent.init();
	}
	if($('.search-filter').length){
		$('.search-filter .button').trigger('click');
	}
});
