// JavaScript Document
var intSelStory = 0;
var recTot =0;
var cPage = 0;
var nPage = 0;
var strSortArgs = "";
var arrReqs = new Array();
var reqInProgress=false;

function change_page(pageIn){
	cPage=pageIn;
	var poststr = "change_page=" +cPage;			
	var strFunc = 'update_table';
	if(strSortArgs)
		poststr += "&" + strSortArgs;
	make_req(strContentURL + 'listing.php',strFunc,poststr,'POST');
	show_update_new('divListingDisplay');
}

function change_news_page(pageIn){
	nPage=pageIn;
	var poststr = "change_page=" +nPage;			
	var strFunc = 'update_news';
	if(strSortArgs)
		poststr += "&" + strSortArgs;
	make_req(strAjaxURL + 'news.php',strFunc,poststr,'POST');
	show_update_new('divNewsMain');
}
function update_news(strArgs){
	$('divNewsMain').innerHTML = strArgs;
	hide_update_new('divNewsMain');
}

function update_table(strArgs){
	$('divListingDisplay').innerHTML = strArgs;
	hide_update_new('divListingDisplay');
	new Effect.Highlight($('divListingDisplay'));
}


function objReq(url, funcName, qry, getpost, uqID, arg2, arg3, arg4, arg5){
	this.url=url;
	this.funcName=funcName;
	this.qry=qry;
	this.getpost=getpost;
	this.uqID =  uqID;
	this.arg2 = arg2;
	this.arg3 = arg3;
	this.arg4 = arg4;
	this.arg5 = arg5;
}

function queue_rec(url, funcName, qry, getpost, uqID, arg2, arg3, arg4, arg5){
	var cReq = new objReq(url, funcName, qry, getpost, uqID, arg2, arg3, arg4, arg5);
	arrReqs.push(cReq);
	setTimeout('tryReq()',250);
}

function tryReq(){
	if(arrReqs.length > 0){
		if(!reqInProgress){
			//reverse to grab the first item in the array
			arrReqs.reverse();
			var cReq = arrReqs.pop();
			//If theres still reqs waiting reverse back again 
			if(arrReqs.length > 0)
				arrReqs.reverse();
			make_req(cReq.url, cReq.funcName, cReq.qry, cReq.getpost, cReq.uqID, cReq.arg2, cReq.arg3, cReq.arg4, cReq.arg5);
		}
		setTimeout('tryReq()',250);
	}
}
	
function make_req(url, funcName, qry, getpost, uqID, arg2, arg3, arg4, arg5){
	//alert("MAKEREQ:" + url + ', ' + funcName+ ', ' + qry+ ', ' + getpost+ ', ' + uqID+ ', ' + arg2);	
	var getpost = (getpost == null) ? "GET" : getpost;
	if(reqInProgress){
		queue_rec(url, funcName, qry, getpost, uqID, arg2, arg3, arg4, arg5);
	}else{
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				//http_request.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject) { // IE
			try {
					http_request = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						http_request = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {}
				}
		}
		if (!http_request) {
			alert('Giving up :( Cannot create an XMLHTTP instance');
			reqInProgress=false;		
			return false;
		} else {
			reqInProgress=true;
			http_request.open(getpost, url, true);
			http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http_request.onreadystatechange =   function() {
				if (http_request.readyState == 4) {
					strResponse = http_request.responseText;
					//hide_working();
					 switch (http_request.status) {
						case 404:
							alert('Error: Not Found. The requested URL ' + url + ' could not be found.');
							reqInProgress=false;
							break;
						 // Display results in a full window for server-side errors
						case 500:
							alert('Error: Not Found. The requested URL ' + url + ' could not be found. (500)');
							handleErrFullPage(strResponse);
							reqInProgress=false;
							break;
						default:
							if (strResponse.indexOf('Error:') > -1 || 
								strResponse.indexOf('Debug:') > -1) {
								alert(strResponse);
								reqInProgress=false;
							}
								// Call the desired result function
							else {
								//alert(funcName + '(' + uqID + ',  strResponse);')
								if(uqID){
									if(arg4)
										eval(funcName + '(uqID,  strResponse, arg2, arg3, arg4, arg5);');
									else if(arg4)
										eval(funcName + '(uqID,  strResponse, arg2, arg3, arg4);');
									else if(arg3)
										eval(funcName + '(uqID,  strResponse, arg2, arg3);');
									else if(arg2)
											eval(funcName + '(uqID,  strResponse, arg2);');
									else
										eval(funcName + '(uqID,  strResponse);');
									
								}else
									eval(funcName + '(strResponse);');
								reqInProgress=false;
							}
							break;
					}
				}
				//else
					//show_working();
			}
			//alert(qry);
			http_request.send(qry);
		}
	}
}


