﻿/**
* jQuery-Plugin "preloadCssImages"
* by Scott Jehl, scott@filamentgroup.com
* http://www.filamentgroup.com
* reference article: http://www.filamentgroup.com/lab/update_automatically_preload_images_from_css_with_jquery/
* demo page: http://www.filamentgroup.com/examples/preloadImages/index_v2.php
* 
* Copyright (c) 2008 Filament Group, Inc
* Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
*
* Version: 5.0, 10.31.2008
* Changelog:
* 	02.20.2008 initial Version 1.0
*    06.04.2008 Version 2.0 : removed need for any passed arguments. Images load from any and all directories.
*    06.21.2008 Version 3.0 : Added options for loading status. Fixed IE abs image path bug (thanks Sam Pohlenz).
*    07.24.2008 Version 4.0 : Added support for @imported CSS (credit: http://marcarea.com/). Fixed support in Opera as well. 
*    10.31.2008 Version: 5.0 : Many feature and performance enhancements from trixta
* --------------------------------------------------------------------
*/

; jQuery.preloadCssImages = function(settings) {
    settings = jQuery.extend({
        statusTextEl: null,
        statusBarEl: null,
        errorDelay: 999, // handles 404-Errors in IE
        simultaneousCacheLoading: 2
    }, settings);
    var allImgs = [],
		loaded = 0,
		imgUrls = [],
		thisSheetRules,
		errorTimer;

    function onImgComplete() {
        clearTimeout(errorTimer);
        if (imgUrls && imgUrls.length && imgUrls[loaded]) {
            loaded++;
            if (settings.statusTextEl) {
                var nowloading = (imgUrls[loaded]) ?
					'Now Loading: <span>' + imgUrls[loaded].split('/')[imgUrls[loaded].split('/').length - 1] :
					'Loading complete'; // wrong status-text bug fixed
                jQuery(settings.statusTextEl).html('<span class="numLoaded">' + loaded + '</span> of <span class="numTotal">' + imgUrls.length + '</span> loaded (<span class="percentLoaded">' + (loaded / imgUrls.length * 100).toFixed(0) + '%</span>) <span class="currentImg">' + nowloading + '</span></span>');
            }
            if (settings.statusBarEl) {
                var barWidth = jQuery(settings.statusBarEl).width();
                jQuery(settings.statusBarEl).css('background-position', -(barWidth - (barWidth * loaded / imgUrls.length).toFixed(0)) + 'px 50%');
            }
            loadImgs();
        }
    }

    function loadImgs() {
        //only load 1 image at the same time / most browsers can only handle 2 http requests, 1 should remain for user-interaction (Ajax, other images, normal page requests...)
        // otherwise set simultaneousCacheLoading to a higher number for simultaneous downloads
        if (imgUrls && imgUrls.length && imgUrls[loaded]) {
            var img = new Image(); //new img obj
            img.src = imgUrls[loaded]; //set src either absolute or rel to css dir
            if (!img.complete) {
                jQuery(img).bind('error load onreadystatechange', onImgComplete);
            } else {
                onImgComplete();
            }
            errorTimer = setTimeout(onImgComplete, settings.errorDelay); // handles 404-Errors in IE
        }
    }

    function parseCSS(sheets, urls) {
        var w3cImport = false,
			imported = [],
			importedSrc = [],
			baseURL;
        var sheetIndex = sheets.length;
        while (sheetIndex--) {//loop through each stylesheet

            var cssPile = ''; //create large string of all css rules in sheet

            if (urls && urls[sheetIndex]) {
                baseURL = urls[sheetIndex];
            } else {
                var csshref = (sheets[sheetIndex].href) ? sheets[sheetIndex].href : 'window.location.href';
                var baseURLarr = csshref.split('/'); //split href at / to make array
                baseURLarr.pop(); //remove file path from baseURL array
                baseURL = baseURLarr.join('/'); //create base url for the images in this sheet (css file's dir)
                if (baseURL) {
                    baseURL += '/'; //tack on a / if needed
                }
            }
            if (sheets[sheetIndex].cssRules || sheets[sheetIndex].rules) {
                thisSheetRules = (sheets[sheetIndex].cssRules) ? //->>> http://www.quirksmode.org/dom/w3c_css.html
					sheets[sheetIndex].cssRules : //w3
					sheets[sheetIndex].rules; //ie 
                var ruleIndex = thisSheetRules.length;
                while (ruleIndex--) {
                    if (thisSheetRules[ruleIndex].style && thisSheetRules[ruleIndex].style.cssText) {
                        var text = thisSheetRules[ruleIndex].style.cssText;
                        if (text.toLowerCase().indexOf('url') != -1) { // only add rules to the string if you can assume, to find an image, speed improvement
                            cssPile += text; // thisSheetRules[ruleIndex].style.cssText instead of thisSheetRules[ruleIndex].cssText is a huge speed improvement
                        }
                    } else if (thisSheetRules[ruleIndex].styleSheet) {
                        imported.push(thisSheetRules[ruleIndex].styleSheet);
                        w3cImport = true;
                    }

                }
            }
            //parse cssPile for image urls
            var tmpImage = cssPile.match(/[^\("]+\.(gif|jpg|jpeg|png)/g); //reg ex to get a string of between a "(" and a ".filename" / '"' for opera-bugfix
            if (tmpImage) {
                var i = tmpImage.length;
                while (i--) { // handle baseUrl here for multiple stylesheets in different folders bug
                    var imgSrc = (tmpImage[i].charAt(0) == '/' || tmpImage[i].match('://')) ? // protocol-bug fixed
						tmpImage[i] :
						baseURL + tmpImage[i];

                    if (jQuery.inArray(imgSrc, imgUrls) == -1) {
                        imgUrls.push(imgSrc);
                    }
                }
            }

            if (!w3cImport && sheets[sheetIndex].imports && sheets[sheetIndex].imports.length) {
                for (var iImport = 0, importLen = sheets[sheetIndex].imports.length; iImport < importLen; iImport++) {
                    var iHref = sheets[sheetIndex].imports[iImport].href;
                    iHref = iHref.split('/');
                    iHref.pop();
                    iHref = iHref.join('/');
                    if (iHref) {
                        iHref += '/'; //tack on a / if needed
                    }
                    var iSrc = (iHref.charAt(0) == '/' || iHref.match('://')) ? // protocol-bug fixed
						iHref :
						baseURL + iHref;

                    importedSrc.push(iSrc);
                    imported.push(sheets[sheetIndex].imports[iImport]);
                }


            }
        } //loop
        if (imported.length) {
            parseCSS(imported, importedSrc);
            return false;
        }
        var downloads = settings.simultaneousCacheLoading;
        while (downloads--) {
            setTimeout(loadImgs, downloads);
        }
    }
    parseCSS(document.styleSheets);
    return imgUrls;
};

$(function() {
    $('#navigation li')
    .find('a[href]')
    .append('<span class="hover" />')
    .each(function() {
        var $span = $('> span.hover', this).css('opacity', 0)
        $(this).hover(function() {
            $span.stop().fadeTo(500, 1)
        },
        function() {
            $span.stop().fadeTo(500, 0)
        })
    })
})

$(document).ready(function() {
    if ($.browser.msie && $.browser.version < 7) {
        alert('Voor deze website heeft u Internet Explorer 7 of hoger nodig!')
    }
    if ($.browser.msie && $.browser.version == 7) {
        //  Bug tekstblokken
        $('.tekstblokken').css("margin", "0px")
    }
    //  Creëer de 'target="_blank"' attributes van de externe links (voor de XHTML 1.0 Strict validatie)
    $('a.target_blank').attr('target', '_blank')

    if ($('div.boekjes').length != 0) {

    }
    //  Preload alle achtergrondafbeeldingen
    $.preloadCssImages();
    // T.b.v. Google Analytics
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-17777777-1']);
    _gaq.push(['_trackPageview']);
    (function() {
        var ga = document.createElement('script');
        ga.type = 'text/javascript';
        ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(ga, s);
    })();
})

function draaien() {
    for (teller = 0; teller < 100; teller++) {
        for (pagina = 0; pagina < 3; pagina++) {
            $('.gordijn')
                .delay(2500)
                .fadeTo(500, 0)
                .animate({left: '-=336px'})
                .fadeTo(500, 1)
                .delay(2500)
        }
        $('.gordijn').delay(2500).fadeTo(500, 0).animate({ left: '0' }).fadeTo(500, 1).delay(2500)
    }
}

$(function() {
    $('a.inkijk_italie')
        .click(function() {
            $('#overzicht_boekjes').hide()
            $('div.inkijk_italie').show()
            draaien();
        })
})

$(function() {
    $('a.inkijk_frankrijk')
        .click(function() {
            $('#overzicht_boekjes').hide()
            $('div.inkijk_frankrijk').show()
            draaien();
        })
})

$(function() {
    $('a.inkijk_oostenrijk')
    .click(function() {
        $('#overzicht_boekjes').hide()
        $('div.inkijk_oostenrijk').show()
        draaien();
    })
})

$(function() {
    $('span.naar_de_boekjes')
        .click(function() {
            $('div.inkijk_italie').hide()
            $('div.inkijk_frankrijk').hide()
            $('div.inkijk_oostenrijk').hide()
            $('#overzicht_boekjes').show()
        })
})

$(function() {
    $('#bt_inschrijven')
        .click(function() {
            $('#nieuwsbriefformulier').validate({
                rules: {
                    tb_email: {
                        required: true,
                        email: true
                    }
                },
                messages: {
                    tb_email: {
                        required: "* Verplicht veld",
                        email: "* Verplicht veld"
                    }
                }
            })
        }
    )
})

var aantal_italie;
var aantal_frankrijk;
var aantal_oostenrijk;
var standaard = 0;
var aantal_totaal;
var subtotaal;
var totaal;

$(function() {
$('.product input').keyup(function() {
        aantal_italie = $('#tb_aantal_italie').val()
        if (aantal_italie == '') {
            aantal_italie = 0
        }
        aantal_italie = parseInt(aantal_italie)
        if (isNaN(aantal_italie)) {
            $('#tb_aantal_italie').val(standaard)
            aantal_italie = 0
        }
        aantal_frankrijk = $('#tb_aantal_frankrijk').val()
        if (aantal_frankrijk == '') {
            aantal_frankrijk = 0
        }
        aantal_frankrijk = parseInt(aantal_frankrijk)
        if (isNaN(aantal_frankrijk)) {
            $('#tb_aantal_frankrijk').val(standaard)
            aantal_frankrijk = 0
        }
        aantal_oostenrijk = $('#tb_aantal_oostenrijk').val()
        if (aantal_oostenrijk == '') {
            aantal_oostenrijk = 0
        }
        aantal_oostenrijk = parseInt(aantal_oostenrijk)
        if (isNaN(aantal_oostenrijk)) {
            $('#tb_aantal_oostenrijk').val(standaard)
            aantal_oostenrijk = 0
        }
        aantal_totaal = aantal_italie + aantal_frankrijk + aantal_oostenrijk
        subtotaal = aantal_totaal * 12.95
        totaal = subtotaal + 1.95
        subtotaal = subtotaal.toFixed(2)
        subtotaal = subtotaal.toString().replace(/\./g, ',')
        totaal = totaal.toFixed(2)
        totaal = totaal.toString().replace(/\./g, ',')
        $('#overzicht #aantal_boekjes').html(aantal_totaal + ' x')
        $('#overzicht .subtotaal.rechts').html('€ ' + subtotaal)
        $('#overzicht .totaal.rechts').html('€ ' + totaal)
        if (aantal_totaal > 10) {
                $('#overzicht span').hide()
                $('#meer_dan_10').show()
            }
            else if (aantal_totaal > 0) {
                $('#overzicht p').hide()
                $('#overzicht span').show()
            }
            else {
                $('#overzicht span').hide()
                $('#overzicht p').hide()
            }
        }
    )
})

$(function() {
    $('.naar_stap_1')
        .click(function() {
            $('#stap_2').hide()
            $('#stap_3').hide()
            $('#stap_1').show()
        }
    )
})

$(function() {
    $('.naar_stap_2')
        .click(function() {
            if (aantal_italie == '') {
                $('#tb_aantal_italie').val(standaard)
            }
            if (aantal_frankrijk == '') {
                $('#tb_aantal_frankrijk').val(standaard)
            }
            if (aantal_totaal == 0) {
                $('#nul').show()
            }
            else if (aantal_totaal > 10) {
                $('#meer_dan_10').show()
            }
            else if (aantal_totaal == undefined) {
                $('#nul').show()
            }
            else {
                $('#stap_3').hide()
                $('#stap_1').hide()
                $('#stap_2').show()
            }
        }
    )
})

$(function() {
    $('.naar_stap_3')
        .click(function() {
            $('#bestelformulier').validate({
                rules: {
                    tb_naam: "required",
                    tb_adres: "required",
                    tb_postcode: "required",
                    tb_plaats: "required",
                    rbg_land: "required",
                    tb_telefoon: "required",
                    tb_email: {
                        required: true,
                        email: true
                    }
                },
                messages: {
                    tb_naam: "* Verplicht veld",
                    tb_adres: "* Verplicht veld",
                    tb_postcode: "* Verplicht veld",
                    tb_plaats: "* Verplicht veld",
                    rbg_land: "* Verplicht veld",
                    tb_telefoon: "* Verplicht veld",
                    tb_email: {
                        required: "* Verplicht veld",
                        email: "* Verplicht veld"
                    }
                }
            })
            if ($('#bestelformulier').valid() == false) {
                $('#stap_3').hide()
                $('#stap_1').hide()
                $('#stap_2').show()
            }
            else {
                $('#stap_1').hide()
                $('#stap_2').hide()
                $('#stap_3').show()
            }
        }
    )
})

$(function() {
    $('.naar_stap_links, .naar_stap_rechts, .naar_de_boekjes').hover(
        function() {
            $(this).css({ 'color': '#C8D20A', 'cursor': 'pointer' })
        },
        function() {
            $(this).css({ 'color': '#0071BC', 'cursor': 'default' })
        }
    )
})

$(function() {
    $('#cb_akkoord')
        .click(function() {
            if ($(this).is(':checked') == true) {
                $('#bt_bestellen').removeAttr('disabled')
            }
            else {
                $('#bt_bestellen').attr('disabled', 'disabled')
            }
        }
    )
})

$(function() {
    $('#bt_zenden')
        .click(function() {
            $('#contactformulier').validate({
                rules: {
                    tb_naam: "required",
                    tb_email: {
                        required: true,
                        email: true
                    },
                    tb_extra: "required"
                },
                messages: {
                    tb_naam: "* Verplicht veld",
                    tb_email: {
                        required: "* Verplicht veld",
                        email: "* Verplicht veld"
                    },
                    tb_extra: "* Verplicht veld"
                }
            })
        }
    )
})
