
$(function(){      
    topnav2height = $('#topnav2').height();
    ctrheight = $('#ctright_overig').height() - 221; // 371 - 150
    ctlheight = $('#ctleft').height() + 60;
              
    if(ctrheight == "-221"){
        ctrheight = $('#ctright').height() + 30;
        
        $('#ctleft').css('margin-top', 221); 
        ctltop = $('#ctleft').css('margin-top');
    
        if(ctlheight > ctrheight){
            $('#inner').css('height', ctlheight);           
        }else{                                   
            $('#inner').css('height', ctrheight);               
        }
            
    } else {      
        $('#ctleft').css('margin-top', topnav2height); 
        ctltop = $('#ctleft').css('margin-top');
                                                        
        if(ctlheight > ctrheight){
            $('#inner').css('height', ctlheight);           
        }else{                                   
            $('#inner').css('height', ctrheight);               
        }        
    }                       
});


/** target attribute is not allowed when using xhtml */
$(function(){
   $('#footer a').attr('target','_blank');
   $('a.target-blank').each(function(key, value){
        $(value).attr('target','_blank');  
   }); 
}); 

$(window).bind("load", function() { 
    var sponsorImages = $('.sponsorOverview img');
    if(sponsorImages.size() > 0) {
        sponsorImages.each(function(key, value) {
            value = $(value);
            value.css('margin-top',(80-value.attr('height'))/2);
        });
    }
});  

// SCROLLER

var numShow             = 2;    
var subSponsorsWrapper  = null;
var subSponsors         = null;
var sponsors            = null;
var max_height          = null;
var original_ul         = null;

$(window).bind("load", function() {  
    subSponsorsWrapper  = $('#subSponsorsWrapper');
    subSponsors         = $('#subSponsors');
    sponsors            = subSponsors.children();
    max_height          = subSponsors.height();

    subSponsors.append(subSponsors.html());
    animateReady();
});

function animateReady(marginTop) {
    if(!marginTop) marginTop = 0;

    subSponsors.css('margin-top',marginTop);
    
    subSponsors.animate(
    {
        marginTop: -max_height
     }, sponsors.size()*3000, 'linear', function() { animateReady() }
     );     
}

//Foto's in Gallery'
$(function(){
   $('.gallerypic').fancybox( {
        'transitionIn'	:	'elastic',
	'transitionOut'	:	'elastic',
	'speedIn'	:	600,
	'speedOut'	:	200,
	'overlayShow'	:	true

   });

});

//Live ticker fancy box
$(function(){
   //console.log ($('a[name=tickerbox]'));
   $('a[name=tickerbox]').fancybox( {
            frameWidth: 460,
            frameHeight: 600,
            overlayShow: true,
            centerOnScroll: false,
            hideOnContentClick: false
   }

   );
       
});

//promo film fancy box
$(function(){
   //console.log ($('a[name=tickerbox]'));
   $('a[name=fancy-movie]').fancybox( {
            frameWidth: 550,
            frameHeight: 505,
            padding: 25,
            overlayShow: true,
            centerOnScroll: false,
            hideOnContentClick: false
   }

   );
       
});

$(document).ready(function(){
    var $_location = window.location.pathname ;
    var $_parts = $_location.split("/");

    if ($_parts[1] == "aanmelden-prominenten-rit"){
        //formchecks
//        $('form#ritinschrijving').validate({
//            rules: {
//                naam : "required",
//                voorletters : "required",
//                adres : "required",
//                postcode : "required",
//                woonplaats : "required",
//                geboortedatum : "required",
//                email : {required:true, email:true}
//            },
//            url: {url:true},
//            comment: { required: true },
//            messages: { comment: "Verplicht in te vullen!"  }
//        });

        $('form#ritinschrijving').submit(function(){

            var $_succes = "true";

            var $_name = $('input[name=naam]').val();
            var $_intials = $('input[name=voorletters]').val();
            var $_adres = $('input[name=adres]').val();
            var $_post = $('input[name=postcode]').val();
            var $_plaats = $('input[name=woonplaats]').val();
            var $_dob = $('input[name=geboortedatum]').val();
            var $_mail = $('input[name=email]').val();

//            console.log("form was submitted...");
//            console.log($_name);
//            console.log($_mail);
            
            if($_name == ""){
                $('input[name=naam]').css('border','1px solid red');
                $_succes = "false";
                return false;
            }
           
            if($_mail == ""){
                $('input[name=email]').css('border','1px solid red');
                $_succes = "false";
                return false;
            }

            //console.log($_succes);
            return $_succes;
        
        });

    }

});

