// quick and dirty history-managed side-tabs plugin
(function($) {

    // here we go!
    $.hmSideTabs = function(element, options) {

        var defaults = {};

        var plugin = this;
        plugin.settings = {};
        var $element = $(element),  // reference to the jQuery version of DOM element the plugin is attached to
             element = element;		// reference to the actual DOM element

        plugin.init = function() {

            plugin.settings = $.extend({}, defaults, options);
  
            // hide sections to be shown in tabs
            $('.tabsec').hide().css( { position: "absolute", top: "0", width: "100px", left: "-100px" } );
            
            // handle clicks on the tabselect UL, just let the hashchange fire
            $element.find('a').click(function(e) {
            	e.preventDefault();
            	window.location.hash = $(this).attr('href');
            });
            
            $(window).bind('hashchange', function(){
            	plugin.handleHashchange();
            });

			$(window).trigger('hashchange');

        }
        
        plugin.handleHashchange = function(){

            var targetSection = $('#tabselect li:first-child a').attr('href');

            if (window.location.hash) {
                targetSection = window.location.hash;
            }
            
            $element.find('li').removeClass('current');
			$element.find('a[href="'+targetSection+'"]').parents('li').addClass('current');
			
			var tabContent = $(targetSection).html();
			
			$('#viewer').fadeOut(200, function() {                    
                    $('#viewer').html(tabContent).fadeIn(200);
             });

        }

        plugin.init();

    }

    // add the plugin to the jQuery.fn object
    $.fn.hmSideTabs = function(options) {

        return this.each(function() {

            if (undefined == $(this).data('hmSideTabs')) {
                var plugin = new $.hmSideTabs(this, options);
                $(this).data('hmSideTabs', plugin);
            }

        });

    }

})(jQuery);


$(document).ready(function() {

			//set up mailto links.. light defense vs. spambots
			$('.mailto').each(function() {
				var $this 		= $(this);
				var str			= $this.html();
				var newStr 		= str.replace(' (at) ', '@');
				newStr 			= newStr.replace(' (dot) ', '.');
				var link 		= document.createElement('a');
				link.setAttribute('href','mailto:'+newStr+'?subject=email from nwsurgeons.com visitor');
				$(link).text('send email');
				$this.empty().append(link);
			});
			
			$('#tabselect').hmSideTabs();


}); // end main doc.ready statement

function loadGmap(url) {
	iframe = '<iframe id="map" width="525" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="' + url + '"></iframe>';
	$('#mapviewer').html(iframe);
}
