// kino

function thumbnail_jump_to_what_we_need(slidename) {

	var inner				= $('div.container_thumbnail_inner');
	var thumb				= inner.find('div.slide_thumbnail');

	var best_thumb	= -1;
	var nr;

	for( var i=thumb.length-1 ; i>=0 ; i-- ) {
		if( $(thumb[i]).attr('_slide') == slidename ) {
			best_thumb=i;
		}
	}

	thumbnail_jump_to(best_thumb);
}

function slide_id_to_pos(slide_id) {

	var inner				= $('div.container_thumbnail_inner');
	var thumb				= inner.find('div.slide_thumbnail');

	var found	= -1;
	for( var i=0 ; i<thumb.length ; i++ ) {
		if( $(thumb[i]).attr('_slidename') == slide_id) {
			found	= i;
		}
	}

	return found;
}

function slide_jump_to_fade( pos ) {
	var container	= $('div.container');
	var slides		= container.find('div.slide');
	var slide_count	= slides.length;

	if( pos.substr( 0 ,1 )=="*" ) {
		pos=pos.substr(1);
		var found	= 0;
		for( var i=0 ; i<slide_count ; i++ ) {
			if( $(slides[i]).attr('_slidename') == pos ) {
				found	= i;
			}
		}
		pos	= found;
	}

	var current_slide	= parseInt(container.attr( 'current_slide' ));

	var next_slide	= 0;
	if( pos=='next' )	{
		next_slide				= current_slide + 1;
	} else if( pos=='prev' ) {
		next_slide	= current_slide - 1;
	} else {
		next_slide	= parseInt(pos);
	}

	if( next_slide > slide_count-1 )		next_slide	= 0;
	if( next_slide < 0 )					next_slide	= slide_count-1;

	// Es soll mglw. einblenden, was schon eingeblendet ist - das waere naturlich falsch
	if( current_slide!=next_slide ) {
		
		var current_slide_div	= $(container.find('div.slide')[current_slide]);
		var next_slide_div		= $(container.find('div.slide')[next_slide]);

		$('div.slide').hide();

		current_slide_div.css('z-Index' , 3);
		current_slide_div.css('opacity' , 1.0);
		current_slide_div.show();

		next_slide_div.css('z-Index' , 2);
		next_slide_div.css('opacity' , 1.0);
		next_slide_div.show();

		// Userdefined event: Slide laeuft jetzt rein...	
		current_slide_div.trigger("slide_leaving_start", { o:current_slide_div });

		// rausfahren
		current_slide_div.animate( {
			'opacity' : 0
		} ,200 , 'linear' , function() {
			$(this).hide();
			// Userdefined event: Slide ist jetzt komplett raus.
			$(this).trigger("slide_leaving_done", { o:$(this) });
		} );


		// Dem Slide seinen Index mitteilen, den schreibt er dann spaeter in den container.
		$('div.container').attr( 'current_slide' , next_slide ); // Dem Container den aktuellen Index mitgeben, welcher Slide grad vor liegt.

//console.debug($(slides[next_slide]).attr('_slidename'));
		thumbnail_jump_to_what_we_need($(slides[next_slide]).attr('_fallback_thumb'));

		// Userdefined event: Slide faehrt jetzt raus...
		next_slide_div.trigger("slide_entering_start", { o:next_slide_div });

			
		// Knoepfe wieder scharfschalten
		re_activate_slide_buttons();

		// Userdefined event: Slide ist jetzt raus.
		$(this).trigger("slide_entering_done", { o:$(this) });


	} else {
		// Hier geht es weiter, falls keine Animatioon stattfand (z.B. gleicher Thumbnail 2x geklickt)

		// Knoepfe wieder scharfschalten
		re_activate_slide_buttons();

	}

}


