var jQ = jQuery;
// const
var BASE = jQ('base').attr('href');

jQuery(document).ready(function()
{
	if (jQ('#SearchForm_ScreeningSearchForm')){
		
		var $ScreeningSearchInput = jQ('#SearchForm_ScreeningSearchForm_ScreeningSearch');
		var SearchForm_Search_Val = $ScreeningSearchInput.val();
			
		$ScreeningSearchInput.focus(function() 
		{	
			if ($ScreeningSearchInput.val() == "Suche" || 
				$ScreeningSearchInput.val() == "Search") 
				jQ(this).val("");	
		});
		$ScreeningSearchInput.blur(function() 
		{	
			if ($ScreeningSearchInput.val() == "")
				jQ(this).val(SearchForm_Search_Val);
				
		});
	}
	if (jQ('#Form_SearchForm_Search')){
		
		var $ScreeningSearchInput = jQ('#Form_SearchForm_Search');
		var SearchForm_Search_Val = $ScreeningSearchInput.val();
			
		$ScreeningSearchInput.focus(function() 
		{	
			if ($ScreeningSearchInput.val() == "Suche" || 
				$ScreeningSearchInput.val() == "Search") 
				jQ(this).val("");	
		});
		$ScreeningSearchInput.blur(function() 
		{	
			if ($ScreeningSearchInput.val() == "")
				jQ(this).val(SearchForm_Search_Val);
				
		});
	}
	jQ('.screeningGroup:first').addClass('current');
	jQ('.screeningGroup')
	.not('.current')
	.hide();
	jQ('#earlier').hide();
	$screeningGroups = jQ('.screeningGroup');

	jQ('#centerCol_head .right')
	.css({
		"cursor":"pointer"
	})
	.click(function() {
		window.print();
	});
	initPlayer();
	jQ('.filter').find('a').bind({
		click:function(e){ 
			jQ(this).siblings('.active').removeClass('active');
			jQ(this).addClass('active');
			jQ('.photo-category').show().not('.'+ jQ(this).attr('data-filter')).hide();
			if (jQ(this).attr('data-filter') == 'all') 			jQ('.photo-category').show();
		}
	});
	if (jQ('.noscreenings').length > 0 ){
		jQ('#earlier, #later').remove();
	}
});

function initPlayer()
{

	if (jQ('.pl').length > 0) {
		var player = "<h3>Podcasts</h3>";
		jQ('.pl').each(function(index) {
			player+= jQ(this).html();
		})
		.remove();
		jQ('#podcasts').html(player);
	}
}

var group = 0;

function nextScreenings(){


	if (group < $screeningGroups.length && group >= 0) {
		group++;		
		jQ('#earlier').show();
		jQ('.screeningGroup.current').removeClass("current").hide();
		jQ($screeningGroups[group]).addClass("current").show();		
	} 		
	if (group >= $screeningGroups.length-1)
	{
		jQ('#later').hide();
		jQ('#earlier').show();
		group = $screeningGroups.length-1;
	}
}
function previousScreenings(){

	if (group <= 0)
	{
		jQ('#earlier').hide();
		jQ('#later').show();
		group = 0;
	}
	if (group >= 1 && group < $screeningGroups.length) {

		group--;
		jQ('#later').show();
		jQ('.screeningGroup.current').removeClass("current").hide();
		jQ($screeningGroups[group]).addClass("current").show();
	}
	if (group <= 0){
		jQ('#earlier').hide();
	}

}


function protectedMail(id)
{
	var acc = jQ.get(BASE+'/kuenstler-datenbank/Mailto/'+id, function(data){
		if (data.length > 0) {
			window.location.href = data;
		}		
	} );


}


function SocialMedia(){
	jQ(function(){
		jQ('#socialshareprivacy').socialSharePrivacy({
			css_path: BASE+"dokfest/css/socialshareprivacy.css",
			services: {
				facebook: {
					'dummy_img': BASE+'dokfest/images/socials/dummy_facebook.png'
				},
				twitter: {
					'dummy_img': BASE+'dokfest/images/socials/dummy_twitter.png'
				},
				gplus: {
					'display_name': 'Google Plus',
					'dummy_img': BASE+'dokfest/images/socials/dummy_gplus.png'
				}
			}
		});
	});
}

