// ---------------------------------------
// Custom Javascript for sunsetonline.org
// ---------------------------------------


 
// Output entire lesson content
function lessonOutput(course,courseid,teacher,lesson,type,vidWidth,vidHeight) {
  $(document).ready(function() {
  var output = '';
	var tch_out = '';
  output += '<div class="so_media"><a id="player"></a>';
  output += '<div id="player_trouble">Having trouble with the player? Please see the <a href="http://www.sunsetonline.org/mod/resource/view.php?id=34#troubleshooting">Troubleshooting FAQs</a>.</div>'
	output += '<div id="lesson_return"><a href="http://www.sunsetonline.org/course/view.php?id=' + courseid + '">Return to course page</a></div>';
	output += '</div>';
	
	output += '<div id="so_outline">';
	output += '<object width="100%" height="100%" title="Lesson ' + lesson + ' Outline" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
		  output += '<param value="http://www.sunsetonline.org/dl/outlines/' + course + '/' + lesson + '.swf" name="movie" />';
		  output += '<param value="high" name="quality" />';
		  output += '<param value="transparent" name="wmode" />'
		  output += '<embed wmode="transparent" width="100%" height="100%" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="http://www.sunsetonline.org/dl/outlines/' + course + '/' + lesson + '.swf" />';
	output += '</object>';
	output += '</div>';
	$("#content").html(output);
	
//  $(document).ready(function() {
  if (type == 'audio') {
		// Output the audio player
		teacher = teacher.toLowerCase();
		teacher = teacher.replace(/ /g,"_");
		$("div.so_media","#content").prepend('<div id="teacher_photo"><p align="center"><img src="/theme/sunsetonline1/images/teachers/' + teacher + '.jpg" /></p></div>');
		$("#player").css({display:"block",height:"30px",width:"284px",margin:"0 16px"});
    $f('player',{src:'/js/flowplayer-3.1.2.swf',wmode:'transparent'}, {
      plugins: { 
        rtmp: { 
          url: 'flowplayer.rtmp-3.1.1.swf', 
          netConnectionUrl: 'rtmp://208.116.36.248/oflaDemo' 
        }, 
        controls: { 
          fullscreen: false, 
          height: 30
        }
      }, 
      clip: { 
        url: course+'/audio/'+lesson,
        provider: 'rtmp'
      }
    });
	} else {
		// Output the video player
		// First, check width and height parameters
		if (!vidWidth) {
			vidWidth = 320;
		}
		if (!vidHeight) {
			vidHeight = 218;
		}
		// Add space for the skin and controls
		vidWidth += 22;
		vidHeight += 40;
		var margin = vidWidth+8;
		$("#so_outline").css("margin-left",margin+"px");
		$("#player").css({display:"block",height:vidHeight+"px",width:vidWidth+"px"});
		// Generate output		
    $f('player',{src:'/js/flowplayer-3.1.2.swf',wmode:'transparent'}, {
      plugins: { 
        rtmp: { 
          url: 'flowplayer.rtmp-3.1.1.swf', 
          netConnectionUrl: 'rtmp://208.116.36.248/oflaDemo' 
        } 
      }, 
      clip: { 
        url: course+'/'+lesson,
        provider: 'rtmp',
        scaling:'fit'
      }
    });
	}
	fixH();
	$(window).resize(fixH);
	});
}







// Output a page with Flashpaper only (no video or audio)
function fpOutput(course,filename) {
	var output = '';
	output += '<div id="so_fponly">';
	output += '<object width="100%" height="100%" title="' + filename + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
		  output += '<param value="http://www.sunsetonline.org/dl/outlines/' + course + '/' + filename + '.swf" name="movie" />';
		  output += '<param value="high" name="quality" />';
		  output += '<param value="transparent" name="wmode" />'
		  output += '<embed wmode="transparent" width="100%" height="100%" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="http://www.sunsetonline.org/dl/outlines/' + course + '/' + filename + '.swf" />';
	output += '</object>';
	output += '</div>';
	
	document.write(output);
	$(document).ready(fixH);
}


