(function($)
{
	$.fn.linePlayer = function(options)
	{
		var defaults = {
			width: 300,
			height: 200,
			src: false,
			player: '/js/jwplayer/player.swf',
			expressInstaller: '/js/swfobject/expressInstall.swf',
			menu: false,
			poster: false,
			controls: 'controls',
			disableFallback: false
		};
		
		/* merge user input with defaults specified above */
		var options = $.extend(defaults, options);
		
		/* global counter */
		var z = 0;
		
		/* get the current object */
		var obj = $(this);
		
		/* detect if UA is an iphone/ipad */
		var is_iphone = function()
		{
			var agent=navigator.userAgent.toLowerCase();
			
			/** return bool */
			return (agent.indexOf('iphone')!=-1 || agent.indexOf('ipad')!=-1) ? true : false;
		};
		
		/* build the html5 version for iphone/ipad */
		var build_html = function()
		{
			var v = $('<video />')
				.attr('width', options.width)
				.attr('height', options.height)
				.attr('controls', options.controls);
				
			/**
			* apply poster image to <video> if specified
			* Note: This only appears as the video loads on the iphone, then is removed and replaced with native apple stuff
			*/
			if(options.poster)
			{
				v.attr('poster', options.poster);	
			}
				
			/* apply source attribute if specified, else log for debug purposes */
			if(options.src)
			{
				var s = $('<source />')
					.attr('src', options.src)
					.attr('type', 'video/mp4');
			}
			else
			{
				/* if console exists, log to it */
				if(window.console)
				{
					console.log('linePlayer: MP4 Source file not supplied');
				}
			}

			/* return the element */
			return v.append(s);
		};
		
		/* return */
		return this.each(function()
		{
			if(is_iphone())
			{
				// html5 version
				//obj.unbind('click'); // unbind thickbox click event
				obj.parent().replaceWith(build_html());
			}
			//else if(options.disableFallback === false)
			//{
				// jwplayer version
			//	build_flash();
			//}
		});
	};
})(jQuery);
