/**
 * uses jQuery 1.5.1
 */

/*
 * Mainmenu
 */

var menu;

function mainmenu_init(mainmenu_id)
{
	menu = $(mainmenu_id);

	// init Menu
	menu.find("li.level0").hover(
		mainmenuL0HoverIn,
		mainmenuL0HoverOut
	);
	menu.find("ul.level1").hide();
}
function mainmenuL0HoverIn(event)
{
	$(event.currentTarget).find('ul.level1').first().slideDown(100);
}
function mainmenuL0HoverOut(event)
{
	$(event.currentTarget).find('ul.level1').first().stop(true, true);
	$(event.currentTarget).find('ul.level1').first().slideUp(100);
}

/*
 * Spots
 */

var spotdata = {};

function spots_init()
{
	var dom_spots_tumbnails = $('div.spot a.thumbnail');
	var dom_spots_ansehen = $('div.spot a.ansehen');
	dom_spots_tumbnails.click(
		spot_ansehen
	);
	dom_spots_ansehen.click(
		spot_ansehen
	);
}
function spot_ansehen(event)
{
	var fplayer_version = swfobject.getFlashPlayerVersion();

	var dom_spot = $(event.currentTarget).parents('div.spot');
	spotdata = pagedata['spots'][dom_spot.attr('id')];

	if(fplayer_version.major >= 9) {
		// Flash Player OK
		event.preventDefault();
		lightbox_open(640,580, function(){
			swfobject.embedSWF("/media/web/flash/videoplayer.swf", "lightboxcontent", "640", "580", "9,0,115,0", false, {fvVideourl:spotdata['url:flv']}, {scale:"noscale", wmode:"transparent", salign:"tl"});
		});
	} else if (fplayer_version.major > 0) {
		// Flash Player veraltet
		alert('Um das Video anzusehen, benötigen Sie einen aktuellen Flash-Player!');
	} else {
		// kein Flash Player
	}
}

/*
 * Lightbox
 */

var lightbox_params = {};

/**
 *
 * @param w Breite
 * @param h Höhe
 * @param callback Wird aufgerufen, wenn die lightbox sichtbar ist
 */
function lightbox_open(w, h, callback)
{
	lightbox_params.body = $('body');
	lightbox_params.w = w;
	lightbox_params.h = h;
	lightbox_params.callback = callback;

	lightbox_params.body.append('<div id="lightboxbackground"></div>');
	lightbox_params.background = $('#lightboxbackground');
	lightbox_params.background.height(lightbox_params.body.height());
	lightbox_params.background.css('z-index', 99);
	lightbox_params.background.fadeTo('fast', 0.9, lightbox_showcontent);
	lightbox_params.background.click(
		lightbox_close
	);
}
function lightbox_showcontent()
{
	lightbox_params.body.append('<div id="lightbox"><a id="lightboxclose" href="">schließen<img src="/media/web/images/icon-lightbox-close.gif" id="lightboxclose-x" /></a><div id="lightboxcontent"></div></div>');
	lightbox_params.box = $('#lightbox');
	lightbox_params.box.css('z-index', 100);
	lightbox_params.box.width(lightbox_params.w);
	lightbox_params.box.height(lightbox_params.h);
	lightbox_params.close = $('#lightboxclose');
	lightbox_params.close.click(
		lightbox_close
	);
	lightbox_repos();
	lightbox_params.box.fadeTo('fast', 1, lightbox_content_complete);
}
function lightbox_content_complete()
{
	$(window).resize(lightbox_windowresize);
//	$(window).scroll(lightbox_windowscroll);
	if(lightbox_params.callback) {
		lightbox_params.callback();
	}
}
function lightbox_windowresize()
{
	lightbox_repos();
}
function lightbox_windowscroll()
{
	lightbox_repos();
}
function lightbox_repos()
{
	lightbox_params.box.offset({left:lightbox_params.body.width() / 2 - lightbox_params.box.width() / 2, top:$(window).scrollTop() + 100});
}
function lightbox_close(event)
{
	event.preventDefault();
	$(window).unbind('resize', lightbox_windowresize);
//	$(window).unbind('scroll', lightbox_windowscroll);
	lightbox_params.background.remove();
	lightbox_params.box.remove();
}

/*
 * Keyvisual
 */
function keyvisual_init(dauer)
{
	window.setInterval('keyvisual_step()', dauer);
}
function keyvisual_step()
{
}

/*
 * Tools
 */

function _log(message)
{
	if(typeof console !== 'undefined') {
		console.log((new Date()).toTimeString() + " " + message);
	}
}

