jQuery(document).ready(function(){
  try
  {
    var a = flowplayerkey;
  }
  catch (e){
    var flowplayerkey = '';
  }

  //Flowplayerek pusztítása
  function removeFlowplayers(){
    try{
      $f("*").each(function() {
        this.unload();
      });
    } catch ( e ) {alert(e);}
  }

  //videóplayer linkek betöltése
  $('.videoPlayer').flowplayer("/flash/flowplayer.commercial.swf", fp_config ).load();

  $('.fp_overlay').live('click', function(e)
  {
	$(".fp_overlay").remove();
	$f().resume();
	var $current_player = $('#' + current_flowplayer_id);
	var current_height = $current_player.data('lastheight');
	$current_player.css('height', current_height);
  });

	$('.fp_overlay a').live('click', function(e)
	{
		window.open($(this).attr("href"));
		return false;
	});

	$(".watermark").each(function()
	{
		$(this).watermark($(this).attr('title'));
	});
});

//toggle default text for input tags
jQuery.fn.extend({
  toggleDefault: function(e){
    this.focus(function(){
      if($(this).val() == e){
        $(this).val('');
      }
    }).blur(function(){
      if($(this).val() == ""){
        $(this).val(e);
      }
    }).parents('form').submit(function(){
      $(this).find('input').each(function(){
        if($(this).val() == e){
          $(this).val('');
        }
      });
    })
  }
});

function getFlowShare()
{
	var vid = current_flowplayer.getClip(0).url;
	vid = vid.slice(vid.lastIndexOf('/'));
	
	$.ajax(
	{
		'url': '/frontend_dev.php/media/videoShare/video' + vid,
		'success': function(html)
		{
			$f().pause();
			
			var $current_player = $('#' + current_flowplayer_id);
		    var current_height = $current_player.css('height');

		    $current_player.data('lastheight', current_height).height('0px');
		    $current_player.closest('.media_box').append(html).find('.fp_overlay').height(current_height);
		}
	});
}


function getFlowEmbed()
{
  $.ajax({
    'url': '/media/videoEmbed',
    'success': function(html)
    {
      $f().pause();

      var $current_player = $('#' + current_flowplayer_id);
      var current_height = $current_player.css('height');

      $current_player.data('lastheight', current_height).height('0px');
      $current_player.closest('.media_box').append(html).find('.fp_overlay').height(current_height);

      var $item = $('#' + current_flowplayer_id).closest('.media_box').find('.fp_overlay textarea').val(current_flowplayer.embed().getEmbedCode(true).replace(">", "\n") );
      $item[0].focus();
      $item[0].select();

      $('.fp_overlay textarea').click(function(e){
        e.target.focus();
        e.target.select();

        e.stopPropagation();
        return false;
      });
    }
  });
}
