﻿(function ($) {
    window.Estepe = {
        boot: function () {
            if ($.browser.msie) {
                $('html').addClass('ie' + parseInt($.browser.version, 10));
            }
            this.fixWatermarks('watermark');
            this.fixSpecialFeatures();
            this.fixSubmenu();
            this.fixMoreTruckSolutions();
            this.fixHomeButtons();
            // this.fixBackground();
            this.fixMailPlusPosition();
            this.fixMailPlusPosition();
            $(window).resize(function () { window.Estepe.fixBackground(); window.Estepe.fixMailPlusPosition(); });
            $(window).bind('load', function () {
                //window.Estepe.fixMailPlusPosition();
            });
            //this.fixSwitchingImages();
        },
        fixWatermarks: function (inputClass) {
            $('input.' + inputClass).each(function () {
                var me = $(this);
                var watermarkText = me.attr('data-watermark');
                if (!watermarkText) {
                    watermarkText = me.val();
                }
                me.focus(function () {
                    if (me.val() == watermarkText) {
                        me.removeClass('watermark');
                        me.val('');
                    }
                });
                me.blur(function () {
                    if (me.val() == '') {
                        me.addClass('watermark');
                        me.val(watermarkText);
                    }
                });
            });
        },
        fixRouteButton: function () {
            $('div#routeButton a').click(function () {
                var addressField = $('input.txtAdres');
                var cityField = $('input.txtPlaats');
                var countryField = $('input.txtLand');
                if (addressField.val() == '' || addressField.val() == addressField.attr('data-watermark')) {
                    return;
                }
                if (cityField.val() == '' || cityField.val() == cityField.attr('data-watermark')) {
                    return;
                }
                if (countryField.val() == '' || countryField.val() == countryField.attr('data-watermark')) {
                    return;
                }

                var to = 'Cereslaan%2015%20Heesch';
                var url = 'http://maps.google.nl/?saddr=' + addressField.val() + '%20' + cityField.val() + '%20' + countryField.val() + '&daddr=' + to;
                window.open(url, 'mapWindow');
            });
        },
        fixSpecialFeatures: function () {
            $('div.featureContent').each(function () {
                var me = $(this);
                me.children('img.featureCircle').each(function () {
                    $(this).hover(function () {
                        me.children().each(function () {
                            $(this).show();
                        });
                        $(this).hide();
                    });
                });
                me.mouseleave(function () {
                    me.children().each(function () {
                        $(this).hide();
                    });
                    me.children('img.featureCircle').show();
                });
            });
        },
        fixSubmenu: function () { //Lijntje aan de rechterkant van het submenuitem links van het geselecteerde submenuitem verwijderen
            $('div#subMenu li.selected').prev().find('div.menuItemRight').css('background-image', 'none').css('width', '10px');
        },
        fixMoreTruckSolutions: function () { //Hele buttons klikbaar maken
            $('div#moreTruckSolutionsTop div.step').each(function () {
                var me = $(this);
                me.click(function () {
                    document.location.href = me.children('a').attr('href');
                });
            });
        },
        fixHomeButtons: function () {
            $('div.column').each(function () {
                var me = $(this);
                var href = $(this).find('div.columnLink a').attr('href');
                me.click(function () {
                    window.location = href;
                });
            });
        },
        fixBackground: function () {
            var winHeight = $(window).height();
            var siteHeight = $('div#site').height();
            if (winHeight > siteHeight) {
                $('body').height(winHeight);
            }
        },
        fixMailPlusPosition: function () {
            var mpForm = $('div.mailplusform');
            if (mpForm.length > 0) { 
                //var offset = ($(window).width() - 1015) / 2;
                var offset = $(".editableTextMailplus").offset().left;
                mpForm.css('left', offset);
                // fix the top position of labels, maiplusform en fotter
                var labelHeight = $('.editableTextMailplus').height();
                var formTop = parseInt(mpForm.css('top'));
                mpForm.css('top', (labelHeight + 230) + 'px');
                $('.mailplusFooterDiv').css('top', (mpForm.height() + 40) + 'px');
                //fix footer
                var contentHeight = $('#defaultContentPage').height();
                var heightFooter = $('.mailplusFooterDiv').height();
                var totaalHeight = labelHeight + mpForm.height() + heightFooter + 80;
                if (contentHeight < totaalHeight) {
                    $('#defaultContentPage').height(totaalHeight);
                }

                //fix the left position of header and footer, default form width is 235
                var formWidth = mpForm.width();
                //$('.editableTextMailplus').css('margin-left', (15 - (formWidth - 219)) + 'px');
                $('.mailplusFooterDiv').css('left', (15 - (formWidth - 219)) + 'px');
            }

            /*
            fixMailPlusPosition: function () {
            var mpForm = $('div.mailplusform');
            if (mpForm.length > 0) {
            //var offset = ($(window).width() - 1015) / 2;
            var offset = ($(window).width() - 860) / 2;
            //                mpForm.css('right', offset+15);
            mpForm.css('left', offset + 583);
            // fix the top position of labels, maiplusform en fotter
            var labelHeight = $('.editableTextMailplus').height();
            var formTop = parseInt(mpForm.css('top'));
            mpForm.css('top', (labelHeight + 230) + 'px');
            $('.mailplusFooterDiv').css('top', (mpForm.height() + 40) + 'px');
            //fix footer
            var contentHeight = $('#defaultContentPage').height();
            var heightFooter = $('.mailplusFooterDiv').height();
            var totaalHeight = labelHeight + mpForm.height() + heightFooter + 80;
            if (contentHeight < totaalHeight) {
            $('#defaultContentPage').height(totaalHeight);
            }

            //fix the left position of header and footer, default form width is 235
            var formWidth = mpForm.width();
            //$('.editableTextMailplus').css('margin-left', (15 - (formWidth - 219)) + 'px');
            $('.mailplusFooterDiv').css('left', (15 - (formWidth - 219)) + 'px');
            }
            */

        },
        doBgFix: function () {
        }
    };
})(jQuery);

var fadeTime = 1000;
var waitTime = 3000;


$(window).load(function () {
    $(".fotoAlbumThumb1 img, .fotoAlbumThumb2 img, .fotoAlbumThumb3 img ").each(function () {
        verticalCenterImage(this);
    });
}); 

$(document).ready(function () {
    $('div.switchingImagesInner').each(function () {
        var me = $(this);
        var id = me.attr('id');
        var count = me.find('img').length;
        var current = 1;
        if (count < 3)
            return; //Niks om te sliden (bij 0 of 2 afbeeldingen, als het er 2 zijn zijn het 2 dezelfde)

        doneSlide(id, count, current); //Bij laden laten staan op eerste plaatje

    });



});


function verticalCenterImage(el) {

    var jq = $(el);

    var marginTop = ((jq.parent().parent().height() - jq.height()) / 2);
    jq.css('margin-top', marginTop + "px");
}

function startSlide(id, count, current) {
    var container = $('div#' + id);

    if (current == count) {
        current = 1;
        container.css('left', '0');
    }

    var left = current * -147;
    current++;
    
    $('div#' + id).animate({ left: left }, 2000, function() { doneSlide(id, count, current); });
}

function doneSlide(id, count, current) {
    setTimeout("startSlide('" + id + "', " + count + ", " + current + ");", 10000);
}

