$(document).ready(function() { 
	$('ul.sf-menu').superfish({
			dropShadows: 	false,
			animation: {height: 'show'}
	});

	$(".toggle").toggle(function() {
		$(".hide").slideDown();
		$(this).html("<img src='images/close.png' />");
	}, function() {
		$(".hide").slideUp();
		$(this).html("Learn more >");
	});
	
	$('.hidemap').click(function(e){
		e.preventDefault();
		$('.map').fadeOut();
		$(this).fadeOut();

	});

	$("#menuwithchild a.parent").toggle(function() {
		if ($(this).parent().hasClass('showchild')) {
			$(this).next('ul').slideUp();
		} else {
			$(this).next('ul').slideDown();
		}
	}, function() {
		if ($(this).parent().hasClass('showchild')) {
			$(this).next('ul').slideDown();
		} else {
			$(this).next('ul').slideUp();
		}
	});
	
	$(".colgoal a.parent").toggle(function() {
		if($(this).next('ul').hasClass('firsttime')){
			$(this).next('ul').slideUp();	
			$(this).removeClass('hidbutton');						
		}else{
			$(".colgoal a.hidbutton").next('ul').slideUp();
			$(".colgoal a.hidbutton").removeClass('hidbutton');
			$("ul.firsttime").slideUp();
			$(this).next('ul').slideDown();
			$(this).addClass('hidbutton');
		}
	}, function() {
		if($(this).next('ul').hasClass('firsttime')){
			$(".colgoal a.hidbutton").next('ul').slideUp();
			$(".colgoal a.hidbutton").removeClass('hidbutton');
			$(this).next('ul').slideDown();
			$(this).addClass('hidbutton');
		}else{
			$(this).next('ul').slideUp();
			$(this).removeClass('hidbutton');	
		}
	});
	
	if( $('#slider').length > 0){
		$('#slider').nivoSlider({
			effect:'fade',
			captionOpacity:1,
			animSpeed:1500, //Slide transition speed
	    	pauseTime:8000
		});
	}
	$('#stop').live('click', function(e){
		e.preventDefault();		
		$(this).attr('id','play');
		$( '#slider' ).data( 'nivoslider' ).stop();
	});
	$('#play').live('click', function(e){
		e.preventDefault();		
		$(this).attr('id', 'stop');
		$( '#slider' ).data( 'nivoslider' ).start();				
	});
	if( $('.icons').length > 0 ){
		$('.icons').betterTooltip({speed: 150, delay: 300});	
	}
	if( $('blockquote').length){
		$('blockquote').quovolver(500, 15000);
	}
	
	// added by Debiprasad on 11th Oct., 2011 -- start
	// checks whether browser supports placeholder and applies js for browsers which don't support it
	if(!Modernizr.input.placeholder){
	
		$('[placeholder]').focus(function() {
		  var input = $(this);
		  if (input.val() == input.attr('placeholder')) {
			input.val('');
			input.removeClass('placeholder');
		  }
		}).blur(function() {
		  var input = $(this);
		  if (input.val() == '' || input.val() == input.attr('placeholder')) {
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		  }
		}).blur();
		$('[placeholder]').parents('form').submit(function() {
		  $(this).find('[placeholder]').each(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
			  input.val('');
			}
		  })
		});
	}
	// added by Debiprasad on 11th Oct., 2011 -- end
	
	// added by Debiprasad on 13th Oct., 2011 -- start
	// the following code enables placeholder for the input under the menu. placeholder property does not save when we save html via custom content html editor
	$('#zipcode_menu').focus(function() {
	  var input = $(this);
	  if (input.val() == 'Zip Code') {
		input.val('');
		input.removeClass('placeholder');
	  }
	}).blur(function() {
	  var input = $(this);
	  if (input.val() == '' || input.val() == 'Zip Code') {
		input.addClass('placeholder');
		input.val('Zip Code');
	  }
	}).blur();
	
	$('#zipcode_menu').parents('form').submit(function() {
		var input = $('#zipcode_menu');
		if (input.val() == 'Zip Code') {
		  input.val('');
		}
	});
	
	// checks cookies set by save location preference and shows those values accordingly
	if ($.cookie('location_pref_zip')) {
		$('#zipcode').val($.cookie('location_pref_zip'));
	}
	if ($.cookie('location_pref_distance')) {
		$('#miles').val($.cookie('location_pref_distance'))
	}
	// for search fields under menu
	if ($.cookie('location_pref_zip')) {
		$('#zipcode_menu').val($.cookie('location_pref_zip'));
	}
	if ($.cookie('location_pref_distance')) {
		$('#miles_menu').val($.cookie('location_pref_distance'))
	}
	// added by Debiprasad on 13th Oct., 2011 -- end
	
	// added by Debiprasad on 18th Oct., 2011 -- start
	$('#content #corporateform #submit').click(function () {
		sendCorpConact();
		return false;
	});
	
	$('#cartform.giftcard select#oa_quantity').change(function() {
		calculateGiftCardTotal();
	});
	$('#cartform.giftcard input[type=radio][name=oa_id]').change(function() {
		calculateGiftCardTotal();
	});
	// added by Debiprasad on 18th Oct., 2011 -- end

	$('#cartform.savingcard select#oa_quantity').change(function() {
		var quantity = $('#cartform select#oa_quantity').val();
		var total = quantity * 50;
		$('#wellness_saving_card_total').html('$' + total + '.00');
	});
	
	$('#sliderprovider').nivoSlider({
	    effect:'fade',
	    captionOpacity:1,
		directionNavHide: true,
	    controlNav: true,
		controlNavThumbs: true
	});
	
	$('#header #searchbar #submit').click(function(event) {
		event.preventDefault();
		saveFindLocation();
	});

	$('.sf-menu .mega .location #submit').click(function(event) {
		event.preventDefault();
		saveFindLocation('menu');
	});
});

