$(document).ready(function () {


    $('.news-fancy').fancybox({
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'fade',
        'speedIn'		:	600,
        'speedOut'		:	200,
        'easingIn'      : 'easeOutBack',
        'overlayShow'	:	true
    });


    //windows contact button padding fix
    /*
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

if(OSName == 'Windows')
    {
        $('#form_main a#submit').css('padding-top','4px');
    }

     */

    var counter = 1;
    $('#bt1').css('z-index','10');

    // $('.top-sub-menu').toggle();

    $(window).load(function() {
        $('.home-banner .slider').nivoSlider({
            effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
            slices:15,
            animSpeed:500, //Slide transition speed
            pauseTime:7000,
            startSlide:0, //Set starting Slide (0 index)
            directionNav:false, //Next & Prev
            directionNavHide:false, //Only show on hover
            controlNav:true, //1,2,3...
            controlNavThumbs:false, //Use thumbnails for Control Nav
            controlNavThumbsFromRel:false, //Use image rel for thumbs
            controlNavThumbsSearch: '.jpg', //Replace this with...
            controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
            keyboardNav:true, //Use left & right arrows
            pauseOnHover:true, //Stop animation while hovering
            manualAdvance:false, //Force manual transitions
            captionOpacity:0.8, //Universal caption opacity
            beforeChange: function()
            {
            },
            afterChange: function()
            {
                            changeBannerText();
            },
            slideshowEnd: function(){}, //Triggers after all slides have been shown
            lastSlide: function(){}, //Triggers when last slide is shown
            afterLoad: function(){} //Triggers when slider has loaded
        });
    });



    function changeBannerText()
    {
        counter++;
        //alert('change');
        var ilosc = $('.slider .nivo-controlNav').children().length;
        ilosc++;
        if(counter == ilosc)
        {
            counter = 1;
        }

        $('.banner-text').css('z-index','0');
        $('#bt' + counter).css('z-index','10');
    }


////////////////CLICK
    $('.slider .nivo-controlNav a').live('click',function(){

       //alert('clicked');
       var _nr = $(this).attr('rel');
       counter = _nr;

    });


    //////TOP SUB MENU

    $('.top-li-sub').bind('mouseover',function(){

        $(this).css('background', 'white');
        $(this).css('-moz-box-shadow', '1px 1px 2px #888');
        $(this).css('-webkit-box-shadow', '1px 1px 2px #888');
        $(this).css('box-shadow', '1px 1px 2px #888');
        $('.top-sub-menu').show();
        
    })

    $('.top-li-sub').bind('mouseout',function(){

        $(this).css('background', 'none');
        $(this).css('-moz-box-shadow', 'none');
        $(this).css('-webkit-box-shadow', 'none');
        $(this).css('box-shadow', 'none');
        $('.top-sub-menu').hide();

    })

    $('.top-li-sub').children().bind('mouseover',function(){

        $('.top-sub-menu').show();

    })

    $('.top-li-sub').children().bind('mouseout',function(){

        $('.top-sub-menu').show();

    })



    $('.top-sub-menu li').bind('mouseover',function(){
        $(this).show();
    })

    $('.top-sub-menu li').bind('mouseout',function(){
        $(this).show();
    })

    $('.sub-list li').bind('mouseover',function(){
        $('.top-sub-menu').show();
    })

    $('.sub-list li').bind('mouseout',function(){
        $('.top-sub-menu').show();
    })



    //////RIGHT-MENU
    $('.right-menu li').last().css('border', 'none');
   /* $('.right-menu li').bind('mouseover',function(){
        $(this).css('background','#e5f0f5');
    });
    $('.right-menu li').bind('mouseout',function(){
        $(this).css('background','none');
    });
     */

            
    //////////////////////////////////////// FORM ONCLICK

    $('input, textarea').click(function() {
        if ( $(this).attr('type') != 'submit'  )
            $(this).val("");
    });

    var products = $('.product-list').children('.product');

    var i = 0;
    $(products).each(function ()
    {
        i++;
        if(i%4 == 0)
        {
            $(this).css('margin-right','0px')
        }

    });
 

    ////// NEWS PAGE COLUMNS HEIGHT
    /*
    if($('.subpage-content .column-right-news').height() > $('.subpage-content .column').height())
    {
        $('.subpage-content .sub-content-text').height($('.subpage-content .column-right-news').height());
        $('.subpage-content .column').height($('.subpage-content .column-right-news').height());
    }
     */
    //// NIEUWS LAST LI BORDER

    $('.news-list-right').children('li').last().css('border-bottom','none');


    //////////////////// COLUMNs_HEIGHT
    
        /*
    $('.news li').last().css('border-bottom','none');

    $('.content .column').height($('.news_list').height()- 2);
    $('.sub_content .column').height($('.sub_content .grid_6').height()- 2);

    if($('.subpage-content .column').height() < $('.subpage-content .sub-content-text').height())
    {
        $('.subpage-content .column').height($('.subpage-content .sub-content-text').height()- 2);
    }
    else
    {
        $('.subpage-content .sub-content-text').height($('.subpage-content .column').height()- 2);
    }
     */


    $(window).load(function() {
        $('.content').children().not('.clear, .people_outer').height($('.content').height());
        $('.sub_content').children().not('.clear, .people_outer').height($('.sub_content').height());
        $('.content .column').height($('.people_outer').height());


        if($('.content').children('.news_list'))
            {
                $('.column').not('.column_ft').height($('.news_list').height() - 20 );
            }

         if ($('.content .column').height() < 185)
            {
               $('.content .column').height(185);
            }


            $('.img-wrap').width($('.img-wrap img').last().width());
            $('.img-wrap').height($('.img-wrap img').last().height());

    });
    //// NEWS PHOTO ZOOM

    $('.news-img-overlay .loop').toggle();
    $('.news-img-overlay .news-fancy').mouseover( function(){
        $('.news-img-overlay .loop').toggle();
    });
    $('.news-img-overlay .news-fancy').mouseout( function(){
        $('.news-img-overlay .loop').toggle();
    });

    /// CONTACT BORDER
    $('#form_main').parent().css('border-right','1px solid #e6e6e6');
    $('#form_main').parent().css('padding-right','10px');


    // FORM VALIDATION



    ///////////// SEND FORM

    $('#form_main #submit').bind('click',function(){
        send_form();
    });


    function IsEmailCorrect(email) {
        return email.match(/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$/)!=null;
    }

    function IsEmpty(pole) {
        if (pole=='')
            return true
        else
            return false
    }


    function send_form() {
        var status = true;

        $("#form_main .required").parent().children('input').each(function () {

            $(this).removeClass('red-border');
            if (IsEmpty($(this).attr('value')) ) {
                status = false;

                $(this).addClass('red-border');

            }
        });

        if(!status)
        {
            alert('Vul alstublieft de verplichte velden in');
        }


        $("#form_main .required_email").each(function () {

            $(this).removeClass('red-border');

            if (!IsEmailCorrect($(this).attr('value')) ) {
                alert('Vul een geldig e-mailadres in');
                status = false;
                $(this).addClass('red-border');

            }
        });

        if ( status ) {
            document.getElementById('form_main').submit();
        }

    }



});