function handleErrFullPage(strIn) {
	var errorWin;
	// Create new window and display error
	try {
			errorWin = window.open('', 'errorWin');
			errorWin.document.body.innerHTML = strIn;
	}
	// If pop-up gets blocked, inform user
	catch(e) {
			alert('An error occurred, but the error message cannot be' +
					' displayed because of your browser\'s pop-up blocker.\n' +
					'Please allow pop-ups from this Web site.');
	}
}

function show_update_new(divTarget,strMsg){
	var dTarget = $(divTarget);
	var dUpdate = $('divUpdate_' + dTarget.id);
	if(dUpdate == null)
		dUpdate = document.createElement('div');
	
	dUpdate.id = 'divUpdate_' + dTarget.id;	
	dUpdate.addClassName("divUpdate");
	dUpdate.style.display = "none";
	dUpdate.style.zIndex = "5000";
	
	if(!strMsg)
		strMsg="Working...";		
	dUpdate.innerHTML =  strMsg;	
	
	document.getElementsByTagName('body')[0].appendChild(dUpdate);
	
	dUpdate.absolutize();
	Effect.Appear('divUpdate_' + dTarget.id, {duration: 0.15, fps:50, from:0.0, to:0.8});
	dUpdate.clonePosition(dTarget);
	
	//hide_form_elms(divTarget);
}

function hide_update_new(divTarget){
	var dTarget = $(divTarget);	
	if(dTarget){
		var dUpdate = $('divUpdate_' + dTarget.id);
		//alert('divUpdate_' + dTarget.id);
		if(dUpdate){
			//alert(dUpdate.id);
			Effect.Fade('divUpdate_' + dTarget.id, {duration: 0.15, fps:50});
		}
	}
}

function do_invite(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal(false, 640, 'divInviteForm');
		//$('divInvSuccess').style.display;
		//$('btnInvSub').appear();
		//var field_area = $('divRecipients');
		//if(recTot > 0)
			//field_area.innerHTML = "";
	 	//var inpEmail = $('strInvEmail');
		//inpEmail.value = "";
	}
}

function remove_recipient(liID){
	 if(!document.getElementById) return; //Prevent older browsers from getting any further.
	 var field_area = $('divRecipients');
	 var recli = $(liID);
	 if(recli){
		 field_area.removeChild(recli);
		 recTot--;
	 }	
	 if(recTot == 0)
		 field_area.innerHTML = "";
}

function invite_cancel(){
	 var field_area = document.getElementById('divRecipients');
	 field_area.innerHTML = "";
	 var inpEmail = $('strInvEmail');
	 inpEmail.value = "";
	 recTot == 0;
	 destroyModal();	
	Effect.DropOut('divInviteForm', {fps:50});
}



