$(function() {
	if (document.getElementById("gallery") != null) {
		//install flowplayer for video gallery
		$f("gallery", flowplayer_path+"flowplayer.commercial-3.0.5.swf", {
			key: '$3f4bda11e65a33b200f',
			
			logo: { 
			    url:flowplayer_path+'gdh-logo-gal.png', 
			    fullscreenOnly: false, 
			    displayTime: 0,
				top: '80%', 
				left: '16%', 
				opacity: 1.0
			},		

			clip:{
				// these two configuration variables does the trick
				autoPlay: false,
				autoBuffering: true,
				scaling: 'fit'
			},

			onBeforeFullscreen : function()  {
				$("a.gall[rel]").click();
				this.pause();
				this.hide();
				return false;
			},

			plugins: {
				controls: {
					play:false,
					volume:true,
					mute:true,
					time:false,
					stop:true,
					playlist:false,
					fullscreen:true,
					scrubber: true
				}
			}
		});

		// install flowplayers for maximize
		$("a.player").flowplayer(flowplayer_path+"flowplayer.commercial-3.0.5.swf", {
			key: '$3f4bda11e65a33b200f',
			
			logo: { 
			    url:flowplayer_path+'gdh-logo-fp-b.png', 
			    fullscreenOnly: false, 
			    displayTime: 0,
				top: '85%', 
				left: '16%', 
				opacity: 1.0
			},		

			// use the first frame of the video as a "splash image"
			clip: {
					autoPlay: false,
					autoBuffering: true,
					scaling:'fit',
						
					onCuepoint: [[0], function(clip, point) { 
						var plugin = this.getPlugin("content"); 
						plugin.show().setHtml($("span.videoTitle1").html() );
						//$("#nowplaying_video").html($("span.videoTitle1").html() );
					}] 						
			},

			plugins: {
				controls: {
					stop:true
				},
						
				content: { 
					url: flowplayer_path+'flowplayer.content-3.0.2.swf', 
					height: 30, 
					 
					// plugin is initially hidden 
					display: 'none' 
				} 						
			}

		});

		// setup overlay actions for maximize the player in gallery
		$("a.gall[rel]").overlay({

			// setup exposing (optional operation);
			onBeforeLoad: function() {
				$("#nowplaying_video").html("");
				this.expose();
			},

			onLoad: function(content) {
				// find the player contained inside this overlay and load it
				$("a.player", content).flowplayer(0).load();
			},

			onClose: function(content) {
				$("a.player", content).flowplayer(0).unload();
				$f("gallery").show();
				// cloase exposing
				$.expose.close();
			}
		});
	}

	// setup overlay actions for I am Interested
	$("button[rel]").overlay({
		
		// load external page
		onLoad: function(content, link) { 
			$("#overlay_i_am_interested a div").load(this.getTrigger().attr("href"));
		},
		
		
		onBeforeLoad: function() {
			if (document.getElementById("gallery") != null) {
				$f("gallery").hide();
			}
			this.expose();	
		},
		
		onClose: function(content) { 
		
			// close exposing
			$.expose.close();
			if (document.getElementById("gallery") != null) {
				$f("gallery").show();
			}
		}
	});				

	// setup player  for playlist
	$f("player_playlist", flowplayer_path+"flowplayer.commercial-3.0.5.swf", {

		key: '$3f4bda11e65a33b200f',
		
		logo: { 
		    url:flowplayer_path+'gdh-logo-fp-b.png', 
		    fullscreenOnly: false, 
		    displayTime: 0,
			top: '85%', 
			left: '16%', 
			opacity: 1.0
		},		

		// properties that are common to both clips in the playlist
		clip: { 
			// by default clip lasts 5 seconds
			autoBuffering: true,
			autoPlay: true,
			duration: 5,
			scaling: 'fit',
						
			onCuepoint: [[0], function(clip, point) { 
				var plugin = this.getPlugin("content"); 
				plugin.show().setHtml($("div.clips a[href='" + this.getClip().url + "'] span.videoTitle").html() ); 
				//$("#nowplaying").html($("div.clips a[href='" + this.getClip().url + "'] span.videoTitle").html() );
			}] 						
		},
		
		// show playlist buttons in controlbar
		plugins:  {
			controls: {
				stop:false,
				playlist:false,		
				volume:false,
				mute:false,
				scrubber: false,
				time:false
			}, 
						
			content: { 
				url: flowplayer_path+'flowplayer.content-3.0.2.swf', 
				height: 30, 
				 
				// plugin is initially hidden 
				display: 'none' 
			} 						
		}	
	}).playlist("div.petrol", {loop:true});

	// setup overlay actions for playlist
	$("a.show_playlist[rel]").overlay({

		// setup exposing (optional operation);
		onBeforeLoad: function() {
			if (document.getElementById("gallery") != null) {
				$f("gallery").hide();
			}
			$("#nowplaying").html("");
			this.expose();
		},

		onLoad: function(content) {
			// find the player contained inside this overlay and load it
			$("a.player_playlist", content).flowplayer(0).load();
		},

		onClose: function(content) {
			$("a.player_playlist", content).flowplayer(0).unload();
			// cloase exposing
			$.expose.close();
			if (document.getElementById("gallery") != null) {
				$f("gallery").show();
			}
		}
	});

	// setup overlay actions for Email to Friend
	$("a.emailtofriend[rel]").overlay({
		
		// load external page
		onLoad: function(content, link) { 
			$("#overlay_email_to_friend a div").load(this.getTrigger().attr("href"));
		},
		
		
		onBeforeLoad: function() {
			if (document.getElementById("gallery") != null) {
				$f("gallery").hide();
			}
			this.expose();	
		},
		
		onClose: function(content) { 
		
			// close exposing
			$.expose.close();
			if (document.getElementById("gallery") != null) {
				$f("gallery").show();
			}
		}
	});				

});