// Bedienelemente reagieren auf 'one', nicht auf 'click', um ueberlappende Events auszuschliessen.
// Daher alle wieder scharfschalten. ("alle" ist einfacher als "finde den richtigen" und kostet kaum Strom)
// Doppelaufrufe muessen aber verhindert werden, deswegen wrden alle ausgeschaltet und alle eingeschaltet
function re_activate_slide_buttons() {
	var container		= $('div.container');
	var slide_count		= container.find('div.slide').length;
	var current_slide	= parseInt(container.attr( 'current_slide' ));

	if( current_slide+1 >= slide_count) {		container.find('div.arrow_next').hide();		} else {		container.find('div.arrow_next').show();		}
	if( current_slide==0 ) {					container.find('div.arrow_prev').hide();		} else {		container.find('div.arrow_prev').show();		}

	$('div.arrow_prev'		).off('click');
	$('div.arrow_next'		).off('click');
	$('div.slide_thumbnail'	).off('click');

	$('div.arrow_prev'		).one('click' , function() { slide_jump_to_fade( 'prev' ); } );
	$('div.arrow_next'		).one('click' , function() { slide_jump_to_fade( 'next' ); } );
	$('div.slide_thumbnail'	).one('click' , function() { slide_jump_to_fade( '*'+$(this).attr('_slide') ); } );
}

// Pfeile wieder "scharfschalten": Alle Events loeschen, alle wieder setzen. Funktioniert, egal wo drauf geklickt wurde, ohne Events zu stapeln
function re_activate_thumbnail_buttons() {
	$('div.thumbnail_arrow_prev').off('click');
	$('div.thumbnail_arrow_next').off('click');

	$('div.thumbnail_arrow_prev').one('click' , function() { thumbnail_jump_to( 'prev' ); } );
	$('div.thumbnail_arrow_next').one('click' , function() { thumbnail_jump_to( 'next' ); } );
}

function thumbnail_hightlight() {
	var inner	= $('div.container_thumbnail_inner');
	var pos		= inner.attr('thumbnail_nr' );
	var active	= $(inner.find('div.slide_thumbnail')[pos]);

	inner.find('div.slide_thumbnail').attr('i_am_selected' , 0 );
	active.attr('i_am_selected' , 1 );

	$('div.container_thumbnail_inner div.slide_thumbnail_text').hide();
	active.find('div.slide_thumbnail_text').show();
}

function thumbnail_mouseenter( me ) {
	if( ! me.attr('i_am_selected' )==0 ) {
		// show this
		me.find('div.slide_thumbnail_text').fadeIn(100);
		
		// gray out selected
	}
	me.parent().find('div.slide_thumbnail_text p').first().addClass('slide_thumbnail_text_gray');
	me.find('div.slide_thumbnail_text p').first().removeClass('slide_thumbnail_text_gray');
}
function thumbnail_mouseleave( me ) {
	if( me.attr('i_am_selected' )==0 ) {
		me.find('div.slide_thumbnail_text').fadeOut(100);
	}
	me.parent().find('div.slide_thumbnail_text p').first().removeClass('slide_thumbnail_text_gray');
}


function thumbnail_jump_to( pos ) {
	
	var inner				= $('div.container_thumbnail_inner');
	var outer				= $('div.container_thumbnail_outer');
	var count				= inner.find('div.slide_thumbnail').length;
	var thumb_width			= $(inner.find('div.slide_thumbnail')[0]).width();
	var current_position	= parseInt(inner.css('left'));

	var maxi_left			= outer.width() - parseInt(inner.css('width'));

	if( ! inner.attr('thumbnail_nr' ) )				inner.attr('thumbnail_nr' , 0 );

	// Die Thumbnails passen nicht genau in den Scroller, weil auch das letzte Thumbnail (wie alle) einen weissen Rand rechts hat, den es aber nicht braucht. 20 Pixel zuviel.
	// deswegen darf man eigentlich zu weit scrollen. Daher korrigieren wir um diesen Betrag, und um auf Nummer Sicher zu gehen, legen wir noch was drauf.
	var korrektur	= 20; 
	
//	console.debug(	maxi_left	);

	var target_position	= "none";
	
	if( pos=="next"	&&	maxi_left  + korrektur + 5 < parseInt(inner.css('left'))	) {
//		inner.attr('thumbnail_nr' , parseInt(inner.attr('thumbnail_nr'  )) + 1 );
		target_position	= parseInt(inner.css('left')) -thumb_width;
	} else if( pos=="prev" && current_position < 0 ) {
//		inner.attr('thumbnail_nr' , parseInt(inner.attr('thumbnail_nr'  )) - 1 );
		target_position	= parseInt(inner.css('left')) +thumb_width;
	} else if ( Number(pos) || pos=="0" ) {
		inner.attr('thumbnail_nr' , pos );
		target_position	= -(pos-2) * thumb_width;	// 2, weil der thumb moeglichst mittig stehen soll.
		if(target_position<maxi_left+korrektur)	target_position=maxi_left+korrektur;
		if(target_position>0) target_position=0;
	} else {
		// Keine Animation  wurde ausgeloest (z.B. bei 0px geht es nicht weiter nach Links)
		target_position	= current_position;
	}

	
	if( target_position != "none" ) {
		if( target_position>=0 ) {
			$('div.thumbnail_arrow_prev').hide();
		} else {
			$('div.thumbnail_arrow_prev').show();
		}
		if( target_position <= maxi_left+korrektur ) {
			$('div.thumbnail_arrow_next').hide();
		} else {
			$('div.thumbnail_arrow_next').show();
		}

		inner.animate( 
			{
				'left' : target_position +'px'
			} , 400 , function(){	
				re_activate_thumbnail_buttons();
				thumbnail_hightlight();	
			}
		);
	}
}