function add_inv_addy() {
 var field_area =$('divRecipients');
 var value=$('strInvEmail').value;
 if(addValid.validate()) {
	 if(value){
		 if(recTot == 0)
			 field_area.innerHTML = "";
		 if(document.createElement) { //W3C Dom method.
		  var li = document.createElement("li");
		  var input = document.createElement("input");
		  input.name = "to_email[]";
		  input.id = "to_email"+recTot.toString();
		  input.value = value;
		  input.type = "hidden"; //Type of field - can be any valid input type like text,file,checkbox etc.
		  li.innerHTML = value + "<A style=\"cursor:pointer\" onclick=\"javascript:remove_recipient('li" + recCnt + "')\"> [ Remove ]</a>";
		 li.setAttribute('id',"li" + recCnt);
		  li.appendChild(input);
		  field_area.appendChild(li);
		 } else { //Older Method
		  field_area.innerHTML += "<LI id=\"li" + recCnt + "\">" + value + " <A  style=\"cursor:pointer\" onclick=\"javascript:remove_recipient('li" + recCnt + "')\">[ Remove ]</a> <input name='to_email['" + value + "']' id='to_email' type='hidden' value='" + value + "' /></LI>";
		 }
	 	recCnt++;
	 	recTot++;
	 //Clear field value
	 document.getElementById('strEmail').value = "";
	}	
 }
 return false;
}

function submit_invite(){
	if(invValid.validate()){
		strFunc = 'after_invite';			
		var poststr = "action=save_invite&" + get_arg_list('frmInvite');
		//alert(poststr);
		make_req(strAjaxURL + 'save_invite.php',strFunc,poststr,'POST');
		//show_update('tableOutput');									
	}
	return false;
}
function after_invite(strArgs){
	if(strArgs == "SUCCESS"){
		$('divInviteSuccess').style.display="";
		$('divInviteFormBody').style.display="none";
	}else
		alert(strArgs);
}

function do_select_story(strNumIn){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		if(intSelStory != strNumIn){
			var divNew = $('divStory_' + strNumIn);
			var divOld = $('divStory_' + intSelStory);
			var divTarg = $('divStory');
			intSelStory = strNumIn;
			for(var i=1; i <=4; i++){
				do_unhover_pic(i);
			}
			divTarg.innerHTML = divNew.innerHTML;
			divOld.display = "none";
			divTarg.style.zIndex = "100";
			divNew.style.zIndex = "50";
		}
	}
}

function do_hover_pic(strNumIn){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else if (strNumIn >0){
		//var divTitleDest = $('divStoryHead');
		//var divBodyDest = $('divStoryBody');
		//var divTitleSrc = $('divStoryHead_' + strNumIn);
		//var divBodySrc = $('divStoryBody_' + strNumIn);
		var imgImage = $('imgHover_' + strNumIn);
		//alert("DEBUG: 'imgHover_" + strNumIn + "' = " + imgImage );
		imgImage.src = "img/hover_" + strNumIn + "_on.jpg";
		if(intSelStory != strNumIn){
			var divNew = $('divStory_' + strNumIn);
			var divTarg = $('divStory');
	
			divNew.absolutize();
			divNew.clonePosition(divTarg) 
			divNew.style.zIndex = "400";
			divNew.appear({duration: 0.25});
		}
		//alert(imgImage.Src);
		//divTitleDest.innerHTML = divTitleSrc.innerHTML;
		//divBodyDest.innerHTML = divBodySrc.innerHTML;
	}
}

function do_unhover_pic(strNumIn){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
	//alert(intSelStory + " != " +  strNumIn + " = " + (intSelStory != strNumIn));
	var divNew = $('divStory_' + intSelStory);
	if(intSelStory != strNumIn){
		var imgImage = $('imgHover_' + strNumIn);
		var divOld = $('divStory_' + strNumIn);
		
		do_hover_pic(intSelStory);		
		imgImage.src = "img/hover_" + strNumIn + "_off.jpg";
		divOld.fade({duration: 0.25});	
		divOld.style.zIndex = "10";
		//alert(imgImage.Src);
	}else {
		var divOld = $('divStory_' + intSelStory);
		divOld.style.zIndex = "100";
	}
	//if(divNew.style.display == "")
		//divNew.appear({duration: 0.25});
	}
}

var arrSticky = new Array();
var arrStuck = new Array();

