// ---------------------------------------
// Custom Javascript for sunsetonline.org
// ---------------------------------------

var pgCourse;
var pgCourseID;
var pgTeacher;
var pgLesson;
var pgType;
var pgVidWidth;
var pgVidHeight;

// Output entire lesson content
function lessonOutput(course,courseid,teacher,lesson,guide,type,vidWidth,vidHeight) {
	if (typeof(lesson)=="object") {
		larr = lesson;
		var lesson = larr[0];
		var mySelect = multiMovie(larr);
	} else {
		var mySelect = "";
	}
	
pgCourse = course;
pgCourseID = courseid;
pgTeacher = teacher;
pgLesson = lesson;
pgType = type;
pgVidWidth = vidWidth;
pgVidHeight = vidHeight;
	
	var output = '';
	var tch_out = '';
  output += '<a id="player"></a>';
	
//	output += '<div class="so_media">';
	if (type == 'audio') {
		// Output the audio player
		teacher = teacher.toLowerCase();
		teacher = teacher.replace(/ /g,"_");
		//output = '<div id="teacher_photo"><p align="center"><img src="/es/theme/sunsetonline1/images/teachers/' + teacher + '.jpg" /></p></div>'+output;
		$("#player").css({display:"block",height:"30px",width:"284px",margin:"0 16px"});
    $(document).ready(function() {
    $f('player','/js/flowplayer-3.1.2.swf', {
      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;
		}
		// Generate output		
		vidWidth += 22;
		vidHeight += 40;
		// Generate output		
    $(document).ready(function() {
		$("#player").css({display:"block",height:vidHeight+"px",width:vidWidth+"px"});
    $f('player','/js/flowplayer-3.1.2.swf', {
      plugins: { 
        rtmp: { 
          url: 'flowplayer.rtmp-3.1.1.swf', 
          netConnectionUrl: 'rtmp://208.116.36.248/oflaDemo' 
        } 
      }, 
      clip: { 
        url: course+'/'+lesson,
        provider: 'rtmp',
        scaling:'fit'
      }
    });
    });
	}
	
	output += mySelect;
	output += '<div id="player_trouble">'+text.lesson.trouble+'</div>'
	output += '<div id="lesson_return">'+text.lesson.ret+'</div>';
//	output += '</div>';
	
	$("div.so_media").html(output);
	
	$("#moviechange").change(function() {
		var lesson = $("#moviechange").val();
    $f().getClip(0).update({url:pgCourse+'/'+lesson});
	});
	
//	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/es/dl/outlines/' + course + '/' + guide + '.swf" name="movie" />';
		  output += '<param value="high" name="quality" />';
		  output += '<embed width="100%" height="100%" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="http://www.sunsetonline.org/es/dl/outlines/' + course + '/' + guide + '.swf" />';
	output += '</object>';
//	output += '</div>';
	
	//document.write(output);
	$("#so_outline").html(output);
	fixH();
}

function lessonOutput_old(course,courseid,teacher,lesson,guide,type,vidWidth,vidHeight) {
	if (typeof(lesson)=="object") {
		larr = lesson;
		var lesson = larr[0];
		var mySelect = multiMovie(larr);
	} else {
		var mySelect = "";
	}
	
pgCourse = course;
pgCourseID = courseid;
pgTeacher = teacher;
pgLesson = lesson;
pgType = type;
pgVidWidth = vidWidth;
pgVidHeight = vidHeight;
	
	var output = '';
//	output += '<div class="so_media">';
	if (type == 'audio') {
		// Output the audio player
		teacher = teacher.toLowerCase();
		teacher = teacher.replace(/ /g,"_");
		output += '<div id="teacher_photo"><p align="center"><img src="/es/theme/sunsetonline1/images/teachers/' + teacher + '.jpg" /></p></div>';
		
		output += '<div id="mediaHolder"><object width="320" height="50" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="FLVAudioPlayer">';
		output += '<param name="movie" value="so_audio_player.swf" />';
		output += '<param name="salign" value="lt" />';
		output += '<param name="quality" value="high" />';
		output += '<param name="scale" value="noscale" />'; 
		output += '<param name="FlashVars" value="audiopath=rtmp://cp33928.edgefcs.net/ondemand/_definst_/33928/' + course + '/audio/' + lesson + '.flv" />';
		output += '<embed width="320" height="50" src="so_audio_player.swf" quality="high" flashvars="audiopath=rtmp://cp33928.edgefcs.net/ondemand/_definst_/33928/' + course + '/audio/' + lesson + '.flv" name="FLVAudioPlayer" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		output += '</object></div>';
	} 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 += 51;
		// Generate output		
		output += '<div id="mediaHolder"><object width="' + vidWidth + '" height="' + vidHeight + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="FLVPlayer">'; 
		output += '<param name="movie" value="FLVPlayer_Streaming.swf" />';
		output += '<param name="salign" value="lt" />';
		output += '<param name="quality" value="high" />';
		output += '<param name="scale" value="noscale" />'; 
		output += '<param name="FlashVars" value="&MM_ComponentVersion=1&serverName=cp33928.edgefcs.net&skinName=Halo_Skin_3&appName=ondemand/_definst_&streamName=33928/' + course + '/' + lesson + '&isLive=false&bufferTime=0&autoPlay=false&autoRewind=true" />';
		output += '<embed src="FLVPlayer_Streaming.swf" flashvars="&MM_ComponentVersion=1&serverName=cp33928.edgefcs.net&skinName=Halo_Skin_3&appName=ondemand/_definst_&streamName=33928/' + course + '/' + lesson + '&isLive=false&bufferTime=0&autoPlay=false&autoRewind=true" quality="high" scale="noscale" width="' + vidWidth + '" height="' + vidHeight + '" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		output += '</object></div>';				
	}
	
	output += mySelect;
	output += '<div id="player_trouble">'+text.lesson.trouble+'</div>'
	output += '<div id="lesson_return">'+text.lesson.ret+'</div>';
//	output += '</div>';
	
	$("div.so_media").html(output);
	
	$("#moviechange").change(function() {
		var lesson = $("#moviechange").val();
		var newFlash = '<object width="' + pgVidWidth + '" height="' + pgVidHeight + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="FLVPlayer">'; 
		newFlash += '<param name="movie" value="FLVPlayer_Streaming.swf" />';
		newFlash += '<param name="salign" value="lt" />';
		newFlash += '<param name="quality" value="high" />';
		newFlash += '<param name="scale" value="noscale" />'; 
		newFlash += '<param name="FlashVars" value="&MM_ComponentVersion=1&serverName=cp33928.edgefcs.net&skinName=Halo_Skin_3&appName=ondemand/_definst_&streamName=33928/' + pgCourse + '/' + lesson + '&isLive=false&bufferTime=0&autoPlay=false&autoRewind=true" />';
		newFlash += '<embed src="FLVPlayer_Streaming.swf" flashvars="&MM_ComponentVersion=1&serverName=cp33928.edgefcs.net&skinName=Halo_Skin_3&appName=ondemand/_definst_&streamName=33928/' + pgCourse + '/' + lesson + '&isLive=false&bufferTime=0&autoPlay=false&autoRewind=true" quality="high" scale="noscale" width="' + pgVidWidth + '" height="' + pgVidHeight + '" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

		$("#mediaHolder").html(newFlash);
	});
	
//	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/es/dl/outlines/' + course + '/' + guide + '.swf" name="movie" />';
		  output += '<param value="high" name="quality" />';
		  output += '<embed width="100%" height="100%" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="http://www.sunsetonline.org/es/dl/outlines/' + course + '/' + guide + '.swf" />';
	output += '</object>';
//	output += '</div>';
	
	//document.write(output);
	$("#so_outline").html(output);
	fixH();
}
function multiMovie(movies) {
	var mySelect = '<form><select id="moviechange">';
	var i = 1;
	for(m in movies) {
		mySelect +='<option value="'+movies[m]+'">Video '+i+'</option>'; 
		i++;
	}
	mySelect +='</select></form>';
	return mySelect;
}

function changeMovie() {
	
}

// 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/es/dl/outlines/' + course + '/' + filename + '.swf" name="movie" />';
		  output += '<param value="high" name="quality" />';
		  output += '<embed width="100%" height="100%" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="http://www.sunsetonline.org/es/dl/outlines/' + course + '/' + filename + '.swf" />';
	output += '</object>';
	output += '</div>';
	
	document.write(output);
	fixH();
}


// Profile reminders for credit students
function profileRemind() {
	document.write(text.profile);
}


// 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 = 229;
	if (type1) heightSubtract = 210;
	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 = '';
	
	document.write(text.progress1);
}

// 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 = text.progress2.assignment;
	} else {
		output = text.progress2.other;
	}
	
	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 = text.memory1.one;
	} else if (status == '2') {
		// Second of two or more groups of verses for the course
		output = text.memory1.two;
	} else {
		// Grouping not specified; output a more generic message that might be suitable for a course with only one grouping of memory work.
		output = text.memory1.def;
	}
	
	document.write(output);
}

// Further explanatory text on memory work pages (appears after the list of verses)
function memWork2() {
	
	document.write(text.memory2);
}


// Generic text for papers
function paperInfo() {
	document.write(text.papers);
}


// Introductory text for exams
function examIntro(exam) {
	var output = text.exam.head;
	if (exam == 'midterm') {
		output += text.exam.midterm;	
	} else if (exam == 'final') {
		output += text.exam.final;
	} else {
		output += text.exam.def;	
	}
	output += text.exam.foot;
	
	document.write(output);
}