﻿(function($) {

    $(document).ready(function() {
        if ($.browser.msie & $.browser.version > 7) {
            $('.slide').css('opacity', '1');
            $('.slide').each(function() {
                var link = $(this).find('a').attr('href');
                $(this).click(function() {
                    document.location.href = link;
                });
                $(this).css('cursor', 'pointer');
            });
        }
        var validator = $("form").validate({
            errorPlacement: function(error, element) {
                $('.errorMsg').text(error[0].innerHTML);
            }
        });

        $.validator.addMethod('phone', function(value) {
        return /((^06((\s{0,1})|(\-{0,1}))[0-9]{8}$)|(^[0-9]{3,4}(\s{0,1}|\-{0,1})[0-9]{6,7}$)|(^\+{1}[0-9]{2}(\s{0,1}|\-{0,1})[0-9]{2,3}(\s{0,1}|\-{0,1})[0-9]{6,7}$))/.test(value);
        }, 'Ongeldig telefoonnummer');

        //        if (!($.browser.webkit)) {
        //            init();
        //        }
        $('a.youtube').fancybox({
            'type': 'swf'
        });
        $(window).bind('resize', function() {
            init();
        });


        $('.searchField').keydown(function(e) {

            var intKey = (window.Event) ? e.which : e.keyCode;
            if (intKey == 13) { //enter key
                doSearch();
                return false;
            }
        });
        $('.searchButton').click(function() {
            doSearch();
            return false;
        });
        //$('.submenu').height($('.content').height());


        /*$('.slide').hover(function(event) {
        $(this).animate({ width: '200px', height: '260px', paddingTop: '5px', marginTop: '0px' }, 600);
        $(this).children('.slideHeadImg').animate({width: '185px', height: '70px'});
        //$(this).stop().effect("scale", { percent: 120 }, 1000);
        }, function(event) {
        $(this).animate({ width: '160px', height: '208px', paddingTop: '4px', marginTop: '26px' }, 600);
        $(this).children('.slideHeadImg').animate({width: '148px', height: '56px'});
        //$(this).stop().effect("scale", { percent: 83 }, 1000);
        });*/

    });
})(jQuery);

function doSearch() {
    if ($('.searchField').val().length > 0) {
        if (window.location.host == 'www.wiseup.nl') {
            window.location = 'http://www.wiseup.nl/zoeken.aspx?q=' + $('.searchField').val();
        }
        else {
            var path = window.location.pathname.split('/');
            window.location = 'http://'+window.location.host+'/'+path[1] + '/zoeken.aspx?q=' + $('.searchField').val();
        }
    }
}

function slideShow() {
    $('.slide').hover(function() {
        $(this).css('z-index', '10');        
        $(this).animate({
            scaleX: 1.2,
            scaleY: 1.2
        }, 600);

    }, function() {
        $(this).animate({
            scaleX: 1,
            scaleY: 1
        }, 600).css('z-index', '1');
    });
}
function validatePhone(phone) {
    var re = /((^06((\s{0,1})|(\-{0,1}))[0-9]{8}$)|(^[0-9]{3,4}(\s{0,1}|\-{0,1})[0-9]{6,7}$)|(^\+{1}[0-9]{2}(\s{0,1}|\-{0,1})[0-9]{2,3}(\s{0,1}|\-{0,1})[0-9]{6,7}$))/;
    return re.test(phone);
}

function validateEmail(value) {
    var re = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    return re.test(value);
}

function validateForm() {
    $('input').removeClass('errorField');
    $('.errorMsg').text('');
    var valid = true;
    $('.required').each(function() {
        if ($(this).val() == '') {
            $(this).addClass('errorField');
            valid = false;            
        }
    });
    if (!valid) {
        $('.errorMsg').text('Verplicht veld');
        return false;
    }

    if (!(validatePhone($('.phone').val()))) {
        $('.phone').addClass('errorField');
        valid = false;
        $('.errorMsg').text('Ongeldig telefoonnummer');
    }
    if (!valid)
        return false;

    if (!(validateEmail($('.email').val()))) {
        $('.email').addClass('errorField');
        valid = false;
        $('.errorMsg').text('Ongeldig e-mailadres');
    }
    if (!valid)
        return false;

    return true;
}

function afterload() {
    //if ($.browser.webkit) {
        init();
    //}
}

function init() {
    $('.ytubeLayer').remove();
    $('a.youtube img').each(function() {
        var imgPos = $(this).offset();
        var theLink = $(this).parent().attr('href');
        $('.MasterWrapper').append('<div class="ytubeLayer" style="position:absolute; top:' + imgPos.top + 'px; left:' + imgPos.left + 'px;"><a href="' + theLink + '" class="youtube"><img src="http://test.v12.nl/wiseup84134/img/youtubeLayer.png" alt="" /></a></div>');
    });
    if ($('.content').height() > $('.submenu').height()) {
        $('.submenu').height($('.content').height());
    }
    
    $('a.youtube').fancybox({
        'type': 'swf'
    });
}


window.onload = afterload;