function show_pop(strAuth,strTarg){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
	var dDiv = $('divPop_'+ strAuth);
	var objTarg = $(strTarg);
	//alert(strAuth+ ' , ' + strTarg);
	dDiv.absolutize();
	dDiv.clonePosition(objTarg, {offsetTop : objTarg.getHeight(), offsetLeft : -12}) 
	dDiv.style.width = "200px";
	dDiv.style.height = "auto";
	dDiv.appear({ duration: 0.15 });
	//alert(objTarg.id);
	}
}

function hide_pop(strAuth, force){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
	var dDiv = $('divPop_'+ strAuth);
	if(force){
		arrStuck = arrStuck.without(strAuth);	
	}
	setTimeout('fade_pop(\'' + strAuth + '\')',200);
	}
}

function fade_pop(strAuth){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
	var dDiv = $('divPop_'+ strAuth);
	//alert('Sticky: ' + arrSticky.indexOf(strAuth) + ' Stuck: ' + arrStuck.indexOf(strAuth));
	if(arrSticky.indexOf(strAuth) < 0 && arrStuck.indexOf(strAuth) < 0)
		dDiv.fade({ duration: 0.15 });
	}
}

function make_pop(strAuth){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
	if(arrSticky.indexOf(strAuth) >= 0)
		arrSticky = arrSticky.without(strAuth);
	else
		arrSticky.push(strAuth);
	}
}


var recCnt = 0;
var recTot = 0;

function do_sendemail(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal(null, 630, 'divUpdateForm');
		//$('divSendEmailForm').style.display = "none";
		//$('divInvSuccess').style.display = "";
	}
}
function copy_twit(){
	var strVal = $('strTwit').value;
	if(window.clipboardData){  
   	 window.clipboardData.setData('text',strVal);  
    } else  {  
       	var clipboarddiv=document.getElementById('divclipboardswf');  
  	 	if(clipboarddiv==null) {  
      		clipboarddiv=document.createElement('div');  
        	clipboarddiv.setAttribute("name", "divclipboardswf");  
       		clipboarddiv.setAttribute("id", "divclipboardswf");  
       		document.body.appendChild(clipboarddiv);  
    	}  
        clipboarddiv.innerHTML='<embed src="clipboard.swf" FlashVars="clipboard='+  encodeURI(strVal)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';  
    }  
    return false;  
}

function submit_sendemail(){
	if(eValid.validate()){
		strFunc = 'after_sendemail';			
		var poststr = "action=send_email&" + get_arg_list('frmEmail');
		make_req(strAjaxURL + 'send_email.php',strFunc,poststr,'POST');
		//show_update('tableOutput');									
	}
	return false;
}
function after_sendemail(strArgs){
	if(strArgs == "SUCCESS"){
		$('divSendEmailForm').style.display = "none";
		$('divInvSuccess').style.display = "";
	}else
		alert(strArgs);
}


function do_resources(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal(null, null, 'divResourceForm');
	}
}
function resource_cancel(){
	destroyModal();	
	Effect.DropOut('divResourceForm', {fps:50});
}

function do_screening(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal(null, null, 'divScreeningForm');
		toggle_play();
	}
}

function screening_cancel(){
	destroyModal();	
	Effect.DropOut('divScreeningForm', {fps:50});
}



function do_listing(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal(null, null, 'divListingDisplay');
	}
}

function listing_cancel(){
	destroyModal();	
	Effect.DropOut('divListingDisplay', {fps:50});
}

function do_screening_disp(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal(null, null, 'divScreeningDisplay');
	}
}

function screening_disp_cancel(){
	destroyModal();	
	Effect.DropOut('divScreeningDisplay', {fps:50});
}


function do_letter(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal(null, 650, 'divLetterForm');
	}
}

function letter_cancel(){
	destroyModal();	
	Effect.DropOut('divLetterForm', {fps:50});
}

