function OnLoad() {

	if ($("#video_cont").size() > 0) {

		// establish default tags
		var defaultTags = [{ query : $("#yt_query").val()}];

		var options = { string_allDone : "Zatvori video" };
		var mySearch = new GSvideoSearchControl(document.getElementById("videosc"), defaultTags, null, null, options);

		$(".results_gsvsc").bind("click", function() {
			$("#video_cont").removeClass("box_pola_levo").addClass("video_wide");
			$("#features_cont").removeClass("box_pola_desno");
		});
		$(".more_gsvsc").bind("click", function() {
			$("#video_cont").removeClass("video_wide").addClass("box_pola_levo");
			$("#features_cont").addClass("box_pola_desno");
		});


		setTimeout(function() {

			if ($("#yt_is_finished").val() == 0) {

				if ($(".video-result_gsvsc").length == 0) {
					var temp_arr = $("#yt_query").val();
					var temp_arr = temp_arr.split("+");
					var ii=temp_arr.length;

					if (ii > 2) {
						var new_yc_query = '';
						for (var i=0; i<ii; i++) {
							if (i != ii-1) {
								new_yc_query += temp_arr[i]+'+';
							}
						}
						new_yc_query = new_yc_query.substring(0, new_yc_query.length-1);
						yc_update('0|||'+new_yc_query);
					}
					else {
						yc_update('-1');
					}

					//mySearch.execute(new_yc_query);
					//$(".gsc-input").val("");
				}
				else {
					yc_update('1|||'+$("#yt_query").val());
				}
			}
		}, 2000);
	}
}

GSearch.setOnLoadCallback(OnLoad);


function yc_update(yc_query) {
	var post_data = "id="+$("#itemid").val()+"&yt_query="+yc_query;
	$.ajax({
		type: "POST",
		url: "/ajax/yt.php",
		data: post_data,
		success: function(msg) {
		}
	});
}

$(document).ready(
	function(){
		$(".results_gsvsc div.video-result_gsvsc img").bind("click", function() {$("#video_cont").css("width", "100%");});
		$(".more_gsvsc").bind("click", function() {$("#video_cont").css("width", "230px");});
	}

);