// Profile reminders for credit students
function profileRemind() {
	output = '<h2>Credit Profile Information</h2>';	
	output += '<p>In order to fully enroll new credit students, there is certain additional information that we need for your file. This information can be entered quickly online, and needs to be completed before we can give you credit for your work.</p>';
	output += '<p>If this is your first course you\'ve taken for credit through SunsetOnline, please return to the main course outline page and click your name in the upper-right corner of the page. On the page that comes up, click the &quot;Edit profile&quot; tab. The additional fields that must be filled out are found in the middle section of the page on this tab.';
	output += '<p>If this is not the first course you\'ve taken for credit through SunsetOnline, please take a moment to check the information in your profile and make sure it is all up-to-date.</p>';
	
	document.write(output);
}


// Size Flashpaper outlines to fill the space available on-screen
function fixH()	{
	d=document
	if (typeof window.innerWidth!='undefined') {
		var type1 = true; // type1 = non-IE
		var winWidth = window.innerWidth;
		var winHeight = window.innerHeight;
	} else {
		if (d.documentElement && 
		typeof d.documentElement.clientWidth!='undefined' && 
		d.documentElement.clientWidth!=0) {
			var winWidth = d.documentElement.clientWidth
			var winHeight = d.documentElement.clientHeight
		} else {
			if (d.body && 
		 	typeof d.body.clientWidth!='undefined') {
		 		var winWidth = d.body.clientWidth
		 		var winHeight = d.body.clientHeight
			}
		}
	}
	// Subtract pixels to account for area occupied by header
	var heightSubtract = 129;
	if (type1) heightSubtract = 110;
	winHeight = winHeight - heightSubtract;
	
	// Check to see if this is a page with a div#so_outline
	if (document.getElementById("so_outline")) {
		// Subtract pixels from width to account for video player and margins
		var widthSubtract = 397;
		if (type1) widthSubtract = 389;
		winWidth = winWidth - widthSubtract;
		// Assign dimensions to the div
		document.getElementById("so_outline").style.height = winHeight + "px";
		//document.getElementById("so_outline").style.width = winWidth + "px";
	}
	// Check to see if this is a page with a div#so_fponly
	if (document.getElementById("so_fponly")) {
		// Subtract pixels from width to account for margins
		var widthSubtract = 44;
		if (type1) widthSubtract = 40;
		winWidth = winWidth - widthSubtract;
		// Assign dimensions to the div
		document.getElementById("so_fponly").style.height = winHeight + "px";
		document.getElementById("so_fponly").style.width = winWidth + "px";
	}
}


// Introductory text on Progress Check or assignment check pages (appears before list of things that should be done)
function progCheck1() {
	output = '<p>By this time you should have:</p>';
	
	document.write(output);
}

// Further explanatory text on Progress Check or assignment check pages (appears after the list of things)
function progCheck2(type) {
	var output = '';
	if (type == 'assignment') {
		output += '<p>If you have completed the above requirement(s), please use this page to confirm it and let us know. First, click the button below. The page will reload with an area below where you can type text. Please type a brief sentence there confirming that you have completed the requirement(s) listed above, and then click the &quot;Save Changes&quot; button.</p>';
	} else {
		output += '<p>Please indicate below whether you have done the above item(s).</p>';
		output += '<p>If you have not, you must catch up on your lessons and/or reading before proceeding any farther in the course.  Once you are caught up, return to this page, click &quot;Yes, I have.&quot;, and then the Submit button.';
	}
	
	document.write(output);
}


// Introductory text on memory work pages (appears before the list of verses)
function memWork1(status) {
	if (status == '1') {
		// First of two or more groups of verses for the course
		output = '<p>As mentioned on the Course Requirements page, the first part of your memory work is due at this point in the course. This consists of the following verses:</p>';
	} else if (status == '2') {
		// Second of two or more groups of verses for the course
		output = '<p>As mentioned on the Credit Requirements page, the second part of your memory work is due at this point in the course. This consists of the following verses:</p>';
	} else {
		// Grouping not specified; output a more generic message that might be suitable for a course with only one grouping of memory work.
		output = '<p>As mentioned on the Credit Requirements page, you have memory work that is due at this point in the course. This consists of the following verses:</p>';
	}
	
	document.write(output);
}