function infobox_toggle( o ) {

	var infobox_small	= o.parents('div.slide_infobox_container').find('div.slide_infobox_small').first();
	var infobox_big		= o.parents('div.slide_infobox_container').find('div.slide_infobox_big').first();


	if( infobox_big.height() < 1 ) {
		infobox_big.show();
		infobox_small.fadeOut(100);
		infobox_big.animate({
			//'top':		(	infobox_big.attr('realtop') - infobox_big.attr('realheight')	)+"px" ,
			'height':	infobox_big.attr('realheight')+"px"
		}, 200, function() {
		});
	} else {
		infobox_small.fadeIn(100);
		infobox_big.animate({
			//'top':		infobox_big.attr('realtop')+"px" ,
			'height':	"0px"
		}, 200, function() {
			$(this).hide();
		});
	}
}

function infobox_toggle_all() {
	// small, big, egal. Die Funktion sucht sich die Boxen selber nochmnal genau aus dem slide raus.
	$('div.slide_infobox_small').each( function() {
		infobox_toggle( $(this) );
	});
}

function init_slideshow() {
	$(window).ready( function () {

		// Jedem Slide einen Index verpassen.
		$('div.slide').each( function (index) {
			$(this).attr("slide_index" , index);
		});

		var slide	= $('div.slide');
		var fallback_thumb ="";
		for( var i =0 ; i<slide.length ; i++ ) {
			if( $(slide[i]).attr('has_thumbnail')==1 ) {
				fallback_thumb	= $(slide[i]).attr('_slidename');
			}
			$(slide[i]).attr('_fallback_thumb' , fallback_thumb)
//			console.debug( $(slide[i]).attr('slide_index') );
		}
		
		// den Thumnail-sroll-DIV die richtige Breite verpassen, weil er (versteckt) breiter ist als der Content.
		var tmp	= $('div.container_thumbnail_inner').find('div.slide_thumbnail');
		$('div.container_thumbnail_inner').css('width' , ($(tmp[0]).width()) * (tmp.length)	);


		// Infoboxen initialisieren, Masse auslesen und dann verstecken
		$('div.slide_infobox_container').each( function () {

			$(this).find('span.infobox_toggle').on( 'click' , function () {	
				infobox_toggle_all(); 
			});

			$(this).find('div.slide_infobox_big').each( function () {
				$(this).css( 'height' , $(this).css( 'height') );	// Hoehe noch mal explizit setzen, jQuery ruckelt sonst um die Distanz eines margins oder Paddings.
				$(this).attr('realheight'	, $(this).height() );
				//$(this).attr('realtop'		, parseInt( $(this).css('top') ) );
				$(this).css('height' , "0px");
				$(this).css( 'visibility' , 'visible');
				$(this).hide();
			});

			$(this).find('div.slide_infobox_small').each( function () {
				$(this).css( 'visibility' , 'visible');
			});

		});


		// Beispiel fuer nutzerdefinierte Events
		/*
		var slide1	= $($('div.container').find('div.slide')[1]);
		
		slide1.on(			"slide_leaving_start",	function(e, value){	console.debug('1: ich geh dann mal' , value);	}		);
		slide1.on(			"slide_leaving_done",	function(e, value){	console.debug('1: bin raus' , value);			}		);
		slide1.on(			"slide_entering_start",	function(e, value){	console.debug('1: komme rein' , value);			}		);
		slide1.on(			"slide_entering_done",	function(e, value){	console.debug('1: bin drin' , value);			}		);

		$('div.slide').on(			"slide_leaving_start",	function(e, value){	console.debug(value.o.attr('slide_index') ,'ich geh dann mal' );	}		);
		$('div.slide').on(			"slide_leaving_done",	function(e, value){	console.debug(value.o.attr('slide_index') ,'bin raus' );			}		);
		$('div.slide').on(			"slide_entering_start",	function(e, value){	console.debug(value.o.attr('slide_index') ,'komme rein' );			}		);
		$('div.slide').on(			"slide_entering_done",	function(e, value){	console.debug(value.o.attr('slide_index') ,'bin drin' );			}		);

		*/
		
		$('div.slide_dock_container').each( function () {
				//$(this).css('left' , (470 - parseInt($(this).css('width'))/2 -4) + 'px');
				// safari has other width calculation, img.width + border + dockborder
				$(this).css('left' , (470 - parseInt($(this).find('img.slide_dock_img').length * (25+8+8))/2) + 'px');
			}
		);

		// Dock 
		$('div.slide_dock_container img.slide_dock_img').each( function () {
			$(this).mouseenter( function() {
				var position	=	$(this).position();
				$(this).prev().css('display' , 'block');
				$(this).prev().css('left' , parseInt(position.left) - ( parseInt($(this).prev().css('width')) / 2) + 13 +'px');	// 13=thumbnail-width/2 - border;
			}).mouseleave( function() {
				$(this).prev().css('display' , 'none');
			});
		});
	
		// Ersten Slide zeigen und userdefined Events aufrufen

		$('div.container').attr( 'current_slide' , 0 );
		var first_slide	= $($('div.container').find('div.slide')[0]);
		$('div.slide').hide();
		first_slide.show();
		first_slide.trigger("slide_entering_start", { o:first_slide });
		first_slide.trigger("slide_entering_done", { o:first_slide });

		thumbnail_jump_to( 0 );


		$('div.container_thumbnail_inner div.slide_thumbnail').mouseenter( function() { thumbnail_mouseenter($(this)); } );
		$('div.container_thumbnail_inner div.slide_thumbnail').mouseleave( function() { thumbnail_mouseleave($(this)); } );


		re_activate_slide_buttons();
		re_activate_thumbnail_buttons();


		
	});
}

