  var scrollableStart = 1;
  var scrollableDir = 0;
  
  $(document).ready(function() {
    if($('#scrollableContent').text()) {
      $('a#scrollablePrev').click(function() {
        scrollPrev();
      });
      $('a#scrollableNext').click(function() {
        scrollNext();
      });
      getArticoliScroll($('#scrollableCurrentSection').val(),scrollableStart);
    }
  });
  
  function getTest() {
    var step = $('#testStep').val();
    var answer = $("input[@name='answer']:checked").val();
    var current = $('#testCurrent').val();
    
    if (answer != undefined) {
      // if (confirm (step + " " + answer + " " + current)) {
        $('#formTest').load('/it/_dynamic/get_test.php?step=' + step + '&answer=' + answer + '&current=' + current + '&','');
      // }
    }
  }
  
  function switchConsigli(id) {
    $('div[id^=consiglio]:visible').fadeOut(300,function () {
      showConsigli(id);
    });
  }
  
  function showConsigli(id) {
    $('#consiglio' + id).fadeIn(500);
  }
  
  function scrollNext() {
    // alert ("next");
    scrollableStart = scrollableStart + 4;
    getArticoliScroll($('#scrollableCurrentSection').val(),scrollableStart);
  }
  
  function scrollPrev() {
    // alert ("prev");  
    if (scrollableStart > 1) {
      scrollableStart = scrollableStart - 4;
      getArticoliScroll($('#scrollableCurrentSection').val(),scrollableStart);
    }
  }
    
  function getArticoliScroll(categoria,start) {
    // alert ("getArticoliScroll");
    $.get('/it/_dynamic/get_articoli_scroll.php?categoria=' + escape(categoria) + "&start=" + start,"",scrollNewContent);
  }
  
  function scrollNewContent(responseText, textStatus, XMLHttpRequest) {
    // alert("scrollNewContent");
    if (responseText != "KO") {
      $('#scrollableContent .items').fadeOut(300,function () {
        showNewContent(responseText);
      });
    } else {
      scrollableStart = scrollableStart - 4;
    }
  }
  
  function showNewContent(responseText) {
    // alert ("showNewContent");
    $('#scrollableContent .items').html(responseText).fadeIn(500);
  }

  function lnkRedirect(strLink){
   	location.href = strLink;
  }
  
  function getArticoli(categoria,current_id,start) {
    $('#listaArticoli').load('/it/_dynamic/get_articoli.php?categoria=' + escape(categoria) + "&current_id=" + escape(current_id) + "&start=" + start);
  }
  
  function saveemail() {
    var email = $('#email').val();
    if (!testEmail(email,true)) {
      alert("Email non valida.");
    } else {      
      txtCont = "http://nl.nowloading.nl/stubs/galbuseraframe.php?k=" + escape(email);
      Shadowbox.open({
        player:     'iframe',
        title:      'Newsletter',
        content:    txtCont,
        height:     235,
        width:      320
      });
    }
  }
  
  function testEmail(oggTextfield, boolObbligatorio) {
    oggTextfield = oggTextfield.replace(/\s+$|^\s+/g,"")
    if (oggTextfield == "")
      if (boolObbligatorio)
        return false
      else
        return true
      var rex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      var risultato = rex.test(oggTextfield);
      return risultato
  }
  
  function showPage(id) {
    $('.paginazione').hide();
    $('#p' + id).show();
  }