function letter_print(){
	window.open('http://www.amnesty.ca/lubicon/content/letter_form.php?print=1','_PRINT','toolbar=1,status=1,scrollbars=1, resizeable=1,width=650,height=800');
}




function do_competition(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal(null, null, 'divCompetitionForm');
	}
}

function competition_cancel(){
	destroyModal();	
	Effect.DropOut('divCompetitionForm', {fps:50});
}


function do_rss(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal(null, 500, 'divRSSForm');
		var strFunc = 'show_rss';
		var poststr;
		make_req(strAjaxURL + 'rss.php',strFunc,poststr,'POST');
	}
}

function show_rss(strArgs){
	$('divRSSContent').innerHTML = strArgs;
}

function do_subscribe_submit(){
	if(newsValid.validate()){
		strFunc = 'after_subscribe';			
		var poststr = "action=subscribe&" + get_arg_list('frmNewsletter');
		make_req(strAjaxURL + 'subscribe.php',strFunc,poststr,'POST');
		//show_update('tableOutput');									
	}
	return false;
}
function after_subscribe(strArgs){
	if(strArgs == "SUCCESS"){
		var objSub = $('aSubmitNewsletter');
		objSub.onclick="";
		objSub.innerHTML = "Subscription Received - Thank You!";
	}else
		alert(strArgs);
}

function submit_screening(){
	if(screenValid.validate()){
		strFunc = 'after_screening';			
		var poststr = "action=add&" + get_arg_list('frmScreening');
		make_req(strAjaxURL + 'screening.php',strFunc,poststr,'POST');
		//show_update('tableOutput');									
	}
	return false;
}
function after_screening(strArgs){
	if(strArgs == "SUCCESS"){
		$('frmScreening').style.display="none";
		$('divScreenSuccess').style.display="";
	}else
		alert(strArgs);
}


function sendemail_cancel(){
	destroyModal();	
}



function update_rand(strCurrId){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var strFunc = 'after_update_rand';
		var poststr;
		
		poststr = "CurrId=" + escape($('hidCurrRandPosts').value);
		//poststr = "CurrId=" + strCurrId;
		make_req(strAjaxURL + 'random.php',strFunc,poststr,'POST');		
	}
}

function after_update_rand(strArgs){		
	$('divRandCont_front').innerHTML = $('divRandCont').innerHTML;
	//$('divRandCont_front').className = $('divRandCont').className;
	//$('divRandCont_front').style = $('divRandCont').style;
	//if(Prototype.Browser.IE)
		$('divRandCont_front').clonePosition($('divRandCont'));
	//else
		//$('divRandCont_front').clonePosition($('divRandCont'), {offsetTop : -10});
	
	$('divRandCont_front').style.display = "";
	$('divRandCont').style.display = "none";
	$('divRandCont').innerHTML = strArgs;	
	$('divRandCont_front').fade({duration:0.75});
	$('divRandCont').appear({duration:1.2});
}

function submit_form(){
	if(Valid.validate()){
		strFunc = 'after_save';			
		var poststr = "action=save_petition&" + get_arg_list('frmPetition');
		make_req(strAjaxURL + 'save_petition.php',strFunc,poststr,'POST');
		//show_update('tableOutput');									
	}
	return false;
}
function after_save(strArgs){
	if(strArgs == "SUCCESS"){
		$('divSuccess').absolutize();
		$('divSuccess').clonePosition($('divSubmit')) ;
		$('divSuccess').appear();
		$('divSubmit').fade();
	}else
		alert(strArgs);
}
//Wipe field variables on load (for firefox)
 /*document.getElementById('name').value ="";
 document.getElementById('city').value ="";
 document.getElementById('email').value ="";
 document.getElementById('province').value ="";
 document.getElementById('message_body').value ="";*/
 
var numPhotos = 0;
var curPhoto = 1;
var objSlideShow;

