$(function() {

	// scrollable for video gallery
	$("div.scrollable").scrollable({
		size: 5,
		items: '#thumbs',
		hoverClass: 'hover',
		keyboard:false
	});

	// install flowplayer for video
	$("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: true,
				autoBuffering: true,
				scaling:'fit',
						
				onCuepoint: [[0], function(clip, point) { 
					var plugin = this.getPlugin("content"); 
					plugin.show().setHtml($("div.main_inner a[href='" + this.getClip().url + "'] span.videoTitle").html() ); 
					//$("#nowplaying_video").html($("div.main_inner a[href='" + this.getClip().url + "'] span.videoTitle").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 video
	$("a.show_video[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();
			// cloase exposing
			$.expose.close();
		}
	});

	// setup overlay actions for city
	$("a.show_city[rel]").overlay({

		// setup exposing (optional operation);
		onBeforeLoad: function() {
			this.expose();

		},

		onLoad: function(content, link) {
			// find the player contained inside this overlay and load it
			//$("#city_overlay a div").load("<? echo constant('HOME_PATH')?>show_cities.php?return_add=<?echo $_SERVER['PHP_SELF']?>"); 
			//$("#city_overlay a div").load(link.attr("href")); 
			$("#city_overlay a div").load(this.getTrigger().attr("href"));
		},

		onClose: function(content) {
			// cloase exposing
			$.expose.close();
		}
	});

	// setup overlay actions for city
	$("a.show_gal_pic_playlist[rel]").overlay({

		// setup exposing (optional operation);
		onBeforeLoad: function() {
			$("#nowplaying").html("");
			this.expose();

		},

		onLoad: function(content, link) {
			// find the player contained inside this overlay and load it
			//$("#gal_pic_playlist_overlay a div").load(link.attr("href")); 
			this.getContent().find("div.wrap").load(this.getTrigger().attr("href"), function() {
				$f("player_playlist_gal_pic2", 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.playlist a[href='" + this.getClip().url + "'] span.videoTitle").html() ); 
							//$("#nowplaying").html($("div.playlist 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.clips_gal_pic", {loop:true});
			});
		},

		onClose: function(content) {
			// cloase exposing
			$f("player_playlist_gal_pic2").unload();
			//$f().unload();
			$.expose.close();
		}
	});

	// get all links that are inside div#clips for video gallery
	if (document.getElementById("thumbs") != null) {
		var links = document.getElementById("thumbs").getElementsByTagName("a");

		// loop those links and alter their click behaviour
		for (var i = 0; i < links.length; i++) {
			links[i].onclick = function() {

				if (this.getAttribute("rel")) {
					// play the clip specified in href- attribute with Flowplayer
					$f(0).play(this.getAttribute("href"));

					// by returning false normal link behaviour is skipped
					return false;
				} else {
					return true;
				}
			}
		}
	}
});