$(document).ready(function() {

	$(".tabs-nav").tabs(".tabs-panes > div");

	$('.events-listView .event-item').hover(
		function(){ $(this).addClass('event-item-ro'); },
		function(){ $(this).removeClass('event-item-ro'); }
	);

	$('.event-item-no').click( function(){
		$(this).removeClass('event-item-no')
			.addClass('event-item-act')
			.find('.event-details').fadeIn();
		$(this).children('.event-full').slideDown();		
		$(this).find('.event-zoom').fadeIn();
	});

	$('.event-close').click( function(event){
		 event.stopPropagation();
		$(this).closest('.event-item-act').removeClass('event-item-act')
		.addClass('event-item-no')
		.find('.event-details').fadeOut();		
		$(this).nextAll('.event-abstract').find('.event-zoom').fadeOut();
		$(this).nextAll('.event-full').slideUp();
	})	

	var locationHref = location.href;
	var locationAnchorArray = locationHref.split('#');
	var locationIdArray = locationHref.split('id=');

	var interval = 8000;
	var displayInteraction = false;	

	if ($('.scrollable .item').length > 1) {
		window.api = $(".scrollable").scrollable({size: 1, clickable: false, circular: true}).navigator({navi: '.displaynavi'}).autoscroll({
		autoplay: false,
		autopause: true,
		steps: 1,
		interval: interval,
		api: true 
	});	
	} else {
		$('#actionButtons').hide();
	}
	
	$(".displaynavi a").click(function () {
		api.stop();
		playPauseDisplay( "stop" );
	});
	
	$("#playBtn").click(function () {
		playPauseDisplay( "play" );
		api.play(); 
	});
	
	$("#pauseBtn").click(function () {
		playPauseDisplay( "pause" );
		api.stop();
	});
	
	setTimeout(function(){
		displayAutoplay();
	}, interval);
	
	
	$("#tabs").tabs(".panes ul");
	
	
	$(".image").fancybox({ 
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : formatTitle,
		'onClosed'		: function() {
			closeBox();
		}
	});

	$(".video").fancybox({
	/*	'padding'		 : 0,*/
		'autoScale'		 : false,
		'transitionIn'	 : 'none',
		'transitionOut'	 : 'none',
		'titlePosition'  : 'inside',
		'showNavArrows'  : false, 
		'titleFormat'    : formatTitle,
		'width'			 : 900,
		'height'		 : 500,
		'href'			 : this.href,
		'type': 'swf', 
		'swf': { 
		'wmode': 'transparent', 
		'allowfullscreen': 'true' 
		},
		'onClosed'       : function() {
			closeBox();
		}
	});	
	
				
	if( window.location.href.match( /#/ ) )
	{
		var pic = window.location.href.split( '#' )[ 1 ];
		$( "#link" + pic ).trigger( 'click' );
	}
	else
	{
		closeBox();
	}
	
	

function displayAutoplay() {
	if( displayInteraction ==  false )
	{
		if (typeof api != 'undefined') {
			api.play();
			displayInteraction = true;
		}
	}
}
	
function playPauseDisplay( action ) {
	if( $("#playBtn").css("display") != "none" && action != "stop" )
	{
		$("#playBtn").css("display","none");
		$("#pauseBtn").css("display","inline");
	}
	else if( $("#pauseBtn").css("display") != "none" )
	{
		$("#pauseBtn").css("display","none");
		$("#playBtn").css("display","inline");
		if( displayInteraction == false )
		{
			displayInteraction = true; 
		}
	}
}	
	
function formatTitle(title, currentArray, currentIndex, currentOpts) {
	yo = currentArray[currentIndex].toString();
	setWinLoc( currentIndex + 1 );
	if( yo.search(".swf") != -1 || yo.search("youtube") != -1 )
	{
	
		//return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '<a href="http://www.addthis.com/bookmark.php" style="color:#d4b370; float:right" onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></span>';
	
		return '<div><span style="display: inline-block; width: 35%; text-align: left; line-height: 16px;">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'
			+ '<span style="display: inline-block; width: 30%; text-align: center; line-height: 16px;"><a href="javascript:;" onclick="$.fancybox.prev();">zur&uuml;ck</a> - <a href="javascript:;" onclick="$.fancybox.next();">weiter</a></span>'
		 	+ title + '<span style="display: inline-block; width: 35%; text-align: right;"><a href="http://www.addthis.com/bookmark.php" style="color:#d4b370; float:right" onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></span>'
			+ '</div>';
	}
	else
	{
		return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '<a href="http://www.addthis.com/bookmark.php" style="color:#d4b370; float:right" onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></span>';	
		//return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		
	}
}		

function setWinLoc( _src ) {
	if( window.location.href.match( /#/ ) )
	{
		var target = window.location.href.split( '#' )[ 1 ];
		target = window.location.href.replace( '#' + target, '#' + _src );
		window.location= target;
		return _src;
	}
	else
	{
		window.location = window.location + '#' + _src;
		return _src;
	}
}
	
function closeBox() {
	if( window.location.href.match( /#/ ) )
	{
		var target = window.location.href.split( '#' )[ 1 ];
		target = window.location.href.replace( '#' + target, '#' );
		window.location= target;
	}
}	
	
	
	
});