// Further explanatory text on memory work pages (appears after the list of verses)
function memWork2() {
	output = '<p>Your memory work should be checked by a friend or relative who can verify that you memorized these verses.  This can be done in either of two ways:</p>';
	output += '<ol><li>If you quote the verses out loud to the person, the person should follow along in the text of your Bible and ensure that you are quoting the verses accurately.</li><li>If you would prefer to write out the verses rather than quote them out loud, the person should compare your written recitation of the verses to the Biblical text and ensure that you have written the verses accurately.</li></ol>';
	output += '<p>Memory work must be quoted/recited with approximately 80% accuracy or better before it is considered completed. Once you have memorized the verses listed above and accurately quoted them or written them for your memory work checker, click the button below to let us know.  After clicking the button, you will be presented with a box where you can type information.  In the box, please type:</p>';
	output += '<ol><li>A brief sentence affirming that you have successfully completed the memory work listed above.</li><li>The first and last name of the person who is your memory work checker.</li><li>The phone number of the person who is your memory work checker.</li><li>The email address of the person who is your memory work checker.</li></ol>';
	
	document.write(output);
}


// Generic text for papers
function paperInfo() {
	output = '<p>This paper should be typed as a word processing document (using a program such as Word, Wordperfect, or OpenOffice).  Use a standard font (such as Times New Roman), 12 point size, double-spaced, and with 1 inch margins.  List your name, the course title, and the date.  A cover page is optional, and does not count toward the page requirement if used.</p>';
	output += '<p>Do not take the final exam for this course until this assignment has been completed and turned in. When you are ready to turn this assignment in, use the form below to upload the file to be graded.</p>';
	
	document.write(output);
}


// Introductory text for exams
function examIntro(exam) {
	var output = '';
	output += '<div class="highlightbox"><h3>Before you attempt your first exam...</h3><p>The exams on SunsetOnline.org have certain technical requirements and can sometimes be interfered with by pop-up blockers or improperly configured browsers. We want you to be certain that you will not encounter any technical difficulties when you attempt to access this exam. Therefore, if you have not already done so with the web browser you are currently using, please take a moment to visit our Course Samples section and try accessing the sample exam there.</p><p align="center"><a href="http://www.sunsetonline.org/mod/quiz/view.php?id=283" target="_blank">Click here to access the sample exam</a></p> </div>';
	output += '<h3>When to Take This Exam</h3>';
	if (exam == 'midterm') {
		output += '<p>This is the mid-term exam for this course, and should only be attempted once you have already completed any progress checks or memory work that appear above the mid-term on the course outline.  Please proceed to take this mid-term exam <em>only</em> if you have already completed all requirements preceding it on the course outline.</p>';	
	} else if (exam == 'final') {
		output += '<p>This is the final exam for this course, and should only be attempted after all other coursework has been completed.  Please proceed <em>only</em> if you have already completed any and all of the other requirements in the course, including progress checks, memory work, and any assignments or papers.</p>';
	} else {
		output += '<p>This exam should only be attempted once you have already completed any progress checks or memory work that appear above the exam on the course outline.  Please proceed to take this exam <em>only</em> if you have already completed all requirements preceding it on the course outline.</p>';	
	}
	output += '<h3>Taken from Memory</h3>';
	output += '<p>This exam must be taken completely from memory.  You may not consult your textbooks, study outlines, notes, lesson video/audio, or your Bible.</p>';
	output += '<h3>Time Limit</h3>';
	output += '<p>Once you begin the exam, you must finish it within the time limit stated below.  A timer should appear on the page so that you can know how much time you have left.  If you are still working when the time limit runs out, the exam will automatically be submitted.</p>';
	output += '<h3>Do Your Best</h3>';
	output += '<p>Read each question carefully and answer according to the best of your ability.  It is always better to guess than to leave a question unanswered.</p>';
	
	document.write(output);
}