// added by Debiprasad on 13th Oct., 2011 -- start
// saves/unsets location preference of search
function saveFindLocation(element_location) {
	element_location = typeof(element_location) != 'undefined' ? '_' + element_location : '';
	
	var input = $('#zipcode' + element_location);
	if (input.val() == 'Zip Code') {
	  input.val('');
	}
	
	$.cookie('zip', $('#zipcode' + element_location).val(), { path: '/' });		// Shall we set cookie for that particular path?
	$.cookie('dist', $('#miles' + element_location).val(), { path: '/' });

	if ($('#save_location' + element_location + ':checked').val() == 'Save') {
		$.cookie('location_pref_zip', $('#zipcode' + element_location).val(), { expires: 365, path: '/' });
		$.cookie('location_pref_distance', $('#miles' + element_location).val(), { expires: 365, path: '/' });
	} else {
		$.cookie('location_pref_zip', null, { path: '/' });
		$.cookie('location_pref_distance', null,  { path: '/' });
	}
	
	if (element_location) {
		document.location = 'http://www.wellnesspossibilities.com/listing/guide/';
	} else {
		document.location = $('#header_find_categories').val();
	}
}
// added by Debiprasad on 13th Oct., 2011 -- end

// added by Debiprasad on 18th Oct., 2011 -- start
// sends email from Corporate Wellness page more info form
function sendCorpConact() {
	//validation
	if ($.trim($('input[name=firstname]').val()) == '') {
		alert('Please enter your first name.');
		$('input[name=firstname]').focus();
		return false;
	}
	
	if ($.trim($('input[name=lastname]').val()) == '') {
		alert('Please enter your lastname name.');
		$('input[name=lastname]').focus();
		return false;
	}
	
	if ($.trim($('input[name=company]').val()) == '') {
		alert('Please enter your company name.');
		$('input[name=company]').focus();
		return false;
	}
	
	if ($('select[name=state]').val() == '') {
		alert('Please enter your state.');
		$('select[name=state]').focus();
		return false;
	}
	
	if ($.trim($('input[name=email]').val()) == '') {
		alert('Please enter your email.');
		$('input[name=email]').focus();
		return false;
	}
	
	if ($.trim($('input[name=phone]').val()) == '') {
		alert('Please enter your phone.');
		$('input[name=phone]').focus();
		return false;
	}
	
    $.post('/includes/code/corp_contact.php', {
        firstname: $('input[name=firstname]').val(),
        lastname: $('input[name=lastname]').val(),
        company: $('input[name=company]').val(),
        state: $('select[name=state]').val(),
        email: $('input[name=email]').val(),
        phone: $('input[name=phone]').val(),
        comments: $('textarea[name=comments]').val()
    },
    function (data) {
       alert(data);
       $('input[name=firstname]').val('');
       $('input[name=lastname]').val('');
       $('input[name=company]').val('');
       $('select[name=state]').val('');
       $('input[name=email]').val('');
       $('input[name=phone]').val('');
       $('textarea[name=comments]').val('');
    });
}

function calculateGiftCardTotal() {
	var amountArray = new Array();
	amountArray['GiftCard025'] = 25;
	amountArray['GiftCard040'] = 40;
	amountArray['GiftCard050'] = 50;
	amountArray['GiftCard075'] = 75;
	amountArray['GiftCard100'] = 100;
	amountArray['GiftCard150'] = 150;
	amountArray['GiftCard200'] = 200;
	amountArray['GiftCard250'] = 250;
	amountArray['GiftCard500'] = 500;
	var quantity = $('#cartform select#oa_quantity').val();
	var giftcard = $('#cartform input[type=radio][name=oa_id]:checked').val();
	var amount = amountArray[giftcard];
	var total = quantity * amount;
	
	$('#wellness_gift_card_total').html('$' + total + '.00');
}
// added by Debiprasad on 18th Oct., 2011 -- end