function image_was_loaded_or_misses( slide_div ) {
	slide_div.attr('number_of_images_to_load_herein' , parseInt(slide_div.attr('number_of_images_to_load_herein' ))-1 );
	if(slide_div.attr('number_of_images_to_load_herein')==0 ) {
		slide_div.attr('is_loaded' , 1 );
		slide_div.find('img.loading_animation').remove();
	}
}



// Favorites
function add_2favorites( lang ,url , img , text) {
	var list	= httprequest('index.php?favcmd=add&language=' + lang + "&whereami=*favoriteslist&cut_content=FAVORITES&admin_tempoff=1&url=" + encodeURIComponent(url)+"&img=" + encodeURIComponent(img)+"&text=" + encodeURIComponent(text)+"&"+httprequest_do_not_cache() );
	favorites_init(lang , list);
}

function add_2favorites_switch( lang , favmode) {
	var list	= httprequest('index.php?favcmd=switchmode&favmode='+favmode+'&language=' + lang + "&whereami=*favoriteslist&cut_content=FAVORITES&admin_tempoff=1&"+httprequest_do_not_cache() );
// Kein Redraw. Es kommt ohnehin gleich zwingend der Event "neuer Favorit", und dann wuerde das blinken.	
//	favorites_init(lang , list);
}