function do_photo_next(){	
	var cImage = $('spnCurPhoto');		
	var cControl = $('imgControl');
	if(objSlideShow.active){
		objSlideShow.active = false;
		clearTimeout(objSlideShow.objTimeout);
		cControl.src = "img/pause.gif";
	}	
	objSlideShow.next();
	/*
	var objTitle = $('h4Image');
	var objBody = $('pPhoto');
	var imgImage = $('imgMain');
	if((curPhoto + 1) <= numPhotos){
		curPhoto++; 
		cImage.innerHTML = curPhoto;
		imgImage.src = 'img/' + arrPhoto[curPhoto]['filename'];
		imgImage.alt = arrPhoto[curPhoto]['credit'];
		objTitle.innerHTML = arrPhoto[curPhoto]['title'];
		objBody.innerHTML =  arrPhoto[curPhoto]['blurb'];
	}
	*/
}

function toggle_slideshow(){
	var cControl = $('imgControl');	
	if(objSlideShow.active){
		objSlideShow.active = false;
		clearTimeout(objSlideShow.objTimeout);
		cControl.src = "img/pause.gif";
	} else {
		objSlideShow.active = true;
		cControl.src = "img/play.gif";
		if((objSlideShow.current + 1 ) == objSlideShow.slides.length){
			objSlideShow.restart();
		} else {
			objSlideShow.next();
		}
	}
}

function do_photo_prev(){	
	var cControl = $('imgControl');	
	var cImage = $('spnCurPhoto');	
	if(objSlideShow.active){
		objSlideShow.active = false;
		clearTimeout(objSlideShow.objTimeout);
		cControl.src = "img/pause.gif";
	}	
	objSlideShow.prev();
	/*
	var imgImage = $('imgMain');
	var objTitle = $('h4Image');
	var objBody = $('pPhoto');
	if((curPhoto - 1) > 0){
		curPhoto--; 
		cImage.innerHTML = curPhoto;
		imgImage.src = 'img/' + arrPhoto[curPhoto]['filename'];
		imgImage.alt =  arrPhoto[curPhoto]['credit'];
		objTitle.innerHTML = arrPhoto[curPhoto]['title'];
		objBody.innerHTML =  arrPhoto[curPhoto]['blurb'];
	}
	*/
}


function Slideshow(slideshow, timeout, started) {
 	this.slides = [];
	this.slideBlurbs = [];
	
	var nl = $(slideshow).getElementsByTagName('div');
	for (var i = 0; i < nl.length; i++) {
		if (Element.hasClassName(nl[i], 'slide')) {
			this.slides.push(nl[i]);
		}
	}
	
	var n2 = $(slideshow + 'Blurb').getElementsByTagName('div');
	for (var i = 0; i < n2.length; i++) {
		if (Element.hasClassName(n2[i], 'slide_blurb')) {
			this.slideBlurbs.push(n2[i]);
		}
	}	
	
	this.timeout = timeout;
	this.current = 0;

	for (var i = 0; i < this.slides.length; i++) {
		this.slides[i].style.zIndex = this.slides.length - i;
		this.slideBlurbs[i].style.zIndex = this.slideBlurbs.length - i;
	}

	Element.show(slideshow);
	if(started){
		this.active=true;
		this.objTimeout = setTimeout((function(){this.next();}).bind(this), this.timeout + 850);
	} else{
		this.active=false;
	}
}

