/* This replaces media place holder images with mediaplayers */


(function ($) {
 
 	$(
 		function()
 		{
 			$("img.mediaHolder").each(
 				function (index) {
 					var a = this.id.split('|');
 					var playerType = a[0];
 					var src = a[1];
 					var id = "media_"+index;
 					var w = this.width;
 					var h = this.height

 					var div = $('<div class="mediaholder"></div>').css({ width:w+"px", height:h+"px", display:'inline' });

 					$(this).hide();
 					$(this).before( div );
					
				try {
					switch ( playerType )
					{
						case "flash" :
							div.html( new SWFObject(src, id, w, h, 8).getSWFHTML () );							
							break;
						case "mediaplayer" :
						case "youtube" :
							var mp = new SWFObject("/js/ced/lib/player.swf",id,w,h,9);
							mp.addParam("allowfullscreen","true");
							mp.addVariable("width",w);
							mp.addVariable("height",h);
							mp.addVariable("file",src);
							div.html(mp.getSWFHTML());
							break;
						case "wmvplayer" :
							new jeroenwijering.Player(div.get(0), '/js/ced/lib/wmvplayer.xaml', { file : src, height : h+"", width : w+"" } );
							break;
					}
				} catch (error) {
						alert("Error embedding media player for "+playerType+" : "+src+"\n"+error);
				}
		
				
 				}
 			
 			);
 		}
 	
 	)
 
 
 })(jQuery);
 
function printPartOfPage(elementId) {
	var printContent = document.getElementById(elementId);
	var windowUrl = 'about:blank';
	var uniqueName = new Date();
	var windowName = uniqueName.getTime();
	var printWindow = window.open(windowUrl, windowName, 'width=1,height=1,top=5000,left=5000,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
	printWindow.document.write(printContent.innerHTML);
	printWindow.document.close();
	printWindow.focus();
	printWindow.print();
	printWindow.close();
}

function submitEventForm(view, year, month, week, day) {
	var event_form = document.forms['event_form'];

	//alert("VIEW: " + view + " YEAR: " + year + " MONTH: " + month + " WEEK: " + week + " DAY: " + day);
	event_form.view.value = view;

	if (typeof(year) != "undefined") {
		event_form.ocyear.value = year;
		event_form.year.value = year;
	}
	if (typeof(month) != "undefined") {
		event_form.ocmonth.value = month;
		event_form.month.value = month;
	}
	if (typeof(week) != "undefined") {
		event_form.ocweek.value = week;
	}
	if (typeof(day) != "undefined") {
		event_form.ocday.value = day;
	}

	event_form.submit();
	return true;
}

function submitTextSearch() {
	var event_form = document.forms['event_form'];
	event_form.view.value = "";
	event_form.type.value = "";
	event_form.year.value = "";
	event_form.month.value = "";
	event_form.ocyear.value = "";
	event_form.ocmonth.value = "";
	event_form.ocday.value = "";
}
