jQuery.noConflict();

jQuery(document).ready(function(){


    // assign a click event to the exposed element
    jQuery("address").click(function() { 
 
		var originalFontSize = jQuery(this).css('font-size');
		var originalWidth = jQuery(this).css('width');
		var originalHeight = jQuery(this).css('height');
		var zoom = 1.4;
 
        // perform exposing for the clicked element 
        jQuery(this).expose({
			api: true,
			color: '#888',
			onBeforeLoad: function() { 
				
				var targetWidth = this.getExposed().width() * zoom;
				var targetHeight = this.getExposed().height() * zoom;
				
	
				this.getExposed().stop(false, true).animate({
					width: targetWidth,
					
					padding: '10px',
					fontSize: '20'
				  }, 300, function() {
					// Animation complete.
				  });
			},
			onBeforeClose: function() { 
				
				this.getExposed().animate({
					width: originalWidth,
					padding: '0px',
					fontSize: originalFontSize
				  }, 300, function() {
					// Animation complete.
				  });
			}
		}).load(); 
 
    }); 



	/* Hauptnavigation, 1. Ebene */
	jQuery("div.menu ul li").children("ul").hide();
	jQuery(".current_page_ancestor").children("ul").show();
	jQuery("div.menu ul li").has("ul").click(
			function(e) {
				var kids = jQuery(this).children("ul");		
jQuery("div.menu ul li ul li").children("ul").hide();				
				kids.toggle();
				return false;
			}
	);
	
	
	/* Hauptnavigation, 3. Ebene */
	jQuery("div.menu ul li ul li").children("ul").hide();
	jQuery(".current_page_parent").children("ul").show();
	

	
	jQuery("div.menu ul li ul li ul li a").click(
			function(e) {
				location = jQuery(this).attr("href"); 			
			}
	)
	
	
	

	
	/* Directors page */
	var currentVideo = null;
	
	var config = {    
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		interval: 200, // number = milliseconds for onMouseOver polling interval    
		over: showVideo, // function = onMouseOver callback (REQUIRED)    
		timeout: 3000, // number = milliseconds delay before onMouseOut    
		out: hideVideo // function = onMouseOut callback (REQUIRED)    
	};

	
	//jQuery(".directorsVideo").hoverIntent(config);
	
	function showVideo(){ 

		var relOfLink = jQuery(this).attr('rel');
		//set new current video
		currentVideo = relOfLink;

		jQuery(this).next("img").css("display", "none");
		
		//show meta information
		jQuery(".videoMetaData").css("display", "none");
		jQuery("#videoMeta"+relOfLink).slideToggle(400);
		
		//call flowplayer
		$f("flowplayer"+relOfLink, "http://tonypetersenfilm.de/wp-content/plugins/wordtube-flowplayer/flowplayer_commercial/flowplayer.commercial-3.1.0.swf",
			{
				key: '#$d18debe3baa0a9305fa',
				version: [9, 115],
				onFail: function() {
					document.getElementById("flowplayer"+this.rel).innerHTML = 'You need the latest Flash version to see MP4 movies. Your version is ' + this.getVersion()
				},
				onFullscreen: function () {
					this.getClip().update({scaling: 'fit'})
				},
				onFullscreenExit: function () {
					this.getClip().update({scaling: 'scale'})
				},
				onLoad: function(){ 
				
				},
				onFinish: function() { 
					this.unload();
					jQuery("#videoMeta"+relOfLink).slideToggle(400);
				},
				clip: {
					onBeforeBegin: function() {
						//jQuery.ajax({type: 'POST', data: 'id=" . $id . "',url: '" . WTFLOW_WEB_PATH . "/counter.php'})
					},
					url : this.href,
					autoPlay : true,
					autoBuffering : false,
					bufferLength : 0,
					scaling: "fit"
				},
				canvas: { 
					backgroundGradient: 'none',
					backgroundColor: 'transparent'
				},
				plugins: {
					controls: {
						autoHide: true,
						play: true,
						volume: true,
						time: false,
						stop: false,
						mute: false,
						playlist: false,
						fullscreen: true,
						backgroundGradient: 'none', 
						backgroundColor: 'transparent', 
						height:20,
						opacity: 0.75 
					}
				}
			}
		);
	}
	
	function hideVideo(){ 
	
		var target = jQuery(this);
		var relOfLink = target.attr('rel');
		
		$f("flowplayer"+relOfLink).stop();
		$f("flowplayer"+relOfLink).unload();
		
		//target.css("display", "none");
	} 
	
	
});

function openLargeVideo(id) {

	//pause video
	$f("flowplayer"+id).stop(); 
	$f("flowplayer"+id).unload(); 
	
	var thisID = id;

	//overlay
	var vid = "#video"+thisID;

	jQuery(vid).overlay({ 

		expose: { 
			color: '#fff', 
			loadSpeed: 200, 
			opacity: 0.5 
		},
		closeOnClick: true, 
		api: true, 
		onLoad: function(event) {
			showPopupVideo(thisID);
		}

	}).load();

}

function showPopupVideo(id) {

	//call flowplayer
	$f("flowplayerPopup"+id, "http://tonypetersenfilm.de/wp-content/plugins/wordtube-flowplayer/flowplayer_commercial/flowplayer.commercial-3.1.0.swf",
		{
			key: '#$d18debe3baa0a9305fa',
			version: [9, 115],
			onFail: function() {
				document.getElementById("flowplayerLink"+this.rel).innerHTML = 'You need the latest Flash version to see MP4 movies. Your version is ' + this.getVersion()
			},
			onLoad: function(){ 
			},
			onFinish: function() { 
				this.unload();
			},
			clip: {
				onBeforeBegin: function() {
					//jQuery.ajax({type: 'POST', data: 'id=" . $id . "',url: '" . WTFLOW_WEB_PATH . "/counter.php'})
				},
				url : this.href,
				autoPlay : true,
				autoBuffering : true,
				bufferLength : 0,
				scaling: 'fit'
			},
			canvas: { 
				backgroundGradient: 'none',
				backgroundColor: 'transparent'
			},
			plugins: {
				controls: {
					autoHide: true,
					play: true,
					volume: true,
					time: false,
					stop: false,
					mute: false,
					playlist: false,
					fullscreen: true,
					backgroundGradient: 'none', 
					backgroundColor: 'transparent', 
					height:20,
					opacity: 0.65 
				}
			}
		}
	);

}

function hideVideoMetaData() {
	jQuery(".videoMetaData").css("display", "none");
}