var SEARCH_DEFAULT_TEXT = "Cerca le risposte alle tue domande";

$(document).ready(function() {
  // Functions called on page load
  $("#newsTicker").jCarouselLite({  
    vertical: true,
    hoverPause: true,
    visible: 3,  
    auto: 4000,  
    speed: 2500,
    scroll: 1
});

  $("#ecalogoTicker").jCarouselLite({  
    horizontal: true,
    hoverPause: true,
    visible: 1,  
    auto: 4000,  
    speed: 2500
});


  $("#dialogWindow").dialog({
      autoOpen: false,
      modal: true,
      resizable: false,
      width: 810,
      height: 590,
      close: function(event, ui) {
        checkTTSAutoplay();
        $("#dialogFrame").attr("src", "");
      }
  });

  $(".searchField").attr("rel", SEARCH_DEFAULT_TEXT).addDefaultText();

  $('#slider').s3Slider({ timeOut: 20000 });
  
});


function toggleRowHover(obj, hoverCssClass) {
  if ($(obj).hasClass(hoverCssClass)) {
    $(obj).removeClass(hoverCssClass);
  } else {
    $(obj).addClass(hoverCssClass);
  }
}

/**
 * TODO: Add comment
 *
**/
function TTSPlayPause() {
  if ($("#TTSPlayPause").hasClass("TTSPause")) {
    // This function is defined into the SitePal js
    // and included in <head> section of MainLayout.Master
    stopSpeech();
  }
  else
  {
    $("#TTSPlayPause").addClass("TTSPause").html("Interrompi");
    // This function is dinamically defined by Index.aspx.cs
    // or statically defined into Index.aspx
    startSpeech();
  }
}

function resetTTSPlayPause() {
  $("#TTSPlayPause").removeClass("TTSPause").html("Ascolta");
}

function hideTTSPlayPause() {
  $("#TTSPlayPause").hide();
  $("#TTSPlayPauseAlt").html("Audio non disponibile");
}

function showTTSControls() {
  $("#TTSControls").show();
}

/**
 * TODO: Add comment
 *
**/
function toggleTTSAutoplay() {
  if ($("#TTSAutoplay").hasClass("TTSAutoplay")) {
    $.post("WebServices/GetResourceContent.asmx/SetTTSAutoplay",
      {"value" : 0},
      function(data){
        if (data == 0) {
          $("#TTSAutoplay").removeClass("TTSAutoplay").html("Attiva l'audio automatico");
          $("#isTTSAutoplayEnabled").html("0");
        }
      }, "text");
  }
  else {
    $.post("WebServices/GetResourceContent.asmx/SetTTSAutoplay",
      {"value" : 1},
      function(data){
        if (data == 1) {
          $("#TTSAutoplay").addClass("TTSAutoplay").html("Disattiva l'audio automatico");
          $("#isTTSAutoplayEnabled").html("1");
        }
      }, "text");
  }
}

/**
 * TODO: Add comment
 *
**/
function checkTTSAutoplay() {
  $.post("WebServices/GetResourceContent.asmx/IsTTSAutoplayEnabled",
    {},
    function(data){
      if (data == 0) {
        $("#TTSAutoplay").removeClass("TTSAutoplay").html("Attiva l'audio automatico");
        $("#isTTSAutoplayEnabled").html("0");
      }
      else {
        $("#TTSAutoplay").addClass("TTSAutoplay").html("Disattiva l'audio automatico");
        $("#isTTSAutoplayEnabled").html("1");
      }
    }, "text");
}

/**
 * TODO: Add comment
 *
**/
function checkSearchString() {
  searchString = $(".searchField").val();
  if (searchString == "" || searchString == SEARCH_DEFAULT_TEXT) {
    return false;
  }
  return true;
}

/**
 * TODO: Add comment
 *
**/
function saveIdAndShowDialog(id, title) {
  $.post("WebServices/GetResourceContent.asmx/SaveId", { "id": id });

  $("#dialogWindow").dialog("option", "title", title).dialog("open");
  $("#dialogFrame").attr("src", "DialogFrame.html");
}

/**
 * TODO: Add comment
 *
**/
function saveClassificationAndShowDialog(classification, title) {
  $.post("WebServices/GetResourceContent.asmx/SaveClassification", { "classification": classification });

  $("#dialogWindow").dialog("option", "title", title).dialog("open");
  $("#dialogFrame").attr("src", "DialogFrame.html");
}

/**
 * TODO: Add comment
 *
**/
function printContent() {
  $("#cellControls").hide();
  $("#dynamicContent").jqprint()
  $("#cellControls").show();
}

function setRegion(region, url) {
  $.post("WebServices/GetResourceContent.asmx/SetRegion",
    { "region": region },
    function() {
      // Force current page reloading.
      window.location.href = window.location.href;
  });
}


function ViewContent(id) {

    window.location.href = 'QuestionPage.aspx?id=' + id
}


