/* Carousel */
var carousel_index = 0;

function carousel_previous()
{
	if (carousel_index == 0)
		carousel_index = carousel_images.length;
	
	carousel_index--;

	document.getElementById("carousel-image").src = carousel_images[carousel_index];
};

function carousel_next()
{
	carousel_index++;
	
	if (carousel_index >= carousel_images.length)
		carousel_index = 0;
	
	document.getElementById("carousel-image").src = carousel_images[carousel_index];
};

function search_engine_switch()
{
	// get search page slug
	var engine = document.getElementById(
			  "search-engine-"
			+ document.getElementById("search-engine").selectedIndex
		).value;
	
	// get action & transform to new
	var action = document.getElementById("search-form").action;
	// in case of missing trailing slash, we get rid of last character
	action = action.substr(0, action.length - 1);
	// remove everything after last slash
	action = action.substr(0, action.lastIndexOf("/") + 1);
	// add new engine
	action = action + engine + "/";
	
	// apply
	document.getElementById("search-form").action = action;
};

function golfit_loaded()
{
	jQuery("#search-form-text").focus(function(e)
			{
			if (jQuery("#search-form-text").attr('value') ==
				jQuery("#search-form-text").attr('defaultValue'))
				jQuery("#search-form-text").attr('value', '');
			});
	jQuery("#search-form-text").blur(function(e)
			{
				if (jQuery("#search-form-text").attr('value') == '')
					jQuery("#search-form-text").attr('value',
							jQuery("#search-form-text").attr('defaultValue'));
			});
	
	if (jQuery("#ad-120x600-outside") &&
		(window.innerWidth || document.body.offsetWidth) >= 1280)
	{
		jQuery("#ad-120x600-outside").css('display', 'block');
	}
	
	jQuery('#friend-selector input').change(function(e)
			{
				if (e.currentTarget.checked)
					jQuery(e.currentTarget.parentNode).css('background-color', '#FFF');
				else
					jQuery(e.currentTarget.parentNode).css('background-color', '');
			}
		);
	
	var el = jQuery('#friend-selector input');
	for (var i = 0; i < el.length; i++)
	{
		if (el[i].checked)
			jQuery(el[i].parentNode).css('background-color', '#FFF');
		else
			jQuery(el[i].parentNode).css('background-color', '');
	}
}
window.onload = golfit_loaded;

//document.write('<script type="text/javascript" defer>golfit_loaded();</script>');

function album_rename(url)
{
	var title = window.prompt('Bitte gib den neuen Titel für dieses Album ein.');
	if (title.replace(/\s/gi, '') == '')
		return;
	
	top.location.href = url + '/' + title;
}


function album_delete(url)
{
	var act = window.confirm('Willst du dieses Foto-Album wirklich mit allen Fotos löschen?');
	
	if (act)
		top.location.href = url;
}

function show_photo_form()
{
	jQuery('#photo_edit_form').css('display', 'block');
	jQuery('#photo_description').css('display', 'none');
}