var sub = 0;

function menuMouseOver(el) {
    el.childNodes[1].style.visibility = 'visible';
}

function menuMouseOut(el) {
    el.childNodes[1].style.visibility = 'hidden';
}

function startscrollleft() {
window.intervalId = window.setInterval(moveleft,10);
}

function startscrollright() {
window.intervalId = window.setInterval(moveright,10);
}

function moveleft()
{
var marginnow = parseInt($("scrollersubcontainer").style.marginLeft);
if (marginnow < 0)
    $("scrollersubcontainer").style.marginLeft = marginnow +1 + "px";
}

function moveright()
{  
    var marginnow = parseInt($("scrollersubcontainer").style.marginLeft);  
    var maxmargin = 0 - sub['width'] + 450 ;
    if (marginnow > maxmargin)
      $("scrollersubcontainer").style.marginLeft = marginnow - 1 + "px";  
    
}

function stopscroll() {
clearInterval(window.intervalId);
}

function position()
{
  if($("scrollersubcontainer"))
      sub = $("scrollersubcontainer").getDimensions();
var height = document.viewport.getHeight();
margintop = ((height - $("positioner").getHeight()) / 2);
if (margintop < 0) margintop = 0;

$("positioner").style.marginTop =  margintop + "px";
}

function startscrollleft2() {
window.intervalId2 = window.setInterval(moveleft2,10);
}

function startscrollright2() {
window.intervalId2 = window.setInterval(moveright2,10);
}

function moveleft2()
{
var marginnow = parseInt($("scroller2subcontainer").style.marginLeft);
if (marginnow < 0)
$("scroller2subcontainer").style.marginLeft = marginnow +1 + "px";
}

function moveright2()
{
var marginnow = parseInt($("scroller2subcontainer").style.marginLeft);
if (marginnow > 0-(parseInt($("scroller2subcontainer").getWidth())-255))
$("scroller2subcontainer").style.marginLeft = marginnow -1 + "px";
}

function stopscroll2() {
clearInterval(window.intervalId2);
}

function initDealerFade()
{
    Effect.Fade($('magazine'), {
      duration: 3.0,
      afterFinish: function(effect) {
      }
    });
    Effect.Appear($('dealerMagazine'), {
      duration: 3.0,
      afterFinish: function(effect) {
      }
    });
}

function showMagazine() {
    $('magazineIFrame').setOpacity(0);
    $('magazineBackground').setOpacity(0);
    $('magazineContainer').show();
    $('magazineIFrame').src = "/flashmagazine";
    new Effect.Parallel( [
        new Effect.Opacity( 'magazineIFrame', { sync: true, from: 0, to: 1 } ),
        new Effect.Opacity( 'magazineBackground', { sync: true, from: 0, to: 0.7 } )
    ] );
}

function AppearOverlay(element) {
        element.setOpacity(0);
        element.style.visibility='visible';
        new Effect.Opacity( element, { from: 0, to: 1 } );
}

function hideMagazine() {
    new Effect.Parallel( [
        new Effect.Opacity( 'magazineIFrame', { sync: true, from: 1, to: 0 } ),
        new Effect.Opacity( 'magazineBackground', { sync: true, from: 0.7, to: 0 } )
    ], { afterFinish: function() { $('magazineContainer').hide(); } } );
}

function hideDrowndownTips() {
    $('dropdowntips').style.display = 'none';
    $('tipson').style.visibility='hidden';
    $('menborder5on').style.visibility='hidden';
    $('menborder6on').style.visibility='hidden';
}

function showForm(b) {
    activeForm = b;
    for( var n = 1; n <= 3; n++ ) {
        if( n == b )
            $('formBox'+n).show().setOpacity(0);
        else
            $('formBox'+n).hide();
    }
    $('formBackground').setOpacity(0);
    $('formContainer').show();
    new Effect.Parallel( [
        new Effect.Opacity( 'formBox'+b, { sync: true, from: 0, to: 1 } ),
        new Effect.Opacity( 'formBackground', { sync: true, from: 0, to: 0.7 } )
    ] );
}

function hideForm() {
    new Effect.Parallel( [
        new Effect.Opacity( 'formBox'+activeForm, { sync: true, from: 1, to: 0 } ),
        new Effect.Opacity( 'formBackground', { sync: true, from: 0.7, to: 0 } )
    ], { afterFinish: function() { $('formContainer').hide(); } } );
}

function sendForm(b) {
    var inputs = $('formEl'+b).getInputs();

    for( var n = 0; n < inputs.length; n++ ) {
        if( inputs[n].getAttribute('required') && !inputs[n].present() ) {
            alert( 'U heeft een verplicht veld niet ingevuld' );
            inputs[n].activate();
            return;
        }
    }

    new Ajax.Request( '/-1/phpblock/formbackend?formid='+b, {
        method: 'post',
        parameters: $('formEl'+b).serialize(),
        onComplete: function( trans ) {
            alert( 'Bedankt voor uw inzending!' );
            hideForm();
        }
    } );
}


