// JavaScript Document
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

(function($){

	$.fn.unwrap = function(elem){
		var elements;
		
		if (elem == null){
			elements = jQuery(this);
		}
		else if (typeof elem == "string"){
			elements = jQuery(this).find(elem);
		}
		else if (typeof elem == "object"){
			elements = elem;
		}
		else alert("unknow elem");
		
		elements.each(function(){
			jQuery(this).parent().replaceWith(jQuery(this));
		});
	}

})(jQuery);  
$(document).ready(function() {
$("img.photoright").dropShadow({left:0, top:0});
$("img.photoleft").dropShadow({left:0, top:0});	
$("img.photocenter").dropShadow({left:0, top:0});	
						   })
$(document).ready(function() {



	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
		$(this).find(".sub").dropShadow();
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			//$(this).calcSubWidth();
			//Set Width
			//$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	var shid = $(this).find(".sub").attr('shadowid');
	$("#"+shid).remove();
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
			
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
	

						   })




$(document).ready(function() {
 $('#jumpMenu').customSelect();
 })
$(document).ready(function() {
$("#go_button").click(function() {						   
var url = $(".customselect").val();
window.location = url;
							   })
})
 $(document).ready(function(){
    // setup ul.tabs to work as tabs for each div directly under div.panes 
  $("ul.tabs").tabs("div.panes > div");
});


function initMenu() {
$('#nav ul').hide();
$('li.active').parent("ul").show();
$('#nav li a').click(
function() {
var checkElement = $(this).next();
if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
return false;
}
if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
$('#nav ul:visible').slideUp('normal');
checkElement.slideDown('normal');
return false;
}
}
);
}
$(document).ready(function() {initMenu();});

 $(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
});
 function theRotator() {
	//Set the opacity of all images to 0
	$('#feature ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('#feature ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',13000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('#feature ul li.show')?  $('#feature ul li.show') : $('#feature ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#feature ul li:first') :current.next()) : $('#feature ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
});
$(function() { 
$("input[rel]").overlay({ 
 
        		expose: 'lightblue', 
        		effect: 'apple', 
onBeforeLoad: function() {  
        
 			var param = $("#ajaxSearch").serialize();
			
            // load the page specified in the trigger 
            //wrap.load(this.getTrigger().attr("href")); 
			$.ajax({
   			type: "POST",
   			url: site_url + "wp-content/themes/athomeprc/index-ajax.php",
   			data: param+"&q=assets/snippets/ajaxSearch/ajaxSearchPopup.php&as_version=1.8.4&subSearch=&ucfg=",
   			success: function(htm){
			if(htm <= 0) {
			var htm = "<h2>Your must enter a search term or terms to view results.<br /> Please try searching again.</h2>"; } else {	
			var htm = "<h2>Your Search results (click the url to navigate to that page)</h2>"+htm;	}
			$("#searchdetails").html(htm);
    		
	   } 
     }); 
			   }
 
	   }); 

 return false; }).load(); 
function directions() { 
								  
$(".openoverlay[rel]").overlay({ 
     		expose: '#000', api: true,
onBeforeLoad: function() {  
var call = this.getTrigger().attr("call");        
 			
            // load the page specified in the trigger 
            //wrap.load(this.getTrigger().attr("href")); 
			$.ajax({
   			type: "POST",
   			url: site_url + "wp-content/themes/athomeprc/func/" + call,
   			data: "&q=assets/snippets/ajaxSearch/ajaxSearchPopup.php&as_version=1.8.4&subSearch=&ucfg=",
   			success: function(htm){
			var htm = htm;	
			$("#overlaycontent").html(htm);
    		
	   } 
     }); 
				   }
 
    }).load(); 

 }; 
 
 function validateme(frm){
	var thisform = "'#"+frm+"'";
    $(frm).validate();
  };
  
function emailthis(t1, t2) { 
								  
$(".openoverlay[rel]").overlay({ 
     		expose: '#000', api: true,
onBeforeLoad: function() {  
var call = this.getTrigger().attr("call");        
 			
            // load the page specified in the trigger 
            //wrap.load(this.getTrigger().attr("href")); 
			$.ajax({
   			type: "POST",
   			url: site_url + "wp-content/themes/athomeprc/func/email_share.php",
   			data: "&func=geform&title="+t1+"&url="+t2,
   			success: function(htm){
			var htm = htm;	
			$("#overlaycontent").html(htm);
    		
	   } 
     }); 
				   }
 
    }).load(); 

 };
$("#saveform").live("click", function() {
 $("#email_share").validate({
	rules: {
    name: "required",
	email2: "required"
	
  },
  messages: {
	  name: "You must enter your name.",
	  email2: "Please enter the email address of the recipient"
	  },
 submitHandler: function(form) {
	var params = $(form).serialize(); 
  $.ajax({
   			type: "POST",
   			url: site_url + "wp-content/themes/athomeprc/func/email_share.php",
   			data: params+"&func=sendform",
   			success: function(htm){
			var htm = htm;	
			$("#overlaycontent").html(htm);
    		
	   } 
     }); 
 }
}); })
$("#send_caregiver_app").live("click", function() {
 $("#caregiver_form").validate({
	rules: {
    name: "required",
	email2: "required"
	
  },
  messages: {
	  name: "You must enter your name.",
	  email2: "Please enter the email address of the recipient"
	  },
 submitHandler: function(form) {
	var params = $(form).serialize(); 
  $.ajax({
   			type: "POST",
   			url: site_url + "wp-content/themes/athomeprc/func/caregiver_handler.php",
   			data: params+"&func=sendform",
   			success: function(htm){
			var htm = htm;	
			$("#form_container").html(htm);
    		
	   } 
     }); 
 }
}); })
$("#saveForm").live("click", function() {
 $("#contact_form").validate({
	rules: {
    name: "required",
	email2: "required"
	
  },
  messages: {
	  name: "You must enter your name.",
	  email2: "Please enter the email address of the recipient"
	  },
 submitHandler: function(form) {
	var params = $(form).serialize(); 
  $.ajax({
   			type: "POST",
   			url: site_url + "wp-content/themes/athomeprc/func/contact_handler.php",
   			data: params+"&func=sendform",
   			success: function(htm){
			var htm = htm;	
			$("#form_container").html(htm);
    		
	   } 
     }); 
 }
}); })
$(document).ready(function() {	
$("#ea").focus(function() {
$("#ea").val("");						
						})
						   })
$(document).ready(function() {	
 $.ajax({
   			type: "POST",
   			url: site_url + "wp-content/themes/athomeprc/func/twitter.php",
   			success: function(htm){
			var htm = htm;	
			$("ul.tweets").html(htm);
    		
	   } 
     });
 $.ajax({
   			type: "POST",
   			url: site_url + "wp-content/themes/athomeprc/func/fbook.php",
   			success: function(htm){
			var htm = htm;	
			$("ul.fbook").html(htm);
    		
	   } 
     });
 })
function linktous() {
$(".sociallink[rel]").overlay({ 
     		expose: '#000', api: true,
onBeforeLoad: function() {  
var call = this.getTrigger().attr("call");        
 			
            // load the page specified in the trigger 
            //wrap.load(this.getTrigger().attr("href")); 
			$.ajax({
   			type: "POST",
   			url: site_url + "wp-content/themes/athomeprc/func/linkto_us.php",
   			success: function(htm){
			var htm = htm;	
			$("#overlaycontent").html(htm);
    		
	   } 
     }); 
				   }
 
    }).load(); }
