function init() {
	Helper.init();
}

function sort_series(id) {
	Sortable.create('sort',
		{ 
			constraint: false,
			overlap:'horizontal',
			onUpdate:function(){
				var keys = Sortable.serialize('sort');
				var url = "/series/order/" + id;
				var myAjax = new Ajax.Request(url, { 
					method: 'post',
					parameters: keys
				});
			}
	});
}


function toggle_loading(b) {
	if (b) {
		var h =  Element.getHeight('sub_header') + 'px';
		$('notifier').style.height = h;
		$('messenger').style.height = h;
		Element.show('notifier', 'messenger')
	} else {
		Element.hide('notifier', 'messenger');
		Helper.init();
	}
}

function validate_new_speaker(form) {
	if (form.elements[0].value == '') {
		alert('Please enter the speaker\'s email');
		return false;
	}
	if (form.elements[1].value == '') {
		alert('Please enter the speaker\'s first name');
		return false;
	}
	if (form.elements[2].value == '') {
		alert('Please enter the speaker\'s last name');
		return false;
	}
	return true;
}

function validate_new_series(form) {
	if (form.elements[0].value == '') {
		alert('Please enter a name for the series');
		return false;
	}
	return true;
}

function validate_profile() {
	if ($F('user_firstName') == '' || $F('user_lastName') == '' || $F('user_email') == '') {
		alert("First name, last name and email are required fields. Make sure you have filled them all in.");
		return false;
	}
	
	if ($F('pass1') != $F('pass2')) {
		alert("Your new passwords must match.")
		return false;
	}
	
	return true;
}

function change_channel() {
	var sel = document.getElementById('channel_id')
	var val = sel.options[sel.selectedIndex].value;
	location.href = "/channel/show/" + val;	
}

function change_series() {
	var sel = document.getElementById('series_id')
	var val = sel.options[sel.selectedIndex].value;
	location.href = "/series/show/" + val;	
}

function kill_more_info(elem) {
	Element.hide(elem);
}

function show_edit() {
	page_array = get_page_size();
	page_scroll = get_page_scroll();
	$('edit_overlay').style.top = (page_scroll[1] + 40) + 'px';
	$('overlay').style.height = page_array[1] + 'px';
	new Effect.Parallel(
		[ new Effect.Appear('overlay', { sync:true, to: 0.6 }), 
		  new Effect.BlindDown('edit_overlay', { sync: true }) ], 
		{ duration: 0.65 }
	);
}

function hide_edit() {
	new Effect.Parallel(
		[ new Effect.Fade('overlay', { sync:true }), 
		  new Effect.BlindUp('edit_overlay', { sync: true }) ], 
		{ duration: 0.65 }
	);
}

function preview(id, feature) {
	Helper.disable();
	page_array = get_page_size();
	page_scroll = get_page_scroll();
	$('preview').style.top = (page_scroll[1] + 40) + 'px';
	$('overlay').style.height = page_array[1] + 'px';
	new Effect.Parallel(
		[ new Effect.Appear('overlay', { sync:true, to: 0.6 }), 
		  new Effect.BlindDown('preview', { sync: true }) ], 
		{ duration: 0.65, 
			afterFinish: function() { write_flash_preview(id); }
		}
	);
}

function write_flash_preview(id) {
	var so = new SWFObject("/swf/preview.swf?sdasdasdas", "preview_swf", "250", "215", "7", "#ffffff");
	so.addVariable("presentation_id", id);
	so.write("preview_container");
}

function kill_preview() {
	$('preview_container').innerHTML = '<img src="/images/loading.gif" />';
	new Effect.Parallel(
		[ new Effect.Fade('overlay', { sync:true }), 
		  new Effect.BlindUp('preview', { sync: true }) ], 
		{ duration: 0.65 }
	);
	Helper.enable();
}

//  Following functions from:
//	Lightbox v2.02
//	by Lokesh Dhakar - http://www.huddletogether.com
//	3/31/06
	
function get_page_scroll() {

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function get_page_size(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}