function initFb () {
	/** init facebook **/
	  FB.init({
		appId      : '109174869184648',
		status     : true, 
		cookie     : true, 
		oauth      : true,
		xfbml      : true  
	  });


	FB.Event.subscribe('auth.login', function(respons) {
		fb.update();
     });
                 
				 
	FB.Event.subscribe('auth.logout', function() {
       fb.update();
	});
	
}

function onWindowResize (e) {

	$sizer 	 =  $( '#page-size' );
	$content = 	$( '#content-wrapper');
	$bottom  =  $( '#bottom' );
	$top 	 =  $( '#top' );


	var min_height = parseInt($sizer.css('min-height'));

	if ($(window).height() < min_height)
		$sizer.css('height',min_height+'px');
	else
		$sizer.css('height','100%');
		

	$content
		.css({
			height: $sizer.height() - $bottom.height()
			});
}




/** location hover effects **/
var locations = {
	
	init:function () {
		
		$('#locations-content > ul > li')
			.hover(locations.onSelectOver, locations.onSelectOut)
			.click(locations.onLocClick);
		
	},
	
	
	
	onSelectOver: function () {
		$(this)
			.find('.foto, .bottom-foto')
			.children('img')
			.stop()
			.animate({opacity:1},400);
		
		
		$(this)
			.find('.glow-stroke')
			.stop()
			.animate({backgroundPosition:'0 0'} ,400);
		
		
		
		$(this)
			.find('p')
			.stop()
			.animate({color:'#E9E9E9'},400);
		
	},
	
	
	
	onSelectOut: function () {
		$(this)
			.find('.foto, .bottom-foto')
			.children('img')
			.stop()
			.animate({opacity:0},400);		
	
	
	
		$(this)
			.find('.glow-stroke')
			.stop()
			.animate({backgroundPosition:'0 -530'} ,400);	
	
		$(this)
			.find('p')
			.stop()
			.animate({color:'#333'},400);	
	
	
	},
	
	
	onLocClick:function () {
		var loc = $(this).attr('loc');
		window.location.hash = loc;
	},
	
	
	
	
	onLocationLoad: function () {
		$('#djs-container > .item')
			.hover(locations.onDjOver, locations.onDjOut)
			.tooltip({
					width:250,
					onData: locations.onTooltip
				});
		
		
		
		$('#location-charts tr').hover(
			function () {
				$(this).stop().animate({'background-color':'#333333'}, 400);
				},
				
			function () {
				$(this).stop().animate({'background-color':$(this).attr('bgcolor')}, 400);
				}
		)
		.click(locations.onChartClick);
		
		
	},
	
	
	onDjOver: function () {
		$(this).stop().animate({'background-color':'#333333'}, 400);
	},
	
	onDjOut : function () {
		$(this).stop().animate({'background-color':'#000000'}, 400);
		
	},
	
	
	onTooltip : function (target) {
		$t = $(target);
		var skills = $t.find('.skills').html();
		$.tooltip.$content.html('<div class="dj-skills-tooltip">'+skills+'</div>');
	},
	
	
	
	onChartClick: function () {
		var data = $(this).attr('data');
		var config = $.extend(fancyboxDefaults,{href:'templates/charts_loader.php?s='+escape(data) ,type:'ajax',width:'auto', height:425,'onStart' : stopMusicplayer,'onClosed' : startMusicplayer});
		$.fancybox(config);	
	},
	
	
	
	onYouTubeCharsOpen: function () {
	
		$('#charts-loader li').hover(
			function () {
				$(this).stop().animate({'background-color':'#333333'}, 400);
				},
				
			function () {
				$(this).stop().animate({'background-color':'#000000'}, 400);
				}
		)
		.click(locations.updateYouTubeVideo);
		
	},
	
	
	updateYouTubeVideo: function () {
		
		var id = $(this).attr('videoid');
		var object = '<object width="100%" height="100%"><param name="movie" value="http://www.youtube.com/v/'+id+'?version=3&amp;hl=de_DE&amp;autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="transparent" ></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+id+'?version=3&amp;hl=de_DE&amp;autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="100%" height="100%" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
		$('#youtube-ebend').html(object);
		
	}
}



function events_close () {
	events.restoreDefaultEvents();
}


function start_close () {
	$.fancybox.close();
	$('#introvideo').remove();
}


/** kntakt map handel **/
function kontakt_open () {
	MAP.init();
}

