var isiPad = navigator.userAgent.match(/iPad/i) != null;
var isiPhone = navigator.userAgent.match(/iPhone/i) != null;

jQuery(function()
{
	//jQuery('.container_11').eq(0).append(jQuery('<div id="videobox" class="abs"><div class="bg abs">&nbsp;</div><a href="#" id="closebtn" class="abs">&nbsp;</a><div class="abs" id="videobox-flash">&nbsp;</div></div>'));
	
	jQuery('#closebtn').click(function()
	{
		var el = jQuery('#videobox');
		el.animate({top:'-550px'}, 400, 'swing', onVideoHide);
		return false;
	});
	
	jQuery('a[href$=flv]').click(function()
	{
		showVideoBox(jQuery(this).attr('href'));
		return false;
	});
});

function onVideoHide()
{
	if (isiPad || isiPhone) 
	{
		var video = document.getElementById("videobox-vid");
		video.pause();
	}
	else
	{
		jQuery('#videobox-flash').empty();
	}
}

function onVideoShow()
{
	
}

function showVideoBox(flv)
{
	//jQuery('#videobox-flash').empty();
		
	if (isiPad || isiPhone)
	{
		var video = document.getElementById("videobox-vid");
		video.src = flv.replace('.flv', '.mp4');
		video.load();
		video.play();
	}
	else
	{
		jQuery('#videobox-flash').empty().flash(
	    { 
	      src: TEMPLATE_URL + '/flash/NonverBlaster.swf',
	      width: 	640,
	      height: 	360,
	      wmode: 	'opaque',
	      quality:	'high',
	      flashvars: 
	      {
	    	mediaURL:flv,
	    	allowSmoothing:true,
	    	autoPlay:true,
	    	buffer:6,
	    	showTimecode:true,
	    	loop:false,
	    	teaserURL:'teaser.jpg',
	    	controlColor:'0xFFFFFF',
	    	controlBackColor:'0x000000',
	    	scaleIfFullScreen:false,
	    	showScalingButton:false,
	    	crop:false
	      }
	    });
	}
	
	jQuery('html, body').animate({scrollTop:0}, 'fast', function()
	{
		var el = jQuery('#videobox');
		el.animate({top:'48px'}, 'fast', 'swing', onVideoShow);
		el.find('.bg').css('opacity', '0.75');
	});

}