
//find all form with class jqtransform and apply the plugin  
$(function() {    
	update_genre_cbs ();
$("form.jqtransform").jqTransform();   
});

//show and hide div
function unhide(divID) {
  var item = document.getElementById(divID);
  if (item) {
    item.className=(item.className=='hidden')?'unhidden':'hidden';
  }
}

//show and hide highlights menu
$(document).ready(function()
{
	$(".highlight > .dropdownON").click(function()
	{
		var dd = $(this).next().find("> ol");

		if(dd.css("display") == "none")
		{
			$('.highlight > ol').hide('');
			dd.slideDown('');
		}
		else
		{
			dd.slideUp('Medium');
		}
	});

	$('.highlight').click(function(e)
	{
		e.stopPropagation();
	});

	$(document).click(function()
	{
		$('.highlight > div > ol').hide('');
	});
});

  function change_param (id)
  {
    s = document.getElementById (id);
    window.location = "?" + id + "=" + s.options [s.selectedIndex].value;
  }

$(document).ready (function () {
  $("#kwdid").autocomplete ("/fmtv/autocomplete.htm");
});

function set_channels_y (y)
{

          if ( y + 420 > channel_ids.length * 42 ) {
            y = channel_ids.length * 42 - 420;
            document.getElementById ('tvicons-down-imgid').src = 'img/epg/channels-down-OFF.png';
          }
          else document.getElementById ('tvicons-down-imgid').src = 'img/epg/channels-down.png';

          if ( y <= 0 ) {
            y = 0;
            document.getElementById ('tvicons-up-imgid').src = 'img/epg/channels-up-OFF.png';
          }
          else document.getElementById ('tvicons-up-imgid').src = 'img/epg/channels-up.png';

          document.getElementById ('dragwindowwrapid').style.top = -y + 'px';
          document.getElementById ('iconswrapid').style.top = -y + 'px';
          document.getElementById ('dragchannelhandleid').style.top = (y * 403 / 42 / channel_ids.length) + 'px';

}

  $(document).ready (
    function () {
      $(".tvicons-up").click (
        function () {
          y = 0;
          try {
            y = parseInt (document.getElementById ('dragwindowwrapid').style.top.substring (1), 10);
            if ( isNaN (y) )
              y = 0;
          } catch ( e ) { }
          set_channels_y (y - 420);
          fetchListings (saved_when);
        }
      );
      $(".tvicons-down").click (
        function () {
          y = 0;
          try {
            y = parseInt (document.getElementById ('dragwindowwrapid').style.top.substring (1), 10);
            if ( isNaN (y) )
              y = 0;
          } catch ( e ) { }
          set_channels_y (y + 420);
          fetchListings (saved_when);
        }
      );
      $(".handletime").click (
        function () {
          startHour = parseInt (this.title, 10);
          moveToHour (startHour);
          return false;
        }
      );
      $("#draghandlemaskid").draggable (
        {axis: 'x',
         drag: function (e, ui) {
	   // left = hour * 26 + 4
           document.getElementById ('draghandleid').style.left = ui.position.left + 'px';
           document.getElementById ('dragwindowwrapid').style.left = '-' + ((ui.position.left - 4) * 168 / 26 - 3) + 'px';
           document.getElementById ('dragtabswrapid').style.left = '-' + ((ui.position.left - 4) * 168 / 26 - 3) + 'px';
         },
         stop: function (e, ui) {
          moveToHour (Math.floor (ui.position.left / 28));
         }
        }
      );
      $("#dragchannelhandleid").draggable (
        {axis: 'y',
         drag: function (e, ui) {
           document.getElementById ('dragwindowwrapid').style.top = (-ui.position.top * 42 * channel_ids.length / 403) + 'px';
           document.getElementById ('iconswrapid').style.top = (-ui.position.top * 42 * channel_ids.length / 403) + 'px';
         },
         stop: function (e, ui) {
	   set_channels_y (ui.position.top * channel_ids.length * 42 / 403);
           fetchListings (saved_when);
         }
        }
      );
      $("#dragwindowwrapid").draggable (
        {drag: function (e, ui) {
           document.getElementById ('dragtabswrapid').style.left = (ui.position.left) + 'px';
           document.getElementById ('draghandleid').style.left = (-ui.position.left * 26 / 168 + 4) + 'px';
           document.getElementById ('draghandlemaskid').style.left = (-ui.position.left * 26 / 168 + 4) + 'px';
           document.getElementById ('iconswrapid').style.top = ui.position.top + 'px';
           document.getElementById ('dragchannelhandleid').style.top = (-ui.position.top * 403 / 42 / channel_ids.length) + 'px';
         },
         stop: function (e, ui) {
	   set_channels_y (-ui.position.top);   
           moveToHour (Math.floor (-ui.position.left / 168));
         }
        }
      );
    }
  );



