jQuery.noConflict();
jQuery(document).ready(function() {
	init();
});

function init() {
	// open external links in new window (checking domain first)
	jQuery("a[href^='http']:not([href*='montand.com'])").each(function() {
		jQuery(this).attr("target", "_blank");
	});
	
	//jQuery("#suckerfishnav li:last-child ").css("border-right","none");
	
	jQuery('a[href=#top]').click(function(){
        jQuery('html, body').animate({scrollTop:0}, 400);
        return false;
    });

	// search term hilighter
	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>';
		}));
	}
});


/* jQuery replaceText - v1.1 - 11/21/2009, (c)2009 Ben Alman 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);

function swapTab(which,tab,numtabs) {
	for (i = 1; i <= numtabs; i++) {
		if (tab == i) {
			document.getElementById(which + i).style.display = "block";
			document.getElementById(which + "Tab" + i).className = "tab-on";
		} else {
			document.getElementById(which + i).style.display = "none";
			document.getElementById(which + "Tab" + i).className = " ";
		}
	}
}
jQuery(document).ready(function($) {
	jQuery('span.vcard a').text('Download vCard');
	
	// show / hide search box
	jQuery("a.search-toggle").click(function () {
		jQuery("#search-slide").slideToggle(400, function() {
			if (jQuery("a.search-toggle").text() == 'Close Search') {
				jQuery("a.search-toggle").text('Search');
			} else {
				jQuery("a.search-toggle").text('Close Search');
			}
		});
	});
});

/* Google Analytics */
var _gaq = _gaq || [];
_gaq.push(
	['_setAccount', 'UA-16159409-8'], //mindshare
	['_setDomainName', '.montand.com'],
	['_trackPageview'],
	['b._setAccount', 'UA-255157-31'], //v1 ga acct
	['b._setDomainName', '.montand.com'],
	['b._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);
})();
