$(document).ready(function()
{

$("input[name='wykonawca']").focus(function()
{
if($(this).val()=="wykonawca") $(this).val("");
});

$("input[name='utwor']").focus(function()
{
if($(this).val()=="utwór") $(this).val("");
});

function get_val()
{
alert($('#wykonawca').val());
return $('#wykonawca').val();
}

$("input[name='login']").focus(function()
{
if($(this).val()=="login") $(this).val("");
});

	function findValueCallback(event, data, formatted) {
		$("<li>").html( !data ? "Brak wyników!" : "szukano: " + formatted).appendTo("#result");
	}
	
	function formatItem(row) {
		return row[0];
	}
	function formatResult(row) {
		return row[0];
	}

$("#wykonawca").autocomplete('/inc/wyszukiwanie/search_wyko.php', {
		width: 165,
		multiple: false,
		matchContains: true,
		formatItem: formatItem,
		formatResult: formatResult
	});
$("#utwor").focus(function()
{	
	//$("#utwor").unbind();
	$(".dodaj_info").show();
	str = $('#wykonawca').val();
	$("#utwor").autocomplete('/inc/wyszukiwanie/search_utw.php?m='+str, {
		width: 165,
		multiple: false,
		matchContains: true,
		formatItem: formatItem,
		formatResult: formatResult
	});

});

$("input[name=cat]").change(function()
{
id = $(this).val();
$("#"+id).toggle();
});

$("a#dodaj_pokaz").click(function()
{
$("a#dodaj_pokaz").hide();
$('#dodaj_form').show();
$("input#wykonawca").attr("READONLY","READONLY");
$("input#utwor").attr("READONLY","READONLY");
$("input[type=checkbox]").attr("READONLY","READONLY");
});

$("#utwor, #wykonawca").blur(function()
{
wyko = $("#wykonawca").val();
utw = $("#utwor").val();

$("#dodaj_info_tekst").text(wyko+" / "+utw);
});
});


        function updateHTML(elmId, value) {
          document.getElementById(elmId).innerHTML = value;
        }

        function setytplayerState(newState) {
          updateHTML("playerstate", newState);
        }

        function onYouTubePlayerReady(playerId) {
          ytplayer = document.getElementById("myytplayer");
          setInterval(updateytplayerInfo, 250);
          updateytplayerInfo();
          ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
        }

        function onytplayerStateChange(newState) {
          setytplayerState(newState);
        }

        function updateytplayerInfo() {
          updateHTML("bytesloaded", getBytesLoaded());
          updateHTML("bytestotal", getBytesTotal());
          updateHTML("videoduration", getDuration());
          updateHTML("videotime", getCurrentTime());
          updateHTML("startbytes", getStartBytes());
          updateHTML("volume", getVolume());
        }

        // functions for the api calls
        function loadNewVideo(id, startSeconds) {
          if (ytplayer) {
            ytplayer.loadVideoById(id, parseInt(startSeconds));
          }
        }

        function cueNewVideo(id, startSeconds) {
          if (ytplayer) {
            ytplayer.cueVideoById(id, startSeconds);
          }
        }

        function play() {
          if (ytplayer) {
            ytplayer.playVideo();
          }
        }

        function pause() {
          if (ytplayer) {
            ytplayer.pauseVideo();
          }
        }

        function stop() {
          if (ytplayer) {
            ytplayer.stopVideo();
          }
        }

        function getPlayerState() {
          if (ytplayer) {
            return ytplayer.getPlayerState();
          }
        }

        function seekTo(seconds) {
          if (ytplayer) {
            ytplayer.seekTo(seconds, true);
          }
        }

        function getBytesLoaded() {
          if (ytplayer) {
            return ytplayer.getVideoBytesLoaded();
          }
        }

        function getBytesTotal() {
          if (ytplayer) {
            return ytplayer.getVideoBytesTotal();
          }
        }

        function getCurrentTime() {
          if (ytplayer) {
            return ytplayer.getCurrentTime();
          }
        }

        function getDuration() {
          if (ytplayer) {
            return ytplayer.getDuration();
          }
        }

        function getStartBytes() {
          if (ytplayer) {
            return ytplayer.getVideoStartBytes();
          }
        }

        function mute() {
          if (ytplayer) {
            ytplayer.mute();
          }
        }

        function unMute() {
          if (ytplayer) {
            ytplayer.unMute();
          }
        }
        
        function getEmbedCode() {
          alert(ytplayer.getVideoEmbedCode());
        }

        function getVideoUrl() {
          alert(ytplayer.getVideoUrl());
        }
        
        function setVolume(newVolume) {
          if (ytplayer) {
            ytplayer.setVolume(newVolume);
          }
        }

        function getVolume() {
          if (ytplayer) {
            return ytplayer.getVolume();
          }
        }

        function clearVideo() {
          if (ytplayer) {
            ytplayer.clearVideo();
          }
        }
        