function request_favorites( lang ) {
	return httprequest('index.php?favcmd=list&language=' + lang + "&whereami=*favoriteslist&cut_content=FAVORITES&admin_tempoff=1&"+httprequest_do_not_cache());
}

function favorites_init(lang , prepared) {
	var html	= "";
	var div	= $('<div>');

	var dat;
	if( prepared) {
		dat	= prepared;
	} else {
		dat	= request_favorites( lang );
	}
	div.html( dat );
	
	var ul	= div.find('ul');
	ul.each(	function(index) {
		var url		= $(this).find('li.url' ).html();
		var img		= $(this).find('li.img' ).html();
		var text	= $(this).find('li.text').html().split('|');
		html+=	"<div class='favorite_thumbnail'><a href='"+url+"'>"	+
					"<img src='" +
						img +
					"'>" +
					"<p><strong>" + text[0] + "</strong>&nbsp;" + text[1] + "</p>" +
				"<\/a><\/div>";
	});

	$('#notepad'			).css('display'	, 'none');
	$('#notepad_empty'		).css('display'	, 'none');
	$('#fast_access'		).css('display' , 'none');
	
	$('#merkzettel_content').html(	html	);

	if( ul.length ) {
		$('#notepad'			).css('display'	, 'block');
		$('#notepad_empty'		).css('display'	, 'none');
		$('#fast_access'		).css('display' , 'block');
	} else {
		$('#notepad'			).css('display'	, 'none');
		$('#notepad_empty'		).css('display'	, 'block');
		$('#fast_access'		).css('display' , 'none');
	}

}

function favorites_delete_all( lang ) {
	return httprequest('index.php?favcmd=deleteAll&language=' + lang + "&whereami=*favoriteslist&cut_content=FAVORITES&admin_tempoff=1&"+httprequest_do_not_cache());
}



// Automatic Slideshow

function auto_slideshow( container , slideshow_type ) {

	// Wenn der Container "gebaut" wurde, kann man die canvas schon mal mit einbauen. Wenn nicht, werden die IMGs eingesammelt und alles andere geloescht.

	var canvas	= container.find('div.create_slideshow_canvas');

	if( ! canvas.length ) {
		canvas	=$('<div class="create_slideshow_canvas">');
		canvas.append( function() {
			return container.find('img');
		});
		container.contents().remove();
		container.append(canvas);
		
		canvas	= container.find('div.create_slideshow_canvas');

	}


//console.debug(canvas);	
	var height	= canvas.find('img').first().height();
	var width	= canvas.find('img').first().width();
//	console.log( width,height	);

	canvas.css('width'  , width  + 'px' );
	canvas.css('height' , height + 'px' );

	container.css('height' , height + 'px' );

	if( ! container.hasClass('slideshow_no_arrows') ) {
		canvas.before($( '<div class="slideshow_arrow_prev"><a href="#"></a></div>' ));
		canvas.after( $( '<div class="slideshow_arrow_next"><a href="#"></a></div>' ));
	}
	var slideshow_options	= {
				fx: 'fade',
				timeout:0 ,
				onPrevNextEvent: auto_slideshow_onPrevNextEvent
	}

	if( container.hasClass('slideshow_loop') ) {
		slideshow_options.speed		= container.attr('_slideshow_speed');
		slideshow_options.timeout	= container.attr('_slideshow_timeout');
	}


	canvas.cycle( slideshow_options );


	container.find('.slideshow_arrow_prev').css('top' , parseInt((height/2)-(61/2)) + 'px');

	container.find('.slideshow_arrow_next').css('left' , (width-20)+'px');
	container.find('.slideshow_arrow_next').css('top' , parseInt((height/2)-(61/2)) + 'px');

	auto_slideshow_init_arrows(container , canvas , 0 );

}

function auto_slideshow_onPrevNextEvent(isNext, zeroBasedSlideIndex, slideElement) {
	var canvas			= $(slideElement).parent();
	var container		= $(slideElement).parent().parent();
//	console.debug( $(slideElement).parent().parent() );
	var this_slide_nr	= zeroBasedSlideIndex;
	auto_slideshow_init_arrows(container , canvas , this_slide_nr );
}

