
jQuery(document).ready(function(){

	if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
		jQuery('#header-logo').css({ left: 0 });
	}

	var locations = new Array();
	locations['orange'] = false;
	locations['losangeles'] = false;
	locations['sandiego'] = false;
	locations['northern'] = false;

	var types = new Array();
	types['residential'] = false;
	types['assisted'] = false;
	types['skilled'] = false;
	types['dementia'] = false;
	types['home'] = false;

	function filterCommunities(){
		jQuery('#footer .filter a').each(function(){
			var activated = true;
			for ( var typ in types ) {
				if ( types[typ] && !jQuery(this).hasClass(typ) ) activated = false;
			}
			for ( var loc in locations ) {
				if ( locations[loc] && !jQuery(this).hasClass(loc) ) activated = false;
			}
			if (activated) {
				if(jQuery.browser.msie){//IE
					jQuery(this).parent('li').animate({ opacity: 1 },'fast');
				}else{
					jQuery(this).animate({ opacity: 1 },'fast');
				}
			} else {
				if(jQuery.browser.msie){//IE
					jQuery(this).parent('li').animate({ opacity: .25 },'fast');
				}else{
					jQuery(this).animate({ opacity: .25 },'fast');
				}
			}
		});
	}

	var numOn = 0;

	jQuery('#footer .right li').click(function(){

		var curli = jQuery(this);
		var type = curli.attr('id');
		
		if(!curli.hasClass("On")){
			curli.addClass("On");
			curli.find('label').css({ opacity: 1 }).prev('.checkbox').css({ backgroundPosition: '-12px' });
			numOn++;
		}else{
			curli.removeClass("On");
			curli.find('label').css({ opacity: .25 }).prev('.checkbox').css({ backgroundPosition: '0px' });
			numOn--;
		}
		types[type] = curli.hasClass("On");
		if (numOn) {
			jQuery('#footer .right li.lo').each(function(){
				if(!jQuery(this).hasClass("On")){
					jQuery(this).find('label').animate({ opacity: .25 },'fast');
				} else {
					jQuery(this).find('label').animate({ opacity: 1 },'fast');
				}
			});
		}
		else {
			jQuery('#footer .right li.lo').find('label').animate({ opacity: 1 },'fast');
		}

		filterCommunities();

	});

	jQuery('#footer .right li.lo:not(.On)').live('mouseover',function(){
		if (numOn) jQuery(this).find('label').stop(true,true).animate({ opacity: 1 },0);
	});
	jQuery('#footer .right li.lo:not(.On)').live('mouseout',function(){
		if (numOn) jQuery(this).find('label').stop(true,true).animate({ opacity: .25 },0);
	});

	jQuery('#footer .right select').change(function(){

		var curop = jQuery(this).children('option:selected');
		var location = curop.val();

		if ( location == "all" ) {
			locations['orange'] = false;
			locations['losangeles'] = false;
			locations['sandiego'] = false;
			locations['northern'] = false;
		}
		else {
			for ( var loca in locations ) locations[loca] = false;
			locations[location] = true;
		}

		filterCommunities();

	});

	jQuery('.living-expenses-calculator form.lecForm input[type="text"]').blur(function(){
		var decimalIt = Number(jQuery(this).val());
		if ( decimalIt ) jQuery(this).val(decimalIt.toFixed(2));
	}).numeric({allow:"."}).keyup(function(){
		var livingExpenses = 0;
		jQuery('.living-expenses-calculator form.lecForm input[type="text"]').each(function(){
			livingExpenses += Number(jQuery(this).val());
		}).parent().parent().find('input[name="total"]').val(livingExpenses).parent().parent().find('input[name="totalShow"]').val(livingExpenses.toFixed(2));
	});
	var lecValidate = jQuery('.living-expenses-calculator form.lecEmailForm').validate({
		errorLabelContainer: "span.callback",
		submitHandler: function(form) {
			var email = jQuery(form).parent().find('input[name="lecEmail"]').val();
			jQuery(form).prevAll('form.lecForm').children('input[name="email"]').val(email);
			jQuery.post(
				themeURL+"/actions.php",
				jQuery('form.lecForm').serialize(),
				function(data) {
					jQuery('.living-expenses-calculator span.callback').show().html(data);
				}
			);
		}
	});
	jQuery('.living-expenses-calculator input:reset').click(function(){
		lecValidate.resetForm();
		jQuery('.living-expenses-calculator').find('input[name="totalShow"]').val("0.00");
		jQuery('.living-expenses-calculator').find('input[name="lecEmail"]').val("");
	});

	jQuery.extend(jQuery.fn.disableTextSelect = function() {
        return this.each(function(){
            if(jQuery.browser.mozilla){//Firefox
                jQuery(this).css('MozUserSelect','none');
            }else if(jQuery.browser.msie){//IE
                jQuery(this).bind('selectstart',function(){return false;});
            }else{//Opera, etc.
                jQuery(this).mousedown(function(){return false;});
            }
        });
    });
    jQuery('.textResizer, .textResizer *').disableTextSelect();


	jQuery('a.top').slideto({
		target : '#top',
		speed  : 1000
	});
	
	
	jQuery('.careerlisting .clTitle').click(function(){
		if (jQuery(this).hasClass('Open')) {
			jQuery(this).removeClass('Open').css({ backgroundImage: 'url('+themeURL+'/library/img/icons/arrow-down.gif)' }).next('.clDescription').slideUp(250);
		}
		else {
			jQuery(this).addClass('Open').css({ backgroundImage: 'url('+themeURL+'/library/img/icons/arrow-up.gif)' }).next('.clDescription').slideDown(500);
		}
	});
	jQuery('.careerlisting:eq(0) .clTitle').css({ borderTop: '0px' });


	var hrwH = jQuery('#header-right-wrap').height();
	jQuery(window).scroll(function(){
		if (navigator.platform != 'iPad' && navigator.platform != 'iPhone' && navigator.platform != 'iPod') {
			var winW = jQuery(window).width();
			var adjL = (( winW - 960 ) / 2 < 0) ? 0 : Math.ceil(( winW - 960 ) / 2);
			var adjR = (( winW - 980 ) / 2 < 0) ? 0 : Math.ceil(( winW - 980 ) / 2);
			if (jQuery(window).scrollTop() > 390) jQuery('.submenu > ul').css({ position: 'fixed', left: adjL, top: '20px' });
			else jQuery('.submenu > ul').css({ position: 'static', left: '', top: '' });
			jQuery('img.tab-site-options').css({ right: adjR });
			if ( hrwO ) {
				if (jQuery(window).scrollTop() > 0) {
					jQuery('img.tab-site-options').fadeIn();
					jQuery('#header-right-wrap').css({ position: 'fixed', right: adjL, top: 0 });
				}
				else {
					jQuery('#header-right-wrap').css({ position: 'absolute', right: 40, top: 0 });
					jQuery('img.tab-site-options').fadeOut();
				}
			}
			else {
				if (jQuery(window).scrollTop() > hrwH + 5) {
					jQuery('img.tab-site-options').fadeIn();
					jQuery('#header-right-wrap').css({ position: 'fixed', right: adjL, top: ( hrwH + 14 ) * -1 });
				}
				else {
					jQuery('#header-right-wrap').css({ position: 'absolute', right: 40, top: 0 });
					jQuery('img.tab-site-options').fadeOut();
				}
			}
			jQuery('#header-right-wrap .flyout').fadeOut(300);
		}
	});

	jQuery('img.tab-site-options').click(function(){
		if (jQuery('#header-right-wrap').hasClass('open')) {
			jQuery('img.tab-site-options').attr('src',themeURL+'/library/img/misc/tab-site-options.png');
			if ( jQuery(window).scrollTop() < hrwH ) var adjT = jQuery(window).scrollTop();
			else var adjT = (hrwH + 14);
			jQuery('#header-right-wrap').removeClass('open').animate({ top: adjT * -1 },500);
			hrwO = false;
		}
		else {
			jQuery('img.tab-site-options').attr('src',themeURL+'/library/img/misc/tab-site-options-o.png');
			jQuery('#header-right-wrap').addClass('open').animate({ top: 0 },500);
			hrwO = true;
		}
	});

	jQuery('img.tab-site-options').hover(function(){
		if ( hrwO ) jQuery(this).attr('src',themeURL+'/library/img/misc/tab-site-options-o-h.png');
		else jQuery(this).attr('src',themeURL+'/library/img/misc/tab-site-options-h.png');
	},function(){
		if ( hrwO ) jQuery(this).attr('src',themeURL+'/library/img/misc/tab-site-options-o.png');
		else jQuery(this).attr('src',themeURL+'/library/img/misc/tab-site-options.png');
	});

	if (jQuery.browser.msie) jQuery('.affordable-housing:even').css({ clear: 'left' });

	jQuery('.wpgmappity_container div:last-child span,.wpgmappity_container div:last-child a').hide();

	jQuery('.submenu > ul').find('ul.children').each(function(){
		var parentLI = jQuery(this).parent("li");
		if(jQuery(this).find('.current_page_item').length){
			parentLI.prepend('<div class="subnavExpandArrow">&nbsp;</div>');
		} else {
			parentLI.prepend('<div class="subnavCollapseArrow">&nbsp;</div>');
			jQuery(this).hide();
		}
	});

});

var hrwO = false;

jQuery(window).resize(function(){

	var winW = jQuery(window).width();
	var hrwH = jQuery('#header-right-wrap').height();
	var subL = (( winW - 960 ) / 2 < 0) ? 0 : ( winW - 960 ) / 2;
	jQuery('.submenu ul').css({ left: subL });
	var hrwR = (( winW - 960 ) / 2 < 0) ? ( 960 - winW ) * -1 : ( winW - 960 ) / 2;
	if ( hrwO ) {
		if (jQuery(window).scrollTop() > 0) {
			jQuery('#header-right-wrap').css({ right: Math.ceil(hrwR) });
		}
	}
	else {
		if (jQuery(window).scrollTop() > hrwH + 5) {
			jQuery('#header-right-wrap').css({ right: Math.ceil(hrwR) });
		}
	}

});


