jQuery.noConflict();

/* Patient Stories on the page */
var divStories = new Array(
	"simone",
	"amanda",
	"david"
);

/* add additional links to open the story panels */
function addReadMore() {
	for(i=0; i<divStories.length; i++){
		var divID = divStories[i];
		var divName = divStories[i].charAt(0).toUpperCase()+divStories[i].substring(1);
		jQuery("div#"+divID+".story div:not(.photos)").before('<p class="more"><a href="#" onclick="return false;">Read the rest of '+divName+'\'s story</a> <img src="/images/bullet/arrow-pink.png" /></p>');
	}
}
function addHide() {
	jQuery("div.story ul").before('<p class="hide"><img src="/images/icon/hide.png" /></p>');
}
function openPanel(storyID,currentDIV) {
	// get the ID of the parent DIV
	// find out if the class is open or closed
	var storyState = jQuery(currentDIV).attr("class");
	if (storyState == "open") { // prepare to close the story
		jQuery(currentDIV).removeClass("open");
		jQuery(currentDIV+", div#"+storyID+" > h2").addClass("closed");
		jQuery("div#"+storyID+" p.more").show();
		jQuery("div#"+storyID+" ul, div#"+storyID+" p.hide").hide();
	} else if (storyState == "closed") { // prepare to open the story
		jQuery(currentDIV+", div#"+storyID+" > h2").removeClass("closed");
		jQuery(currentDIV+", div#"+storyID+" > h2").addClass("open");
		jQuery("div#"+storyID+" p.more").hide();
		jQuery("div#"+storyID+" ul, div#"+storyID+" p.hide").show();
	}

	// open or close the story
	jQuery(currentDIV).slideToggle();
}


jQuery(document).ready(function(){
	
	/* hide the story divs on page load, add the Read the Rest links */
	addReadMore();
	addHide();
	jQuery("div.story div:not(.photos), div.story ul, div.story p.hide").hide();
	jQuery("div.story div:not(.photos), div.story h2").addClass("closed");
		
	
	
	/* onclick event for story headline */
	jQuery("div.story > h2, div.story p.more, div.story p.hide").click(function () {
		var storyID = jQuery(this).parent().attr("id");
		var currentDIV = "div#"+storyID+" div:not(.photos)";
		openPanel(storyID,currentDIV);
	});
	
	for(i=0; i<divStories.length; i++) {
		if (window.location.hash.substring(1).toLowerCase() == divStories[i]) {
			openPanel(divStories[i],"div#"+divStories[i]+" div:not(.photos)");
			document.location = window.location.hash;
		}
	}

});