function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
		var my_tooltip = $("#"+name+i);

		$(this).removeAttr("title").mouseover(function(){
				my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
		}).mouseout(function(){
				my_tooltip.fadeOut(400);
		});
	});
}

function goTo(page){
	window.location = page;
}


//Map Functions
$(document).ready(function(){
    $("#trigger").click(function () {
        $sd = $("div#curtain");
        if($sd.is(":visible"))
        {
            $sd.slideUp("slow");
        }else
            $sd.slideDown("slow", function(){
                centerMap();
            });
    });
    initialize();
});

var geocoder;
var map;
var llPoint;
function initialize() {
    if($("#map_canvas").length != 0){
        geocoder = new google.maps.Geocoder();
        var myOptions = {
          zoom: 11,
          //center: latlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        codeAddress();
    }
}

function codeAddress() {
    if (geocoder) {
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            llPoint = results[0].geometry.location;
          map.setCenter(llPoint);
          var marker = new google.maps.Marker({
              map: map,
              size: new google.maps.Size(300, 286),
              position: results[0].geometry.location
          });
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }
}

function centerMap()
{
    if($("#map_canvas").length != 0){
        if(map == null || map == undefined)
            initialize();
        else{
            google.maps.event.trigger(map, 'resize');
            map.setCenter(llPoint);
        }
    }
}

$(document).ready(   
function()
    {
    
    //login box
    $(".loginTrigger").fancybox({
		'width'				: 260,
		'height'			: 230,
        'autoScale'     	: false,
        'transitionIn'		: 'elastic',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
       $(".emailForm").formfocus();
       $("#directionsForm").formfocus();
        //hide popup search results when clicked outside
        $(document).ready(function(){
            $(document).click(function(event) {
                if($(event.target).parents().index($('.search_results')) == -1) {
                    if($('.search_results').is(":visible")) {
                        $('.search_results').hide();
                    }
                }        
            });
		});
        //end convert richtext popup full size images to fancybox images
		
        //convert richtext popup thumb images to fancybox images
        $(".aboutColumnRight a").each(function(){
            var href = $(this).attr("href");
           if(href != undefined){
                var index = href.indexOf("viewImage");
                if(index > -1){
                   href = href.replace("javascript:viewImage('", "");
                   href = href.replace("')","");
                   $(this).attr("href", href);
                   $(this).addClass("single_image"); 
                }
            }
        });
        $("a.single_image").fancybox();
        //end convert richtext popup images to fancybox images
    
	    //first level hover
	    $('.aNavName').hover(
	        function(){
	        	$(this).children('.menus').show().children().hover(
	        		function(){
	        			$(this).addClass('navItemHover');
	        		},
	        		function(){
	        			$(this).removeClass('navItemHover');
	        		}
	        	);
	        },
	        function(){
	        	$(this).children('.menus').hide();
	        }
	    );
	    //end first level hover	

	simple_tooltip(".tip","tooltip");
	//TABLE
	$('#propertyTax table tr:eq(0)').addClass('tt_header');
	$('#propertyTax table tr:odd').addClass('odd');
		
	//Remove Img if it's empty
	$('#bg .siteContainer .content .contentLeft img').each(function(){
		var imgSrc = $(this).attr("src");
		if(imgSrc == "")
			$(this).remove();
	});	
	//Home Fader
	$('#features').jshowoff({ 
		controls: false,
		links: true,
		hoverPause: false,
		changeSpeed: 1200,
		speed: 5000
	});
	
	//Events Agenda View Page
	  	//ACCORDION
	$('.eventButton').click(function() {
		$('.eventButton').removeClass('on');
	 	$('.eventContent').slideUp('fast');
	 	$(".print").hide();
		if($(this).next().is(':hidden') == true) {
			$(this).addClass('on');
			$(this).next().slideDown('fast');
			$(this).children(".print").show();
			SetRSVP();
		 } 
	 });
	 
	 $('.print').click(function(e){
	    e.stopPropagation();
	    $(this).parent().slideDown();
	 });
	  
	$('.eventButton').mouseover(function() {
		$(this).addClass('eOver');
	}).mouseout(function() {
		$(this).removeClass('eOver');										
	});
	$('.eventContent').hide();
	
	$("#wrapper .eventButton:last").css('border-bottom', 'none');
	
	$('#featureDate').hover(function(){
		$("#featureDate ul").css('display','block');
		$("#featureDate li").addClass('listHover');
	},function(){
		$("#featureDate ul").css('display','none');
		$("#featureDate li").removeClass('listHover');
	});
	
	//print popup
	/*
	$(".printTrigger").fancybox({
		'width'				: 700,
		'height'			: 400,
        'autoScale'     	: false,
        'transitionIn'		: 'elastic',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	*/
	$(".printTrigger").printHelper();
	$("#newsLetter").fancybox({
		'width'				: 420,
		'height'			: 264,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	$(".welcome").hoverIntent(
		function () {
        	$("div.welcomeContainer").show();
        },
        function () {
	        $("div.welcomeContainer").hide();
	    }
	);
	
	$(".welcome").click(
		function () {
			$("div.welcomeContainer").hide();
		}
	);
	
	$(".directions").hoverIntent(
		function () {
        	$("div.directionsContainer").show();
        },
        function () {
	        $("div.directionsContainer").hide();
	    }
	);

});