function auto_slideshow_init_arrows(container , canvas , this_slide_nr ) {
	var slide_count		=  canvas.children().length;

	if( this_slide_nr+1 >= slide_count) {		container.find('.slideshow_arrow_next').hide();		} else {		container.find('.slideshow_arrow_next').show();		}
	if( this_slide_nr==0 ) {					container.find('.slideshow_arrow_prev').hide();		} else {		container.find('.slideshow_arrow_prev').show();		}

	container.find('.slideshow_arrow_prev').each(
		function () {
			$(this).unbind('click');
			$(this).bind( 'click' ,
				function () {
					canvas.cycle('prev');
				}
			);
		}
	);
	container.find('.slideshow_arrow_next').each(
		function () {
			$(this).unbind('click');
			$(this).bind( 'click' ,
				function () {
					canvas.cycle('next');
				}
			);
		}
	);

}



// Automatic Movies
function auto_movie_resize_event(player) {
	$(player).parent().find('li.jp-progress').first().css('width' ,	parseInt(player.css('width'))-100+'px'		 );
}

function movie_player_standalone_close() {

	// If something plays already then kill it.
	var remove_player	= $('#movie_player_standalone').find('.jp-jplayer').first();
	if(	remove_player.hasClass('jp-jplayer') ) {
		remove_player.jPlayer("pause");
		remove_player.jPlayer("stop");
		remove_player.jPlayer("destroy");
	}
	$('#movie_player_standalone').animate({'height':'0px'}).animate({'marginBottom':'0px'});
}