Slideshow.prototype = {	
	next: function() {
		var cImage = $('spnCurPhoto');
		//alert(this.current + ' ==  ' + this.slides.length);
		if((this.current + 1) !=  this.slides.length){
			for (var i = 0; i < this.slides.length; i++) {
				var slide = this.slides[(this.current + i) % this.slides.length];
				var slideBlurb = this.slideBlurbs[(this.current + i) % this.slideBlurbs.length];
				slideBlurb.style.zIndex = this.slideBlurbs.length - i;	
				slide.style.zIndex = this.slides.length - i;	
			}
	
			Effect.Fade(this.slides[this.current], {
				afterFinish: function(effect) {
					effect.element.style.zIndex = 0;
					Element.show(effect.element);
					Element.setOpacity(effect.element, 1);
				}
			});
			Effect.Fade(this.slideBlurbs[this.current], {
				afterFinish: function(effect) {
					effect.element.style.zIndex = 0;
					effect.element.style.display = "none";
					Element.show(effect.element);
					Element.setOpacity(effect.element, 1);
				}
			});			
			this.current = (this.current + 1) % this.slides.length;
			cImage.innerHTML = (this.current + 1);	
			if(this.active){
				this.objTimeout = setTimeout((function(){this.next();}).bind(this), this.timeout + 850);
			}
		} else {
			//End of show
			var cControl = $('imgControl');	
			if(this.active){
				this.active = false;
				clearTimeout(this.objTimeout);
				cControl.src = "img/pause.gif";
			}			
		}
	},
	prev: function() {
		var cImage = $('spnCurPhoto');
		if(this.current != 0){
			for (var i = 0; i < this.slides.length; i++) {
				var intVal = (this.current - i) % this.slides.length;
				if(intVal < 0)
					intVal = this.slides.length + intVal;
				var slide = this.slides[intVal];
				var slideBlurb = this.slideBlurbs[intVal];
				//alert((this.current - i) + ' % ' + this.slides.length + ' == ' + intVal)
				
				slideBlurb.style.zIndex = this.slideBlurbs.length - i;	
				slide.style.zIndex = this.slides.length - i;	
			}
	
			Effect.Fade(this.slides[this.current], {
				afterFinish: function(effect) {
					effect.element.style.zIndex = 0;
					Element.show(effect.element);
					Element.setOpacity(effect.element, 1);
				}
			});
			Effect.Fade(this.slideBlurbs[this.current], {
				afterFinish: function(effect) {
					effect.element.style.zIndex = 0;
					effect.element.style.display = "none";
					Element.show(effect.element);
					Element.setOpacity(effect.element, 1);
				}
			});		
			this.current = (this.current - 1) % this.slides.length;
			if(this.current < 0)
				this.current = this.slides.length + this.current;
			cImage.innerHTML = (this.current + 1);
			if(this.active){
				this.objTimeout = setTimeout((function(){this.next();}).bind(this), this.timeout + 850);
			}
		}
	},
	restart: function() {
		var cImage = $('spnCurPhoto');		
		//alert(this.current + ' ==  ' + this.slides.length);
		this.slides[0].zIndex = this.slides[this.current] -1;
		Effect.Fade(this.slides[this.current], {
				afterFinish: function(effect) {
					effect.element.style.zIndex = 0;
					effect.element.style.display = "none";
					Element.show(effect.element);
					Element.setOpacity(effect.element, 1);
				}
			});
		Effect.Fade(this.slideBlurbs[this.current], {
				afterFinish: function(effect) {
					effect.element.style.zIndex = 0;
					effect.element.style.display = "none";
					Element.show(effect.element);
					Element.setOpacity(effect.element, 1);
				}
			});
		this.slides[1].zIndex = this.slides[0] - 1;
		/*for (var i = 1; i < this.slides.length; i++) {
			var slide = this.slides[(1 + i) % this.slides.length];
			var slideBlurb = this.slideBlurbs[(this.current + i) % this.slideBlurbs.length];
			slideBlurb.style.zIndex = this.slideBlurbs.length - i;	
			slide.style.zIndex = this.slides.length - i;	
		}*/
		this.current = 0;
		cImage.innerHTML = (this.current + 1);		
		if(this.active){
			this.objTimeout = setTimeout((function(){this.next();}).bind(this), this.timeout + 850);
		}
	}
}
function do_toggle_section(strTarg){
	var divCont = $('div'+ strTarg.toString());
	var objImg = $('img'+ strTarg.toString());
	if(!divCont.readAttribute('firing')){
		if(divCont.style.display == "none"){
			divCont.blindDown({ duration: 0.3 });	
			objImg.src="img/contractSec.gif";
			objImg.title="Hide Section";			
		} else if(divCont.style.display == ""){
			divCont.blindUp({ duration: 0.3 });
			objImg.src="img/expandSec.gif";
			objImg.title="Show Section";	
		}
		divCont.writeAttribute('firing', true);
		setTimeout("$('" + divCont.id + "').writeAttribute('firing', false);",300);
	}
}
function do_video_preview(){
	var s1 = new SWFObject("includes/mediaplayer.swf","POSPlayer","640","480","8");
						s1.addParam("allowfullscreen","true");
						s1.addVariable("width","640");
						s1.addVariable("height","480");
						s1.addVariable("id","POSPlayer");
						s1.addVariable("file","http://www.amnesty.ca/lubicon/videos/lubicon_preview_v5.flv");
						//s1.addVariable("image","afraid.jpg");
						s1.addVariable("showstop","true");
						s1.addVariable("autostart","true");
						s1.addVariable("bufferlength","25");						
						s1.addParam('wmode', 'opaque','true');
						s1.addParam("id","POSPlayer");
						s1.addVariable("id","POSPlayer");
						s1.write("divMainDisp");
	///var player = $('mediaplayer');
	//player.addModelListener("STATE","POSlistener");
}
function do_video_full(){
	var s1 = new SWFObject("includes/mediaplayer.swf","POSPlayer","640","480","8");
						s1.addParam("allowfullscreen","true");
						s1.addVariable("width","640");
						s1.addVariable("id","POSPlayer");
						s1.addVariable("height","480");
						s1.addVariable("file","http://www.amnesty.ca/lubicon/videos/lubicon_25min_640.flv");
						//s1.addVariable("image","afraid.jpg");
						s1.addVariable("showstop","true");
						s1.addVariable("autostart","true");
						s1.addVariable("bufferlength","25");
						s1.addParam('wmode', 'opaque','true');
						s1.addParam("id","POSPlayer");
						s1.addVariable("id","POSPlayer");
						s1.write("divMainDisp");	
	//var player = $('mediaplayer');
	//
}

