// JavaScript Document

var fadeTime = 800;
var loader = "<img class='loading' alt='loading' src='../../images/empty-pixels.gif'>";

$(document).ready(function() {
	
	$(".standard").on("click", null, function(e) {
		if($(this).hasClass('plusIcon2') && !$(this).hasClass('expander') ){
			$(this).replaceWith(loader);		
		}else {
			$(this).replaceWith(loader);
		}
		return false;
	});
	
	$("#ben_btn_Outpatient").on("click", null, function() {
		if($(this).hasClass('plusIcon2')){
			$(this).replaceWith(loader);
			$("#outpatientAdditional").slideDown(fadeTime);
		}else{
			$(this).replaceWith(loader);
			$("#outpatientAdditional").slideUp(fadeTime);
		}
	});
	
	$("#ben_btn_Maternity").on("click", null, function() {
		if($(this).hasClass('plusIcon2')){
			$(this).replaceWith(loader);
			$("#maternityAdditional").slideDown(fadeTime);
		}else{
			$(this).replaceWith(loader);
			$("#maternityAdditional").slideUp(fadeTime);
		}
	});
	
	$("#optionalBenefitDeductibleSelect").on("change", null, function() {
		$("#ben_btn_Outpatient").replaceWith(loader);
	});
	
	$("#outpatientBenefitCoInsuranceOptionsSelect").on("change", null, function() {
		$("#ben_btn_Outpatient").replaceWith(loader);
	});
	
	$("#maternityBenefitCoInsuranceOptionsSelect").on("change", null, function() {
		$("#ben_btn_Maternity").replaceWith(loader);
	});
	
	$('#leftContent').bind('mouseenter', function() {
		$('.tooltipAnchorAjax').tooltip({
			position : "center top",
			relative : true,
			offset : [ -12, 20 ]
		});
	});
	
});




$(function(){
	attachBenefitHandlers();
});

function attachBenefitHandlers(){
	$('#dep1AddAddress').hide();
	$('#dep2AddAddress').hide();
	$('#addDependant1').hide();
	$('#addDependant2').hide();
	$("#datepicker").hide();
	if($("#ben_btn_Outpatient").hasClass('plusIcon2') ){	
		$("#outpatientAdditional").hide();
	}
	if($("#ben_btn_Maternity").hasClass('plusIcon2') ){	
		$("#maternityAdditional").hide();
	}
	$("#lifeAdditional").hide();
	$("#accidentAdditional").hide();
	$("#incapacityAdditional").hide();
	$('#silverContent').hide();
	$('#goldContent').hide();
	
	var copyright=new Date();
	var currYear=copyright.getFullYear();
	$("#copyDate").text(currYear + " Cigna");

	$('.tooltipAnchor').tooltip({ 
		position: "center top",
		relative: true,
		offset: [-12, 20]
	});
	
	$('.tooltipAnchorSelect').click(function(){ 
		$('.tooltipSelect').hide();									 
		$(this).next().show();
	});
	
	$('.tooltipAnchorSelect').blur(function(){ 
		$('.tooltipSelect').hide();
	});
	
	$('body').click(function() {
		$('.tooltipSelect').hide();
	});
	
	$(".tooltipAnchorSelect").click(function(event) {
		 event.stopPropagation();
	});
	

	try {

		$("#slider").slider({
				min : 0,
				max : 2,
				value : 2,
				step : 1,
				slide : function(event, ui) {
					$("#amount").val("$" + ui.value);
				}
			});
	
		$("#amount").val("$" + $("#slider").slider("value"));

	} catch (err) {
		// ignore this error when loaded from PersonalInformationLiteV4.html as the JQuery versions are different from the standard Tapestry pages
	}
	
	
	
	$(".paymentContainer span").each(function() {
		$(this).click(function() {
			$(this).attr('class', 'singleBoxSelected');
			$('.paymentContainer span').not(this).attr('class','singleBox');
		});
	});
	
	$(".dateContainer span").each(function() {
		$(this).click(function() {
			if($(this).hasClass('topBox')) {
				$(this).next().attr('class', 'bottomBoxSelected');
				$('.topBox').not(this).next().attr('class','bottomBox');
				if($(this).hasClass('topBoxDate') || $(this).hasClass('bottomBoxDate')){
					//Do nothing
				}else {
					$('#otherMonth').text("--");
					$('#otherDay').text("Other");
				}
			}else if($(this).hasClass('bottomBox')) {
				$(this).attr('class', 'bottomBoxSelected');
				$('.bottomBoxSelected').not(this).attr('class','bottomBox');
				if($(this).hasClass('topBoxDate') || $(this).hasClass('bottomBoxDate')){
					//Do nothing
				}else {
					$('#otherMonth').text("--");
					$('#otherDay').text("Other");
				}
			}
		});
	});
	
	$('.selectButton').each(function() {
		$(this).click(function() {
			$(this).attr('class','selectButtonOff').attr('alt','Product selected button image').attr('title','Product selected');
			$('.selectButtonOff').not(this).attr('class','selectButton').attr('alt','Select product button image').attr('title','Select this product');
			return false;
		});
	});
	
    //Documents tab table functions
	var navBar = $('<div id="tableNavBar"><ul><li id="tab1" class="silver"><a href="#" id="silverTab">Silver<br /> from $1000</a></li><li id="tab2" class="gold"><a href="#" id="goldTab">Gold<br /> from $1000</a></li><li id="tab3" class="selected platinum"><a href="#" id="platinumTab">Platinum<br /> $1500 per month</a></li></ul></div>');
	
	navBar.insertBefore('#tableContent');


	$('#silverTab').click(function() {
			$('#tab1').addClass('selected');
			$('#tab2').removeClass('selected');
			$('#tab3').removeClass('selected');
			$('#silverContent').show();
			$('#goldContent').hide();
			$('#platinumContent').hide();
			return false;
	});

	$('#goldTab').click(function() {
			$('#tab1').removeClass('selected');
			$('#tab2').addClass('selected');
			$('#tab3').removeClass('selected');
			$('#silverContent').hide();
			$('#goldContent').show();
			$('#platinumContent').hide();
			return false;
	});
	
	$('#platinumTab').click(function() {
			$('#tab1').removeClass('selected');
			$('#tab2').removeClass('selected');
			$('#tab3').addClass('selected');
			$('#silverContent').hide();
			$('#goldContent').hide();
			$('#platinumContent').show();
			return false;
	});

}