var MAP = {
	map:null,
	
	init:function () {
		if (MAP.map == null) {

			  var stylez = [
					  {
						featureType: "landscape",
						elementType: "all",
						stylers: [
						  { hue:'#000000' },
						  { saturation: -100 },
						  { lightness: -10 }
						]
					  },{
						featureType: "water",
						elementType: "all",
						stylers: [
						  { saturation: -100 },
						  { lightness: -30 }
						]
					  },{
						featureType: "administrative",
						elementType: "labels",
						stylers: [
						  { hue: "#ffffff" },
						  { saturation: 0 },
						  { lightness: 0 }
						]
					  },{
						featureType: "poi",
						elementType: "all",
						stylers: [
						  { lightness: 0 },
						  { visibility: "off" }
						]
					  },{
						featureType: "landscape",
						elementType: "all",
						stylers: [
						  { visibility: "off" }
						]
					  },{
						featureType: "water",
						elementType: "labels",
						stylers: [
						  { lightness: 0 },
						  { visibility: "off" }
						]
					  },{
						featureType: "road",
						elementType: "labels",
						stylers: [
						  { visibility: "on" },
						  { hue: "#C50C85" },
						  { saturation: -30 },
						  { lightness: 0 }						  
						]
					  },{
						featureType: "administrative",
						elementType: "geometry",
						stylers: [
						  { visibility: "simplified" }
						]
					  },{
						featureType: "road.highway",
						elementType: "geometry",
						stylers: [
						  { saturation: -100 }
						]
					  },{
						featureType: "road.arterial",
						elementType: "geometry",
						stylers: [
						  { saturation: -100 }
						]
					  },{
						featureType: "road.local",
						elementType: "geometry",
						stylers: [
						  { saturation: -100 },
						  { lightness: 0 }
						]
					  },{
						featureType: "transit",
						elementType: "all",
						stylers: [
						  { visibility: "off" }
						]
					  }
					];



			var latlng = new google.maps.LatLng(52.8873600, 8.4162100);
		
		  var mapOptions = {
			zoom: 13,
			center: latlng,
			mapTypeControlOptions: {
			   mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'FunFact']
			}
		  };
		  
		MAP.map = new google.maps.Map(document.getElementById("map-embed"), mapOptions);
		
		  var styledMapOptions = {
			  name: "FunFact"
		  }
		
		  var jayzMapType = new google.maps.StyledMapType(
			  stylez, styledMapOptions);
		
		  MAP.map.mapTypes.set('FunFact', jayzMapType);
		  MAP.map.setMapTypeId('FunFact');


		var marker = new google.maps.Marker({
			position: latlng, 
			map: MAP.map, 
			title:"Fun Factory Wildeshausen "
			});   
		  
		  
		}
	}	
}






/** special trigger object **/
var sp = {
	
	triggers:{
		events_flairevents:function () {
			events.loadFlairEvent();
			}
		},

	hasTrigger: function (np) {
		if (typeof(sp.triggers[np]) == "function") {
			return sp.triggers[np];	
		}else{
			return false;	
		}
	}
}








function startMusicplayer () {
	try {swfobject.getObjectById("muisplayer-object").startSound()}catch (e) {}
}

function stopMusicplayer (){
	try {swfobject.getObjectById("muisplayer-object").stopSound()}catch (e) {}
}






var fancyboxDefaults = {
	autoDimensions:false,
	autoScale:false,
	padding:5,
	margin:5,
	width:800,
	height:'auto'
}


/** gloabl init function **/
onDocumentReady = function (e) {
		
	$( window ).resize(onWindowResize);

	slider.init( $( '#slider-content') , $( '#slider-layers' ) );
	pm.init();		
	startSlider.init();
	events.init();
	vip.init();
	fb.init();
	gallery.init();
	locations.init();
	
	$('.scroller, #serienliste, #serien_thumbs').moveScroller();
	
	/** facebook login layer **/
	$('#fb-login-layer').hover (
						function () {
							$(this).stop().animate({'margin-top': 30},300);
							}, 
						function () {
							$(this).stop().animate({'margin-top': -55},300);
							}
						);




	/** bind hover layers **/
	$('.hover-layer').parent().hover (function () {
			$(this).find('.hover-layer').stop().css('display','block').fadeTo(500,1);
		}, function () {
			$(this).find('.hover-layer').stop().fadeTo(500,0, function () {
				$(this).css('display','none');
				});
			});
	
	
	
	
	
	/** new trigger **/
	$('#start-news')
		.find('a')
		.click(function () {
			var config = $.extend(fancyboxDefaults,{href:'templates/news_detail.php',type:'ajax'});
			$.fancybox(config);
		})
		
	
	
	/** animate toogle **/
	$('#ani-toggle').click (function () {
		var $t = $(this);
		var status = $t.attr('status');
		if (status == "on") {
			$t.html('Animaton: <span class="text-p">OFF</span>');
			$t.attr('status','off');
			$.fx.off = true;
			/** save cooki **/
			$.get('animation-toggle.php',{animate:'off'});
		}else{
			$t.html('Animaton: <span class="text-p">ON</span>');
			$t.attr('status','on');
			$.fx.off = false;
			/** save cooki **/
			$.get('animation-toggle.php',{animate:'on'});		
		}
	});
	/** animate toogle **/
	
	
	/** cleanup function **/
	delete onDocumentReady;
}

$( document ).ready(onDocumentReady);
$(window).ready(initFb);


