/*
$.noConflict();
var homeGalleryStop = false;
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);
		});
	});
}
*/

//Map Functions
$(document).ready(function(){
    $("#sd-tab").click(function () {
        $sd = $("#sd");
        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);
        }
    }
}


function goTo(page){
	window.location = page;
}
$(document).ready(function() {	
    	
    	$("#nav" + pageName).addClass("current");
    
    	$('#features').jshowoff({ 
			links: false,
			speed: 9000,
			hoverPause: false,
			effect: 'slideLeft'
		});
		
		$('.jshowoff-play').remove();
		
		$('#main-image').hover(function(){
			$('p.jshowoff-controls').css('display','block');
		}, function(){
			$('p.jshowoff-controls').css('display','none');
		});
		
		$('td.nextPrevious a:first').addClass('leftArrow');
		$('td.nextPrevious a:last').addClass('rightArrow');
		
		$('.sermonTitleLink').click(function(){
			$(this).siblings('.sermonDescription').slideToggle('fast');
		});
		
		
		$('#nav .nav-item').hover(function(){
			$(this).children('.clearfix').css('display','block')
		}, function(){
			$(this).children('.clearfix').css('display','none')
		});
		
		$('.sermonNotes').click(function(){
		    $(this).parent().parent().siblings('.sermonDescription').slideToggle('fast');
		    $(this).parent().parent().parent('.sermonElement').toggleClass('bg');
	    });
	    
	    
	    $(".nav-item").each(function(){
	    	var width = 0;
	    	$(this).children("div").css("display", "block").children("div").each(function(){
	    		var w = $(this).children("a").innerWidth();
	    		if(w > width)
	    			width = w;
	    	});
	    	$(this).children("div").css({"width" : width + "px", "display" : "none"});
	    });
	    
		/*$('#nav .nav-item').hover(function() {
		  $(this).children('.clearfix').css('display','block').animate({
		    opacity: 1
		  }, 5000, function() {
		  $(this).children('.clearfix').css('display','none').animate({
		  	opacity: 0,
		  })
		  });
		});*/

		
		
		
		
    	/*


        //convert richtext popup images to fancybox images
        $(".content 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(".navL").addClass("navLOn");
	        	$(this).children(".navR").addClass("navROn");
	        	var left = $(this).position().left-37;
		        $(this).children(".menus").stop().css({'display':'block', 'top':'42px', 'left': -left}).animate(
		        {
			        opacity: 1
			        //children hover
		        }, "fast").children().hover(
		            
		            function()
		            {
		                $(this).parent().css({'filter':'none'});
		                $(this).addClass('navItemHover');
		                $(this).children('.menuExtra').stop().css({'display':'block', 'top':'0px'}).animate({
			                opacity: 1,
			                left: 0
		                }, "fast");
		            },
		            //children hover out
                    function(){
                        $(this).removeClass('navItemHover');
                        $(this).children('.menuExtra').stop().animate({
	                        opacity: 1,
	                        left: 0
                        }, "fast").animate({
	                        top: -1000
                        }, 2);
                    }
                    //end children hover out
                );
                //end children hover
	        },
	        //first level hover out
	        function(){
	        	if($(this).attr("id") != "aNav" + pageName)
	        	{
		        	$(this).children(".navL").removeClass("navLOn");
		        	$(this).children(".navR").removeClass("navROn");
		        }
		        $(this).children(".menus").stop().animate({
			        opacity: 0
		        }, "fast").animate({
			        top: -1000
		        }, 2);
	        }
	        //end first level hover out
	    );
	    //end first level hover	
	
		//NAVAGATION ADD 2 CORNERS	
		$('#navHolder .aNavName').hover(function(){
			$(this).find('.aNavName').css('color','#ccc09b')
		}, function(){
			$(this).find('.aNavName').css('color','#fff')
		});
		
		
	simple_tooltip(".tip","tooltip");
	//TABLE
	$('#bg .siteContainer .content .contentLeft table').addClass('telco_table');
	$('table tr:eq(0)').addClass('tt_header');
	$('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();
	});
	
	$("#various1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
			
	$("#wdlMls").fancybox({
				'width'				: 636,
				'height'			: 1000,
		        'autoScale'     	: false,
		        'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});
	$("#wdlMls2").fancybox({
				'width'				: 636,
				'height'			: 1000,
		        'autoScale'     	: false,
		        'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});
	$("#houMls").fancybox({
				'width'				: 990,
				'height'			: 1000,
		        'autoScale'     	: false,
		        'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});
	*/
});
