///--------------------------------------------------
/// RiCE JavaScript Functions - jQuery Version
///--------------------------------------------------

	jQuery(document).ready(function(){

		/// get metatag data
		var rsmPageTitle = $("title").text();

		/// create gallery image links - has to execute before pretty photo lightbox links
/*		jQuery('div[class=rsmGalleryImage]').each(function(i) {
			var imgChk = jQuery(this).attr('id').replace(/^img/,'');
			var imgThb = $(this).html().match('/\/files\/gallery\/([0-9]{1,})\/([0-9]{1,})\.jpg" title="([^"]{1,})"/i');
			if (imgThb.length == 4) { $(this).html("<a href=\"/files/gallery/"+imgThb[1]+"/"+imgThb[2]+'-'+imgChk+".jpg\" rel=\"prettyPhoto[gallery1]\" title=\""+imgThb[3]+"\"><img src=\"/files/gallery/"+imgThb[1]+"/"+imgThb[2]+".jpg\" alt=\"gallery thumbnail\" title=\""+imgThb[3]+"\" /></a>"); }
		}); */

		/// create pretty photo lightbox links
		$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
	
		/// set all external links in the page content to open in a new window
		var domainRegex = new RegExp('^http([s]{0,1}):\/\/'+document.domain);
		$('div#rsmPageContent a[href]').each(function(i) {
			if ((!domainRegex.test($(this).attr('href'))) && (!/^(\/|#)/i.test($(this).attr('href'))) && (!/^javascript/i.test($(this).attr('href')))) { 
				$(this).attr({target: "_blank",title: "Opens in a new window"});
				if ($(this).text().length > 0) { $(this).append(' <img src="/files/template/newWindowIcon.gif" alt="icon" title="Open link in a new window" class="rsmInlineIcon" />'); }
			}
		});

		/// clean up obfuscated email links
		$('span[class=rsmMailTo]').each(function(i) {
			var emailAddress = $(this).html();
			var sp = Math.ceil(emailAddress.length / 2);
			var p1 = emailAddress.substring(0,sp);
			var p2 = emailAddress.substring(sp,sp+sp);
			var e = '';
			for(x=0;x<sp;x++) { e += p1.substring(x,x+1) + p2.substring(x,x+1); }
			$(this).html("<a href=\"mailto:"+e+"\">"+e+"</a> <img src=\"/files/template/emailIcon.gif\" alt=\"email icon\" title=\"email\" class=\"rsmInlineIcon\" /> ");
		});
		
		/// display youtube videos
		$('div[class=rsmYouTubeVideo]').each(function(i) {
			var str = $(this).html().match(/\(([^\-]{1,})\)/);
			var rsmVideoWidth = (rsmContentWidth - 10);
			var rsmVideoHeight = Math.ceil(rsmContentWidth * 0.614583333333333);
			if (str.length == 2) { 
				$(this).fadeOut('fast',function() {
					$(this).html("<iframe class=\"youtube-player\" type=\"text/html\" width=\""+rsmVideoWidth+"\" height=\""+rsmVideoHeight+"\" src=\"http://www.youtube.com/embed/"+str[1]+"\" frameborder=\"0\"></iframe>");
					$(this).fadeIn('slow');
				});
			}
		});

		/// display vimeo videos
		$('div[class=rsmVimeoVideo]').each(function(i) {
			var str = $(this).html().match(/\(([^\-]{1,})\)/);
			var rsmVideoWidth = (rsmContentWidth - 10);
			var rsmVideoHeight = Math.ceil(rsmContentWidth * 0.614583333333333);
			if (str.length == 2) { 
				$(this).fadeOut('fast',function() {
					$(this).html("<iframe src=\"http://player.vimeo.com/video/"+str[1]+"?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff\" width=\""+rsmVideoWidth+"\" height=\""+rsmVideoHeight+"\" frameborder=\"0\"></iframe>");
					$(this).fadeIn('slow');
				});
			}
		});

		/// display breakout quotes
		$('span[class=rsmBreakoutQuote]').each(function(i) { $(this).append(' <span class=\"rsmBreakoutBox1\"><span class=\"rsmBreakoutBox2\"><span class=\"rsmBreakoutPadding\">'+$(this).html()+'</span></span></span> '); });		

		/// display formatted blockquotes
		$('div#rsmPageContent blockquote').each(function(i) {
			var blockQuoteContent = $(this).html();
			$(this).html('<span class="rsmBlockQuoteBox1"><span class="rsmBlockQuoteBox2"><span class="rsmBlockQuotePadding">'+blockQuoteContent+'</span></span></span>');
		});		

		/// display social network sharing and subscription links
		if (jQuery('#rsmPageShare').width() > 0) {
			var pageSharing = (
				"<iframe src=\"http://www.facebook.com/plugins/like.php?href="+escape(rsmCanonicalUrl)+"&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;font=lucida+grande&amp;colorscheme=light&amp;height=35\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:450px; height:35px;\" allowTransparency=\"true\"></iframe>"+
				"<br />"+
				"<a href=\"http://twitter.com/share\" class=\"twitter-share-button\" data-count=\"horizontal\">Tweet</a>"+
				"<a class=\"DiggThisButton DiggCompact\">DIGG This</a>"+
				"<script type=\"text/javascript\" src=\"http://widgets.digg.com/buttons.js\"></script>"+
				"<script type=\"text/javascript\" src=\"http://platform.twitter.com/widgets.js\"></script>"
				);
			$('div#rsmPageShare').css({background:'transparent'});
			$('div#rsmPageShare').css({padding:'0px'});
			$('div#rsmPageShare').html(pageSharing);
		}

		/// start any slideshows on this page
		if (($.browser.msie != undefined) && ($.browser.version == "6.0")) { } else { $('#hdrSlideshow').nivoSlider({ effect:'random',directionNav:false,controlNav:false,keyboardNav:false,pauseOnHover:false,manualAdvance:false}); }
///		if (($.browser.msie != undefined) && ($.browser.version == "6.0")) { alert('IE6'); } else { $('#hdrSlideshow').nivoSlider({ effect:'random',directionNav:false,controlNav:false,keyboardNav:false,pauseOnHover:false,manualAdvance:false,}); }
///		if (($.browser.msie != undefined) && ($.browser.version == "6.0")) { alert('IE6'); } else { $('#hdrSlideshow').nivoSlider(); }

	});
