$(function()
{
  $('.link_champs').click(function()
  {
    $id = $(this).attr("id");
   
    $('.div_hidden').css("display", "none");
    $id_div = '#div-'+$id;
    $($id_div).css("display", "block");
  });
  
	$(".datepicker").datepicker();

  var BASEURL = 'http://www.soldesetc.com/';
  
  $.easy.tooltip();
  $.easy.popup();
  $.easy.showhide();
  
  // confirm
  
  $('a[rel="delete"]').click(function()
  {
    return confirm('Êtes-vous sûr de vouloir supprimer cet item?');
  });
  
  $('#auth_form').css('z-index', 10000);
  $('.ads').css('z-index', 9000);
  
  // sign in
  
  $('#sign_in').click(function()
  {
    $('form[name="sign_in"]').slideToggle("fast");
    $(this).toggleClass("down");
  });
  
  // dropdown

  $('.dropdown a.down, .dropdown a.up').click(function()
  {
    $(this).parent().find('ul').slideToggle("fast");
    $(this).toggleClass('down');
    $(this).toggleClass('up');
  });

  // slideshow

  $("#slideshow").scrollable
  ({
    interval: 5000,
    loop: true,
    speed: 1000,
    size: 7,
    keyboard: false,
    easing: 'custom',
    next: '#partners .next a',
    prev: '#partners .previous a'
  });
  
  $("#other_ads").scrollable
  ({
    interval: 5000,
    loop: true,
    speed: 1000,
    size: 1,
    easing: 'custom'
  });

  $.easing.custom = function(x, t, b, c, d)
  {
    if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
    return c/2*((t-=2)*t*t*t*t + 2) + b;
  };

  // region picker
  
  function getCities(regionsSelect, citiesSelect)
  {
    var getJSON = false;

    citiesSelect.children('option[value!=""]').remove();

    if($(regionsSelect).val() != '')
    {
      getJSON = $.getJSON(BASEURL + 'location/cities/' + $(regionsSelect).val(), function(json)
      {
        if(json.length > 0)
        {
          citiesSelect.removeAttr('disabled');

          for(var i = 0; i < json.length; i++)
          {
            citiesSelect.append('<option value="' + json[i].id + '">' + json[i].name + '</option>');
          }
        }
      });
    }

    if(getJSON == false)
    {
      citiesSelect.attr('disabled', 'disabled');
    }
  }

  $('#region_id').change(function()
  {
    getCities(this, $('#city_id'));
  });
  
  // category picker
  
  function getCategories(supSelect, subSelect)
  {
    var getJSON = false;

    subSelect.children('option[value!=""]').remove();

    if($(supSelect).val() != '')
    {
      getJSON = $.getJSON(BASEURL + 'categories/get/' + $(supSelect).val(), function(json)
      {
        if(json.length > 0)
        {
          subSelect.removeAttr('disabled');

          for(var i = 0; i < json.length; i++)
          {
            subSelect.append('<option value="' + json[i].id + '">' + json[i].title + '</option>');
          }
        }
      });
    }

    if(getJSON == false)
    {
      subSelect.attr('disabled', 'disabled');
    }
  }

  $('#cat').change(function()
  {
    getCategories(this, $('#cat_id'));
  });
  
  // search
  
  $('#search_region_id').change(function()
  {
    if($(this).val() != '')
    {
      window.location = BASEURL + '?region=' + $(this).val();
    }
    else
    {
      window.location = BASEURL;
    }
    
    //$('#search_city_id').attr('disabled', 'disabled');
    //$(this).parents('form:first').submit();
  });
  
  $('#search_store').change(function()
  {
    if($(this).val() != '')
    {
      window.location = $(this).val();
    }
  });
  
  $('#search_city_id').change(function()
  {
    if($(this).val() != '')
    {
      window.location = BASEURL + '?region=' + $('#search_region_id').val() + '&city=' + $(this).val();
    }
    else
    {
      window.location = BASEURL + '?region=' + $('#search_region_id').val();
    }
  });

  // popup

  $('a.openPopup').click(function()
  {
    window.open($(this).attr('href'), 'popup', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=545,left=355,top=134');
    return false;
  });
  
  // reference
  
  $('#discover').change(function()
  {
    if($(this).val() == 'seller')
    {
      $('#refer_div').css('display', 'block');
      $('#reference').focus();
    }
    else
      $('#refer_div').css('display', 'none');
  });
  
  // datepicker
  
  $('.datepicker').datepicker(
  {
    defaultDate: new Date(),
    minDate: new Date(),
    dateFormat: 'dd-mm-yy'
  });
  
  // rating
  
  $('.rate').rating(
  {
    callback: function(value, link)
    {
      var form = $(this).parent('form[name="rating"]');
      $.get(form.attr('action') + value);
      form.find('input[type="radio"]').rating('readOnly', true);
    }
  });
  
  // categories slider
  
  $('#categories_slider').click(function()
  {
    $('#categories').slideDown('slow');
    $(this).hide();
  });
  
  // innactives
  
  $('#inactive').change(function()
  {
    if($(this).val() != '')
      window.location = $(this).val();
  });
});

var addthis_language = "fr";
