/**
 * Explore section javascripts for insurace 2009
 *
 */

function prepTooltips() {
	jQuery('.tip').tooltip({
		bodyHandler: function() {
			var elt = jQuery(this);
			var term = elt.attr('term');
			var def = elt.attr('definition');
			var ret = "<div class='point'></div>";
			ret += '<h3>' + term + '</h3>';
			if (def.length > 0) {
				ret += '<p>' + def + '</p>';
			} else {
				ret += '<p><em>no definition</em></p>';
			}
			return ret;
		},
		top : -30,
		left : 40,
		track : true,
		showURL: false
		});
}

function shrinkQuickPlans() {
	// Shring quick plans helper functions
	var showLess = function() {
		//debug.log(jQuery(this).parent()); 
		jQuery(this).parent().prev('.bd').animate({'height':'230px'}, 600, 'swing').removeClass('expanded');
		jQuery(this).toggleClass('less').unbind('click').click(showMore);
		jQuery(this).children('.text').text('Show More');		
	};
	var showMore = function() {
		//debug.log(jQuery(this)); 
		jQuery(this).parent().prev('.bd').animate({'height':'575px'}, 600, 'swing').animate({'height':'100%'}, 600, 'swing');
		jQuery(this).toggleClass('less').unbind('click').click(showLess);
		jQuery(this).children('.text').text('Show Less');
		jQuery('.quick-plan-container').each(function(index, item){
			if (!jQuery(item).parent().hasClass('ui-tabs-hide')) {
				//debug.log(jQuery(item).parent().attr('class'));
				jQuery.scrollTo( jQuery(item).prev(), {'duration' : 'slow', 'axis' : 'y'} );
			}
		});
	};
	// hack to bind 'click' to newly appended elt with .append(...).children('<selector for appended ...>)
	//jQuery('.full-plan-container').css({'display' : 'none'});
	//jQuery('.full-plan-container').prev().css({'display' : 'none'});
	jQuery('.quick-plan-container>li .controls').css({'display' : 'block'});
	jQuery('.section-header>div.button').css({'display' : 'block'});
	jQuery('.quick-plan-container>li .controls').children('a.show-more').click(showLess).click();
	jQuery('.quick-plan-container>li .controls').children('a.show-more').hover(showMoreAnimateOn, showMoreAnimateOff);
	jQuery('.fp-tabs').children('li').children('a').click(function() {
		jQuery(this).parent().parent().css({'border-color' : jQuery(this).parent().css('background-color')});
	});
	jQuery('.fp-tabs').each(function(index, item){
		jQuery(item).children('li:first').children('a').click();
	});
	//jQuery('.fp-tabs').children('li:first').children('a').click();
	jQuery('.quick-plan-container>li .controls').children('div.view-full-plan').click(function() {
		//debug.log(jQuery(this));
		//debug.log('.'+jQuery(this).attr("rel"));
		//jQuery('.full-plan-container').prev().show();
		//jQuery('.full-plan-container').show();
		var button = this;
		jQuery('.full-plan-container').each(function(index, item){
			if (!jQuery(item).parent().hasClass('ui-tabs-hide')) {
				jQuery.scrollTo( jQuery(item).prev(":visible"), {'duration' : 'slow', 'axis' : 'y'} );
				jQuery(item).children('.fp-tabs:visible').children('.'+jQuery(button).attr("rel")).children('a').click();
			}
		});
		//jQuery.scrollTo(jQuery('.full-plan-container').prev(), {'duration' : 'slow', 'axis' : 'y'});
	});
	jQuery('.section-header>div.button').click(function() {
		jQuery(this).toggleClass('minimize');
		jQuery(this).toggleClass('maximize');
		jQuery(this).parent().next().children().toggle('slow');
	});
	/*
jQuery('.quick-plan-container>li .hd').click(function () {
		jQuery(this).parent().find('a.show-more-less').click();
	});
*/
}
function showMoreAnimateOn () {
		if (jQuery(this).parent().prev().height() > 300) {
			jQuery(this).children('.icon').addClass('less_hover');
		}
		else {
			//debug.log(jQuery(this).children('.icon'));
			jQuery(this).children('.icon').addClass('icon_hover');
		}
		
}
function showMoreAnimateOff () {
		jQuery(this).children('.icon').removeClass('less_hover');
		jQuery(this).children('.icon').removeClass('icon_hover');
}
function tabify() {
	var tabs = jQuery('.create-dynamic-tabs')
	if(tabs.length > 0) {
		tabs.tabs();
	}
}
