function event_shareurl(url)
{
	jQuery.facebox("<p>To share this event with others, just give them the URL below:</p>"
	+"<p><input type=\"text\" value=\"http://"+window.location.host+"/event/"+url+"/\" style=\"width:600px;\" onclick=\"$(this).select();\"/></p>");

}
function event_index_shareurl(url)
{
	jQuery.facebox("<p>To share this event with others, just give them the URL below:</p>"
	+"<p><input type=\"text\" value=\"http://"+window.location.host+"/event/"+url+"/\" style=\"width:600px;\" onclick=\"$(this).select();\"/></p>");
}

function loadEventIndexGrid(type,part2,page)
{
	new Ajax.Request("/events/ajax_index_list.php?type="+encodeURIComponent(type)+"&extra="+encodeURIComponent(part2)+"&p="+page,{
		method:'get',
		onSuccess:function(t){
			var json = t.responseJSON;
			
			var eventtpl = new Template('<div class="album">'
			+'<a href="/events/view.php?eid=#{eventid}"><img src="#{photourl}" width="#{width}" height="#{height}" border="0" /></a> '
			+'<span class="name"><a href="/events/view.php?eid=#{eventid}">#{name}</a></span></div>');

			
			if(json.events.length>0)
			{
				var pager = showJsonPager(json.pager,"loadEventIndexGrid('"+type+"','"+part2+"','#{page}');return false;");
				var content = pager;
				content += '<div class="albumrow clearfix">';
				for(i=0;i<json.events.length;i++)
				{
					content += eventtpl.evaluate(json.events[i]);
					if((i+1)%4==0)
					{
						content += '</div><div class="albumrow clearfix">';
					}
				}
				content+=pager;
				content+="</div>";
				$('eventsarea').update(content);
			}
			else
			{
				$('eventsarea').update('<p>Sorry, but no events were found.</p>');
			}
		}
	});
}

var event_flyers = new Array();
var event_flyer_current = 0;

function event_addFlyer(url,width,height,burl,bw,bh)
{
	var img = new Image(width,height);
	img.src = url;
	event_flyers.push({
		'url': url,
		'width':width,
		'height':height,
		'image':img,
		'burl':burl,
		'bw':bw,
		'bh':bh
	});
}

function event_nextFlyer(divid)
{
	event_flyer_current++;
	event_drawFlyer(divid);
}
function event_prevFlyer(divid)
{
	event_flyer_current--;
	event_drawFlyer(divid);
}
function event_flyer_zoom()
{
	var m=new Control.Modal(false,{
		image:true,
		opacity:1,
		constrainToViewport:false,
		contents:function()
		{
			var flyer = event_flyers[event_flyer_current];
			return '<img onclick="Control.Modal.close();" src="'+flyer.burl+'" width="'+flyer.bw+'" height="'+flyer.bh+'" alt="" title="Click to close"/>';
		}
	});
	m.open();
}

function event_drawFlyer(divid)
{
	var content = "";
	var flyer = event_flyers[event_flyer_current];
	content += '<a href="#flyerzoom" onclick="event_flyer_zoom();return false;">';
	content += '<img src="'+flyer.url+'" width="'+flyer.width+'" height="'+flyer.height+'" border="0" />';
	content += '</a>';

	content += '<div class="pagerlinks clearfix">';
	if(event_flyer_current!=0)
	{
		content += '<a href="#prevflyer" onclick="event_prevFlyer(\''+divid+'\');return false;">Prev</a>';
	}
	else
	{
		content += '<a href="#prevflyer" onclick="return false;" class="disabled">Prev</a>';
	}
	if((event_flyer_current+1)<event_flyers.size())
	{
		content += '<a href="#nextflyer" onclick="event_nextFlyer(\''+divid+'\');return false;">Next</a>';
	}
	else
	{
		content += '<a href="#nextflyer" onclick="return false;" class="disabled">Next</a>';
	}
	content += '</div>';
	$(divid).update(content);
}

var event_managealbumlist = new Array();
function event_addremovealbum(albumid)
{
	if( $('albcb'+albumid).checked)
	{
		$('albdiv'+albumid).removeClassName("checked");
		$('albcb'+albumid).checked=false;
	}
	else
	{
		$('albdiv'+albumid).addClassName("checked");
		$('albcb'+albumid).checked=true;
	}
}

