jQuery.noConflict();

var options = { path: '/', expires: 30 };

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

jQuery(document).ready(function() {
	/*********
		Convert span with class="email" to clickable and Google Analytics tracked link
		
		Input: <span class="email">email @ domain . com</span>
		or:    <span class="email">email(at)domain(dot)com</span>
		or combination of signs and at/dot in text.
		
		Output <a href='mailto:email@domain.com' onclick='...'>email@domain.com</a>

		Optional title attribute can be used for the link text.
		Input: <span class="email" title="email us">email @ domain . com</span>
		Output <a href='mailto:email@domain.com' onclick='...'>email us</a>
		
		26 Nov 2009: Updated replace strings to be case insensitive and not limited to first replacement.
	*********/
	jQuery(".email").each(function() {
		var email = jQuery(this).text().toLowerCase();
		email = email.replace(/\(/g, " ");
		email = email.replace(/\)/g, " ");
		if ((email.indexOf("@") != -1) || (email.indexOf(" at ") != -1) || (email.indexOf(" dot ") != -1)) {
			email = email.replace(/\s+dot\s+/gi, ".");
			email = email.replace(/\s+at\s+/gi, "@");
			var parts = email.split("@");
			if (parts.length == 2) {
				if (jQuery(this).attr('title').length > 0) var text = jQuery(this).attr('title');
				else var text = email;
				var domain = parts[1].split(".");
				email = parts[0].trim() + "@" + domain[0].trim() + "." + domain[1].trim();
				jQuery(this).replaceWith("<a href='mailto:" + email + "' onclick='javascript: pageTracker._trackPageview(\"/email/" + email + "\");'>" + text + "</a>");
			}
		}
	});
	
	/********
	 Add Google Analytics tracking to document links
	 ********/	
	jQuery("a").click(function() {
		if ( jQuery(this).attr("href").match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/i) ) {
			//alert(jQuery(this).attr("href"));
			pageTracker._trackPageview(jQuery(this).attr("href"));
		}
	});
	
	/********
	 Toggle Multi Comment Forms icon
	 ********/	
	jQuery(".CommentForm").each(function() {
		var form = this;
		jQuery(this).before("<div id='toggle" + jQuery(this).attr("id") + "' class='value toggleComment'><img src='pagemulticomments/images/internet-group-chat-pen.png' alt='Add a comment' width='26' height='22'/><span>Add a comment</span></div>");
		var icon = jQuery("#toggle" + jQuery(this).attr("id"));
		jQuery(icon).click(function() {
			jQuery(form).toggle();
			return false;
		});
		jQuery(this).hide();
		//jQuery(icon).attr("id");
		//alert(jQuery(this).attr("id"));
	});	

	/********
	 Toggle Multi Comments in page, show only all comments at bottom of page
	 ********/	
	jQuery(".CommentHolder").each(function() {
		var form = this;
		if (jQuery(this).attr("id") != "CommentHolder_") { // Don't hide CommentHolder showing all comments
			//var class = ;
			//if (jQuery(this).attr("class").indexOf("CurrentMember") == -1) { // Only hide if not CurrentMember class present
				jQuery(this).before("<div id='toggle" + jQuery(this).attr("id") + "' class='value toggleComment'><img src='pagemulticomments/images/internet-group-chat.png' alt='View comment(s)' width='27' height='22'/><span>View comment(s) on this section</span></div>");
				var icon = jQuery("#toggle" + jQuery(this).attr("id"));
				jQuery(icon).click(function() {
					jQuery(form).toggle();
					return false;
				});
				jQuery(this).hide();
				//jQuery(icon).attr("id");
				//alert(jQuery(this).attr("id"));
			//}
		}
	});	

}); 
