(function($){
	$(document).ready(function(){
		$(':input[placeholder]').placeholder();
		
		$('div.navigation').filter(function(){
			return $(this).children('div:empty').length == 2;
		})
		.remove();
		//initFlowPlayer();
		//position for fixed
		$('div.lightbox').live('oap.position',function(){
			var $this = $(this);
			$this
			.css({
				top:($(window).height()/3)+'px',
				left:(($(window).width()/2) -250)+'px'
			});
		});
		
		$('a.inline-video').live('click',function(){
			//grab the overlay from signin
			var overlay = $(document.body).children('div.ui-widget-overlay').fadeIn('fast');
			
			var playerParams = {
				src: '/wp-content/plugins/fv-wordpress-flowplayer/flowplayer/flowplayer.swf',
				wmode:'transparent'	
			},
			$this = $(this),
			data = $this.data('vid-setup');
			
			if(data){
				//console.log('open');
				//open lightbox and start playing the vid
				data.wrapper.fadeIn('fast',function(){
					data.player.play(); 
				})
				.trigger('oap.position');
				
			}else{
				//setup everything
			
				var $wrapper = $('<div class="lightbox ui-corner-all"><div class="close"><img alt="close" src="http://officeautopilot.com/wp-content/themes/OfficeAutoPilot3/images/ico-button-close.png"></div><div class="vid" style="width:500px; height:281px;"></div></div>')
				.css({
					position:'fixed',
					'z-index':'10000',
					'background':'#feffff'
				})
				.trigger('oap.position')
				.bind('close',function(){
					data.player.stop();
					data.wrapper.fadeOut('fast',function(){
						overlay.fadeOut('fast');
					});

				})
				.appendTo(document.body)
				.find('div.close')
				.click(function(){
					$(this).closest('div.lightbox').trigger('close');
					
				})
				.end();
				
				var player = flowplayer($wrapper.children('div.vid')[0],playerParams, 
					{
					clip: {
						url: this.href,
						scaling: 'fit',
						autoBuffering: true
					},		
					onKeyPress: function(key) {
						if (key == 27) data.wrapper.trigger('close');
					}
				});
				player
				.ipad()
				.play();
				var data = {
					wrapper:$wrapper,
					player:player
				};
				$this.data('vid-setup',data);		
			}
			return false;
		});
		
		//do the plugins job of flow player
		$('a.flowplayer').each(function(){
			var self = this,
			buffering = true;
			
			flowplayer(this,
			{
				src:"/wp-content/themes/OfficeAutoPilot3/swf/flowplayer.commercial-3.2.5.swf",
				wmode:'transparent',
				width:'500',
				height:'280'
			}, 
			{
				key: '#$a7ff13c94e064d176b4',              
				clip: {
				   autoPlay: false,
				   autoBuffering: true,
				   start: 2,
				   url: ('mp4:vod/moonray.moonray/' + this.getAttribute('data-href')),
				   provider: 'hddn',
				   onBegin : function(){
				   		if(buffering){
				   			setTimeout(function(){
				   			$f(self).stopBuffering();
				   			buffering = false;
				   		},1000);
				   		}
				   }
				},
				canvas: { 
					// remove default canvas gradient 
				//	backgroundGradient: 'none'
				},
				// streaming plugins are configured under the plugins node
				plugins: {
					hddn: {
							url: '/wp-content/themes/OfficeAutoPilot3/swf/flowplayer.rtmp-3.2.3.swf',
							netConnectionUrl: 'rtmp://rtmp01.hddn.com/play'
					},
					controls: {
						//opacity: 0,
					 	url: "/wp-content/themes/OfficeAutoPilot3/swf/flowplayer.controls-3.2.3.swf"
					 }
				}
			
								
			});
		});
		
		
		
	});
	
})(jQuery);

