// -----------------------------------
// 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');
//        });
//}

function slideSwitch() {
    var $active = $('#pimgs div.active');
    var $imgactive = $('#pimgs img.active');

    if ($active.length == 0) $active = $('#pimgs div:last');
    if ($imgactive.length == 0) $imgactive = $('#pimgs img:last');

    var $next = $active.next().length ? $active.next()
        : $('#pimgs div:first');

    var $imgnext = $imgactive.next().length ? $imgactive.next()
        : $('#pimgs img:first');

    $active.addClass('last-active');
    $imgactive.addClass('last-active');

    $active.animate({ opacity: 0.0 }, 1000);
    $imgactive.animate({ opacity: 0.0 }, 1000);

    $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
            $active.removeClass('active last-active');
        });
    $imgnext.css({ opacity: 0.0 })
    .addClass('active')
    .animate({ opacity: 1.0 }, 1000, function() {
        $imgactive.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() {
          if ($(this).attr('src').slice($(this).attr('src').length - 7, $(this).attr('src').length) != '_on.png') {
              $(this).attr('src', $(this).attr('src').slice(0, -4) + '_on.png');
          }

      })
      .mouseout(function() {
      if ($(this).attr('src').slice($(this).attr('src').length - 7, $(this).attr('src').length) == '_on.png') {
              $(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();
      });
}


function help2() {
    $('span.help2 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,");
    });
}
//--------------------------------------------------------------------------//
// -----------------------------------
// accordion
// -----------------------------------
function Accordion() {
   $('.accordionElem .pointer').click(function(){ 
   		$(this).toggleClass('pointer-expanded');
   		$(this).parent().find('.dd-content').slideToggle();
   		return false;
   		
   });
}
//--------------------------------------------------------------------------/
$(function() {
    setInterval("slideSwitch()", 5000);
    labelToInput.init();
    btnRollover();
    toggleBlocks();
    toggleDevis();
    help();
    help2();
	Accordion();
});


