var photo_current = 0;

function browse_to (url)
{
	window.location.assign (url);
}

function event_toggle (id)
{
	var e = document.getElementById ('event_' + id);
	e.style.display = (e.style.display == 'block') ? 'none' : 'block';
}

function other_captcha ()
{
	var e = document.getElementById ('captcha_img');
	var s = e.src.replace (/\?ts=\d+/, '');
	e.src = s + '?ts=' + new Date ().getTime ();
}

function photo_activate (idx)
{
	if (idx == photo_current) return;
	
	var e = document.getElementById ('photo_' + idx);
	if (e)
	{
		var o = document.getElementById ('photo_' + photo_current);
		if (o)
		{
			var l = document.getElementById ('photo_' + (photo_current - 1));
			if (!l) l = document.getElementById ('photo_' + (photo_current + 2));
			if (l) l.style.display = 'none';
			o.style.display = 'none';
			var r = document.getElementById ('photo_' + (photo_current + 1));
			if (!r) r = document.getElementById ('photo_' + (photo_current - 2));
			if (r) r.style.display = 'none';
		}
	
		var l = document.getElementById ('photo_' + (idx - 1));
		if (!l) l = document.getElementById ('photo_' + (idx + 2));
		if (l)
		{
			l.className = 'thumb inactive';
			l.style.display = '';
		}
		e.className = 'thumb active';
		e.style.display = '';
		var r = document.getElementById ('photo_' + (idx + 1));
		if (!r) r = document.getElementById ('photo_' + (idx - 2));
		if (r)
		{
			r.className = 'thumb inactive';
			r.style.display = '';
		}
		photo_current = idx;
		
		document.getElementById ('input_photo').value = e.src.match (/(\w+)_\w+?_s\.jpg/) [1];
		document.getElementById ('photo_large').src = e.src.replace ('_s.jpg', '_m.jpg');
	}
}

function photo_select (evt)
{
	if (!evt) var evt = window.event;
	if (!evt) return;
	var e = evt.target ? evt.target : evt.srcElement;
	switch (e.id)
	{
	case 'photo_left' :
		photo_activate (photo_current - 1);
		break;
	case 'photo_right' :
		photo_activate (photo_current + 1);
		break;
	default :
		photo_activate (parseInt (e.id.substr (6)));
	}
}

function rating_preview (n)
{
	var e = document.getElementById ('rating');
	e.className = 'spacer rating' + n;
}

function rating_vote (n)
{
	var url = window.location.href;
	url = url.replace (/([\?&])rating=\d*/, '$1');
	url = url.replace ('?&', '?');
	url = url.replace (/&$/, '');
	url = url + ((url.indexOf ('?') >= 0) ? '&' : '?') + 'rating=' + n;
	window.location = url;
}

function tabswitch (id, idx)
{
	$ ('#' + id + ' .tabs li').removeClass ('current').eq (idx).addClass ('current');
	$ ('#' + id + ' .tab').addClass ('inactive').eq (idx).removeClass ('inactive');
}
