$(document).ready(function() {
	
	$(".news_tab").click(function() {
		$(".news_tab").removeClass("active");
		$(".items").hide();
		$(this).addClass("active");
		$($(this).attr('href').replace(/\//, "")).show();
		return false;
	});
	
	$(".video_tab").click(function() {
		$(".video_tab").removeClass("active");
		$(".video").hide();
		$(this).addClass("active");
		$($(this).attr('href').replace(/\//, "")).show();
		return false;
	});
	
	$("a.document").each(function(i) {
		$(this).attr("rel", "facebox");
		$(this).attr("href", "fileadmin/scripts/form.php?doc="+encodeURIComponent($(this).attr('href')));
	});
	
	$('a[rel*=facebox]').facebox();

	//$.fn.fancyzoom.defaultsOptions.imgDir='typo3conf/ext/flickrset/res/js/ressources/';
	//$("#centerCol p img").fancyzoom({overlay:0.8});
	
	if($('.tx-timtabsociable-pi1')){
		$('.tx-timtabsociable-pi1').hide();

		$('#socials').toggle(
			function(){
				$('.tx-timtabsociable-pi1').slideDown();				
			},
			function(){
				$('.tx-timtabsociable-pi1').slideUp();				
			}			
		);	
		//$('.tx-timtabsociable-pi1').mouseout(function(){$(this).hide();});		
	}
	$('#active-image-control').css('cursor', 'pointer');
	

});


/**
 * People Selector
 */
function adjustPeopleToolButton(){
	var countryValue = $('#countryDropdown').val();
	var companyValue = $('#companyInstitutionDropdown').val();
	var peopleToolButton = $('#peopleToolButton');
	
	if (countryValue.length == 0) {
		//console.log('no country no company : country value : '+ countryValue +' company value : '+ companyValue);
		peopleToolButton.load(
			'http://www.berlin-school.com/index.php?eID=people'			
		);
		$('#peopleToolButton').attr(
			'href',
			'http://www.berlin-school.com/index.php?id=239'
		);
		
	}else if(countryValue.length != 0 && companyValue.length != 0 ) {
		//console.log('country and company : country value : '+countryValue + ' company value : '+companyValue);		
		peopleToolButton.load(
			'http://www.berlin-school.com',
			'eID=people&country='+countryValue+'&company='+companyValue
		);

		$('#peopleToolButton').attr(
			'href',
			'http://www.berlin-school.com/index.php?id=239&country='+countryValue+'&company='+companyValue
		);
		
	}else if(countryValue.length != 0 && companyValue.length == 0 ){
		//console.log('no company : country value : '+countryValue);
		peopleToolButton.load(
			'http://www.berlin-school.com',
			'eID=people&country='+countryValue
		);
		$('#peopleToolButton').attr(
			'href',
			'http://www.berlin-school.com/index.php?id=239&country='+countryValue
		);
	
	}
	
}

function adjustCompanyDropdown(){
	var countryValue = $('#countryDropdown').val();
	var dropdownSet = $('#companyInstitutionDropdown');
	if(countryValue.length == 0){
		dropdownSet.attr('disabled', true);
		adjustPeopleToolButton();
	} else {
		adjustPeopleToolButton();
		dropdownSet.attr('disabled', false);
		dropdownSet.load(
			'http://www.berlin-school.com/index.php?eID=company',
			'country=' + countryValue		
		);
		
		
	}
}	
