// Global vars
var fadeSpeed = 500;

$(document).ready(function() {
	
	loadStoryUploader();

	$('.openStory').live('click',function(){
		
		var storySrc = $(this).attr('alt');

		populateStory(storySrc);

		return false;
	});

	$('#close_story').live('click',function(){
		$('#story_container').fadeOut(fadeSpeed);
		return false;
	});

	if (window.location.hash != null){
		hash = window.location.hash;
	}
		
	if( hash.length >= 2  ) {

		goTo = hash.substring(1);
		fadeSpeed = 0;	
		$(".openStory[alt="+goTo+"]").click();
		fadeSpeed = 500;
	}

	
	// Show Story Sumbission form
	$('#story_sub_upload').live('click',function(){
		$('#close_story').click();
		$('#story_sub_container').fadeIn(0);
		return false;
	});

	// Hide Story Sumbission form
	$('#close_story_sub').live('click',function(){
		$('#story_sub_container').fadeOut(0);
		return false;
	});


}); // End (document).ready

/////////////////////////////////////////////////////////////////

function populateStory(storyID){
		
	$('#story_ajax').load("content/"+storyID+".html","",function(){
		setLocationHash(storyID);
	});
		
	$('#story_container').fadeIn(fadeSpeed);
}

/////////////////////////////////////////////////////////////////

function setLocationHash(value){
	window.location.hash = value;
	return false;
}

/////////////////////////////////////////////////////////////////

function loadStoryUploader(){

	var params = {	menu: "false",
					bgcolor: "#FFFFFF",
					allowFullScreen: "false"
				 };

	var flashvars = {
					};			
	
	 swfobject.embedSWF("flash/rally_story_upload.swf", "flash_story_sub_upload", "785", "700", "9.0.0", "expressInstall.swf", flashvars, params);
}