function auto_movie(o) {
	// Insert if you need an inspector:  <div id="jplayer_inspector" style="float:left; margin-left:20px;">inspector</div>
	if( typeof o == 'string' )	o	= $('#'+o);

	var image_to_replace;
	if( o.hasClass('automovie_standalone') ) {

		// If something plays already then kill it.
		var remove_player	= $('#movie_player_standalone').find('.jp-jplayer').first();
		if(	remove_player.hasClass('jp-jplayer') ) {
			remove_player.jPlayer("pause");
			remove_player.jPlayer("stop");
			remove_player.jPlayer("destroy");
		}
		$(window).scrollTop(	parseInt($('#content_right').first().offset().top) -10 	)


		$('#movie_player_standalone').html(	'<img src="/customize/image/1x1_trans.gif"><div class="movie_player_standalone_closer">&nbsp;</div>' );
		image_to_replace				= $('#movie_player_standalone img');
		movie_player_standalone_closer	= $('#movie_player_standalone div.movie_player_standalone_closer').first();
		movie_player_standalone_closer.click( function() {
			movie_player_standalone_close();
		});
		
		// carefull. o ist the image representing the movie. But if it´s a standalone-player, the image getting replaced is the one *there*in. So, o==image_to_replace or !=, depending on playmode.
		var height=100;
		var width=100;
//		 automovie automovie_standalone automovie_height_400 automovie_width_400
		var tmp	= o.attr('class');
		height	= tmp.match(/automovie_height_(\d+)/)[1];
		width	= tmp.match(/automovie_width_(\d+)/)[1];

		$('#movie_player_standalone').animate({'height':height+'px'}).animate({'marginBottom':'20px'});
		image_to_replace.css('width',width+'px');
		image_to_replace.css('height',height+'px');
		image_to_replace.css('margin-left',((940-width)/2)+'px');
	} else {
		image_to_replace	= o;
	}

	var auto_movie_count=0;
	if( $(window).attr('auto_movie_count') ) {
		auto_movie_count	= parseInt( $(window).attr('auto_movie_count') );
	}
	$(window).attr('auto_movie_count' , auto_movie_count+1 );

	var	jquery_jplayer_id	= "jquery_jplayer_"+auto_movie_count;
	var	jp_container_id		= "jp_container_"+auto_movie_count;
	
	var movie_name			= o.attr('src');		movie_name		= movie_name.replace(/\.\w+$/ , '' );
	var movie_width			= parseInt(image_to_replace.css('width') );
	var movie_height		= parseInt(image_to_replace.css('height'));
	var movie_fullscreen	= o.hasClass('automovie_fullscreen');
	var movie_no_gui		= o.hasClass('automovie_no_gui');

	var movie_container	= 	MOVIEPLAYERHTML; // custom.js.php
	movie_container	= movie_container.replace(/JPLAYER_PLAYER_ID/g , jquery_jplayer_id).replace(/JPLAYER_CONTAINER_ID/g , jp_container_id).replace(/JPLAYER_TITLE/g , 'Movie');
	movie_container	= $(movie_container);

	for (var i=0 ; i<4 ; i++ ) {
		for( var j=0 ; j<3 ; j++ ) {
			var prop	= Array('border' , 'margin' , 'padding' )[j] + '-' + Array('left' , 'right' , 'top' , 'bottom' )[i];
			movie_container.css(prop ,	image_to_replace.css(prop));
		}
	}

	image_to_replace.after( movie_container );
	image_to_replace.remove();
	
	$("#"+jp_container_id).css('width' , movie_width+'px');
	$("#"+jp_container_id+" .jp-type-single").css('width' , movie_width+'px');


	$("#"+jquery_jplayer_id).jPlayer("pauseOthers"); // pause all players except this one.

	// Error in the docs: 'fullscreen' must be written 'fullScreen'

	if( movie_no_gui ) {
		$("#"+jp_container_id+ " div.jp-gui").css('visibility' , 'hidden'); //display none klappt nicht
	}


	$("#"+jquery_jplayer_id).jPlayer({
		cssSelectorAncestor: "#"+jp_container_id ,
		autohide: {
			restored:1 ,
			full:1
		} ,
		errorAlerts: MOVIEPLAYERRUNSONEGON ,
		warningAlerts: MOVIEPLAYERRUNSONEGON ,
		fullScreen: movie_fullscreen ,
		ready: function () {
			$(this).jPlayer("setMedia", {
				m4v:	movie_name+".m4v",
				ogv:	movie_name+".ogv",
				webmv:	movie_name+".webm",

				poster:	movie_name+".jpg"
			});

			// Attempt to auto play the media. For BrowserisMobile see custom.js
			// Mobile browsers do not allow autoplay, trying renders page unusable.
			if ( ! BrowserisMobile ) {
				$(this).jPlayer("play");
			}

			auto_movie_resize_event($(this));
		},
		swfPath: "/customize/jplayer/js",
		supplied: "m4v, ogv, webmv",
		size: {
			width:  movie_width  ,
			height: movie_height ,
			cssClass: "jp-video"
		} ,
		resize:function(e){		auto_movie_resize_event( $(e.target) )		} ,
		ended:function(e){		var tmp=e.jPlayer.status.media;tmp.poster=tmp.poster.replace(/(_done)?.jpg$/ , "_done.jpg"); $(e.target).jPlayer( "setMedia" , tmp )		} ,
		click:function(e){		$(this).jPlayer("play");		} 
		
	});

//		ended:function(e){		console.debug( 	e.jPlayer.status.media.poster	);		} ,


	// Bind an event handler to the instance's play event.
	$("#"+jquery_jplayer_id).bind($.jPlayer.event.play, function() { 
		$(this).jPlayer("pauseOthers");
	});

// 		supplied: "webmv, ogv, m4v",


//	$("#"+jquery_jplayer_id).find('.jp-interface').hide();

//	$("#"+jquery_jplayer_id).jPlayer('play');

/*
	if( $("#jplayer_inspector") ) {
		$("#jplayer_inspector").jPlayerInspector( {
			jPlayer: $("#"+jquery_jplayer_id),
			visible: true
		});
	}
*/

/*


$("#jquery_jplayer_0").click(function() {
  $("#jquery_jplayer_0").jPlayer("play");
  return false;
});

$("#jquery_jplayer_0").click(function() {
	$("#jquery_jplayer_0").jPlayer("pause");
	return false;
});


	cssSelector: {
		play: "",
		pause: ""
	} ,


*/
	
}