var player = null;
function playerReady(obj) {
	alert('the videoplayer has been instantiated');
	player = $(obj['id']);
	player.addModelListener("STATE","POSlistener");
};


var blnPausedPlayer = false;
var POSstate = false;

function POSlistener(obj){
	 POSstate = obj.newstate;
}


function toggle_play(){
	if(player == null){
		player = $('POSPlayer');
		alert(player.id);
		//player.addModelListener("STATE","POSlistener");
	}	
	alert(POSstate);
	if(POSstate == "PLAYING"){
		blnPausedPlayer = true;
		player.sendEvent('PLAY', 'false');	
	} else if(blnPausedPlayer){
		player.sendEvent('PLAY', 'true');
		blnPausedPlayer = false;
	}
	/*
	if(player == null){
		player = $('POSPlayer');
		alert(player.id);
		//player.addModelListener("STATE","POSlistener");
	}	
	alert(player.IsPlaying());
	if(!blnPausedPlayer){
		blnPausedPlayer = true;
		player.StopPlay();	
	} else if(blnPausedPlayer){
		player.Play();
		blnPausedPlayer = false;
	}*/
}

function screening_show_past(){
	if($('divPastScreenings').style.display == "none"){
		Effect.BlindDown($('divPastScreenings'), {duration:0.25});
		Effect.BlindUp($('divFutureScreenings'), {duration:0.25});
		$('aShowPast').style.fontWeight = "bold";
		$('aShowFuture').style.fontWeight = "normal";
	}
}

function screening_show_future(){
	if($('divFutureScreenings').style.display == "none"){
		Effect.BlindDown($('divFutureScreenings'), {duration:0.25});
		Effect.BlindUp($('divPastScreenings'), {duration:0.25});
		$('aShowFuture').style.fontWeight = "bold";
		$('aShowPast').style.fontWeight = "normal";
	}
}

function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;} 
