// JavaScript Document
/*
 * jQuery unwrap plugin
 * GPL (GPL-LICENSE.txt) licenses.
 * Created by: Tiziano Treccani
 *
 * $Date: 2008-1-06 12:00:00
 *
 * Version: 1.0
 */
 
(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() {
var childuls = $('ul.subul li:has(ul)')
$(childuls).each(function () {
$(this).removeClass().addClass('subparent');

var child2uls = $('li.subparent ul.subul');
$(child2uls).each(function() {
$(this).removeClass('subul').addClass('megaul');

						   })
						   })

});

$(document).ready(function() {
$('ul.megaul').unwrap();	
var h3 = $(".subparent a:first-child ");
$(h3).each(function () {
$(this).wrap("<h2 style='border-style:none;'></h2>");					 
					 })
	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);
	


});




function slideSwitch() {
    var $active = $('#features a.active');

    if ( $active.length == 0 ) $active = $('#features a:last');

    var $next =  $active.next().length ? $active.next()
        : $('#features a:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


$(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: "index-ajax.php",
   			data: param+"&q=assets/snippets/ajaxSearch/ajaxSearchPopup.php&as_version=1.8.3&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);
    		
	   } 
     }); 
				   }
 
    }); 

 }).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: "assets/templates/seniors/func/" + call,
   			data: "&q=assets/snippets/ajaxSearch/ajaxSearchPopup.php&as_version=1.8.3&subSearch=&ucfg=",
   			success: function(htm){
			var htm = htm;	
			$("#overlaycontent").html(htm);
    		
	   } 
     }); 
				   }
 
    }).load(); 

 }; 
function calendar() { 
								  
$(".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: "assets/templates/seniors/calendar/" + call,
   			data: "&q=assets/snippets/ajaxSearch/ajaxSearchPopup.php&as_version=1.8.3&subSearch=&ucfg=",
   			success: function(htm){
			var htm = htm;	
			$("#overlaycontent").html(htm);
    		
	   } 
     }); 
				   }
 
    }).load(); 

 };  

function theRotator() {
	//Set the opacity of all images to 0
	$('#features ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('#features 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()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('#features ul li.show')?  $('#features ul li.show') : $('#features 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')) ? $('#features ul li:first') :current.next()) : $('#features 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();
});
 $(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
});
 $(document).ready(function(){
    // setup ul.tabs to work as tabs for each div directly under div.panes 
  $("ul.tabs").tabs("div.panes > div");
});
  $(document).ready(function(){
$("#page_content iframe").css("float", "right");							 
							 })
$(document).ready(function() { 
         
    // enable tooltip for "download" element. use the "slide" effect 
    $("a.tt").tooltip({ effect: 'slide'});  
});							 
							 