jQuery.noConflict();
jQuery(document).ready(function() {
	init();
});

function init() {
	// open external links in new window (checking domain first)
	jQuery("a[href^='http']:not([href*='climbsantafe.com'])").each(function() {
		jQuery(this).attr("target", "_blank");
	});
	
	jQuery("#suckerfishnav li:last-child ").css("margin-right","0");
	jQuery("#LoginWithAjax_Info *").replaceText( /(blog)/gi, "site" );

	var mouse_is_inside = false;
	var panel_is_open = false;

	// Expand Panel
	jQuery("#open").click(function(){
		jQuery("div#panel").slideDown("slow");
		panel_is_open = true;
	});	
	// Collapse Panel
	jQuery("#close").click(function(){
		jQuery("div#panel").slideUp("slow");
		panel_is_open = false;
	});	
	
	jQuery('#toppanel').hover(function(){ 
		mouse_is_inside = true; 
	}, function(){ 
		mouse_is_inside = false; 
	});
	
	jQuery("body").mouseup(function(){
		//console.log(panel_is_open);
		if(!mouse_is_inside && panel_is_open) {
			jQuery("div#panel").slideUp("slow");
			jQuery("#toggle a").toggle();
			panel_is_open = false;
		}
	});
		
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	jQuery("#toggle a").click(function () {
		jQuery("#toggle a").toggle();
	});
	
	jQuery('a[href=#top]').click(function(){
        jQuery('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });
	
	/*jQuery('#community #slides').jcarousel({
		auto: 4,
		scroll: 4,
		wrap: 'circular',
		buttonPrevHTML: null,
		buttonNextHTML: null,
		initCallback: mycarousel_initCallback
	});*/
	
	if (typeof(mcms_query) != 'undefined') {
		var area;
		var i;
		var s;
		for(s in mcms_areas) {
			area = jQuery(mcms_areas[s]);
			if(area.length != 0) {
				for(var l = 0; l < area.length; l++) {
					for(i in mcms_query) {
						area.eq(l).highlight(mcms_query[i], 1, 'highlight term-' + i);
					}
				}
				break;
			}
		}
	}
}

// search term hilighter
jQuery.fn.extend({
	highlight: function (term, insensitive, span_class) {
		var regex = new RegExp('(<[^>]*>)|(\\b' + term.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1") + ')', insensitive ? 'ig' : 'g');
		return this.html(this.html().replace(regex, function (a, b, c) {
			return (a.charAt(0) == '<') ? a : '<span class="' + span_class + '">' + c + '</span>';
		}));
	}
});

function mycarousel_initCallback(carousel) {
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});
	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});
	
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};

/*
 * jQuery replaceText - v1.1 - 11/21/2009
 * http://benalman.com/projects/jquery-replacetext-plugin/
 * 
 * Copyright (c) 2009 Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($){$.fn.replaceText=function(b,a,c){return this.each(function(){var f=this.firstChild,g,e,d=[];if(f){do{if(f.nodeType===3){g=f.nodeValue;e=g.replace(b,a);if(e!==g){if(!c&&/</.test(e)){$(f).before(e);d.push(f)}else{f.nodeValue=e}}}}while(f=f.nextSibling)}d.length&&$(d).remove()})}})(jQuery);

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16159409-17']);
_gaq.push(['_setDomainName', '.climbsantafe.com']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
