jQuery(function($) {
	$.init_images();
	$.init_videos();
	$.init_html();
});

(function($) {
	$.init_images = function() {
		var $$ = $('.lightbox');
		// $.build_image_overlays($$);
		$$.fancybox({
			'hideOnContentClick': false,
			'overlayOpacity': 0.80,
			'zoomSpeedIn': 700,
			'zoomSpeedOut': 500,
			'easingIn': 'easeOutBack',
			'easingOut': 'easeInBack',
			'scrolling'	: 'no',
			'frameWidth' : 620,
			'frameHeight' : 420
		});
	};

	$.init_html = function() {
		var $$ = $('.html');
		
		$$.fancybox({
			'hideOnContentClick': false,
			'overlayOpacity': 0.80,
			'zoomSpeedIn': 700,
			'zoomSpeedOut': 500,
			'easingIn': 'easeOutBack',
			'easingOut': 'easeInBack',
			'scrolling'	: 'no',
			'showNavArrows' : false
		});
	};
	
	$.init_videos = function() {
		var videoclip = '';
		var player = '';
		var $$ = $('.video');
		
		/*
		$.build_image_overlays($$, {
			icon: 'control-play'
		});
		*/
		
		$$.hover(function() {
			videoclip = $(this).attr('href');
			$(this).attr({
				'href': '#video_box'
			});
		}, function() {
			$(this).attr({
				'href': videoclip
			});
		});
		
		$$.fancybox({
			'hideOnContentClick': false,
			'overlayOpacity': 0.80,
			'zoomSpeedIn': 700,
			'zoomSpeedOut': 500,
			'easingIn': 'easeOutBack',
			'easingOut': 'easeInBack',
			'callbackOnShow': function() {
				var file = $$.attr('href');
				var path = file.substring(0, file.lastIndexOf('/'));
				
				player = $f('fancy_div', (path + '/flowplayer/flowplayer-3.2.2.swf'), {
					play: {
						opacity: 0
					},
					clip: {
						url: file,
						autoPlay: true,
						autoBuffering: true,
						onStart: function(clip) {
							var wrap = $(this.getParent());
							var clipWidth = clip.metaData.width;
							var clipHeight = clip.metaData.height;
							var pos = $.fn.fancybox.getViewport();
							
							$('#fancy_outer').css({
								width: clipWidth,
								height: clipHeight
							});
							
							$('#fancy_outer').css('left', (((clipWidth + 36) > pos[0]) ? pos[2] : (pos[2] + Math.round((pos[0] - clipWidth - 36) / 2))));
							$('#fancy_outer').css('top', (((clipHeight + 50) > pos[1]) ? pos[3] : (pos[3] + Math.round((pos[1] - clipHeight - 50) / 2))));
						},
						onFinish: function() {
							// $('#fancy_close').trigger('click');
						}
					},
					plugins: {
						controls: {
							buttonColor: '#FFFFFF',
							backgroundColor: '#333333',
							backgroundGradient: 'none',
							sliderColor: '#FFFFFF',
							sliderBorder: '1px solid #000000',
							progressColor: '#CE5622',
							volumeSliderColor: '#FFFFFF',
							volumeBorder: '1px solid #000000',
							timeColor: '#FFFFFF',
							durationColor: '#969696',
							opacity: 0.98,
							height: 36
						}
					}
				});
				
				player.load();
				
				$('#fancy_close').click(function() {
					$('#fancy_div_api').remove();
				});
			},
			'callbackOnClose': function() {
				$('#fancy_div_api').remove();
			}
		});
	};
})(jQuery);
