// -----------------------------------
// slideshow
// -----------------------------------

function slideSwitch() {
    var $active = $('#pimgs img.active');

    if ( $active.length == 0 ) $active = $('#pimgs img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#pimgs img:first');

    $active.addClass('last-active');
    
    $active.animate({opacity: 0.0}, 1000);
    
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}



// -----------------------------------
// labelToInput
// -----------------------------------
var labelToInput = {
	init: function() {
		$('.labelvalue').each(function(index, domElement){								
						$(this).css("display","none");	
						var txt = $(this).text();
						var chpsTxt = $(this).next(':text, :password');
							
							if(chpsTxt.attr('type') == "text") {
								chpsTxt.val(txt);
								chpsTxt.focus(function(e){if($(e.target).val() == txt) $(e.target).val('')});
								chpsTxt.blur(function(e){if($(e.target).val() == '') $(e.target).val(txt)});
							}
							if(chpsTxt.attr('type') == "password") {
								var newInput = $('<input type="text" />');
								$(newInput).attr('class',chpsTxt.attr('class'))
								$(newInput).attr('id',chpsTxt.attr('id'));
								//$(newInput).attr('name',chpsTxt.attr('name'))
								$(newInput).val(txt);
								
								var oldInput = chpsTxt.clone();
								$(chpsTxt).replaceWith(newInput);
								newInput.focus(function(e){ $(e.target).replaceWith(oldInput); oldInput.focus();});
								//oldInput.blur(function(e){  if($(e.target).val() == '') { $(e.target).replaceWith(newInput);}    });
							}

		});
	}
}


// -----------------------------------
// button rollover
// -----------------------------------

function btnRollover() {
   $(':image')
      .mouseover(function() {
         $(this).attr('src',$(this).attr('src').slice(0,-4) + '_on.png');
      })
      .mouseout (function() {
         $(this).attr('src',$(this).attr('src').replace('_on', ''));
      });
}


// -----------------------------------
// help balloon
// -----------------------------------

function help() {
   $('span.help img')
      .mouseover(function() {
         $(this).next('span').show();
      })
      .mouseout (function() {
         $(this).next('span').hide();
      });
}


// -----------------------------------
// toggle information blocks
// -----------------------------------

function toggleBlocks() {
   $('a.toggle').click(function() {
      $(this).parents('.informations_block').toggleClass('collapsed');
      return false;
   });
   $('a.extend_all').click(function() {
      $('.informations_block').removeClass('collapsed');
      return false;
   });   
   $('a.collapse_all').click(function() {
      $('.informations_block').addClass('collapsed');
      return false;
   });   
}

// -----------------------------------
// toggle devis perso
// -----------------------------------
function toggleDevis() {
  $(".toggle_container").hide();

	$(".trigger").toggle(function(){
		$(this).addClass("active"); 
		}, function () {
		$(this).removeClass("active");
	});
	
	$(".trigger").click(function(){
		$(this).next(".toggle_container").slideToggle("slow,");
	});
}
//--------------------------------------------------------------------------//

$(function() {
    setInterval( "slideSwitch()", 5000 );
    labelToInput.init();
    btnRollover();
    toggleBlocks();
    toggleDevis();
    help();
});

