$(document).ready(function() {

	/* 
	* attach a function to open all links with a class of "external" in a new window 
	* this avoids the use of target="_blank" and allows us to validate as XHTML strict
	*/
	$("a[rel^='external']").click( function() {
		window.open(this.href);
		return false;
	});

	$("a[rel^='prettyPhoto']").prettyPhoto({
		overlay_gallery: false,
		social_tools: false,
		slideshow: false
	});

	/*
	* prevent ie from flickering with css backgrounds
	*/
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {} 

	/*
	* index slideshow
	*/
	if($("#slides > div").size() == 1 ){
		$('#slides div').show();
	} else {
		$('#slides').cycle({
			fx:         'fade',
			timeout:    6000, 
			speed:      900
		});
	}

	
	$('.readmore').each(function() {

		var maxWords = 10;
		var thisTextArray = $(this).text().trim().split(' ');
		var wordcount = $(this).text().trim().split(' ').length;
		
		if(wordcount > maxWords){
			var alteredText = '';
			for(i=0; i < wordcount; i++){
				if(i == maxWords-1){
					alteredText += thisTextArray[i] + ' <a class="openMore" style="cursor:pointer;">... more </a><span class="hide" style="display:none;">';
				} else {
					alteredText += thisTextArray[i] + " ";
				}
			}
			alteredText += '</span>';
			$(this).html(alteredText);
		}

	});
	
	$('.readmore .openMore').click(function(){
		$(this).fadeToggle(100);
		$(this).siblings().fadeToggle(400);
	});

	
});
