// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function getElementsByName_iefix(tag, name) {
    
     var elem = document.getElementsByTagName(tag);
    
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {           
          att = elem[i].getAttribute("id");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function textLimit(field, maxlen) {
   if (field.value.length > maxlen) {
      field.value = field.value.substring(0, maxlen);
      alert('Vous avez atteint la longueur maximum pour votre saisie.');
   }
}


function refresh_elt(elt,message){
    if (elt.value == message) {
		elt.value = '';
	}
}

  function crop(img_id, crop_id, x, y, width, height, classname) {
    $(crop_id).update('<img id="' + crop_id + '_img" class="' + classname +'" src="' +
        $(img_id).getAttribute('src') + '" style="display:none" />');

    var scale_x = $(crop_id).getWidth() / width;
    var scale_y = $(crop_id).getHeight() / height;

    $(crop_id).setStyle({
      position: 'relative',
      overflow: 'hidden' 
    });

    $(crop_id + '_img').setStyle({
      position: 'absolute',
      display: 'block',
      left: (-x * scale_x) + 'px',
      top: (-y * scale_y) + 'px',
      width: ($(img_id).getWidth() * scale_x) + 'px',
      height: ($(img_id).getHeight() * scale_y) + 'px'
    });
  }

  function slideSwitch() {
    var $active = jQuery('#slideshow div.active');

    if ( $active.length == 0 ) $active = jQuery('#slideshow div:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : jQuery('#slideshow div:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
  }  
  