﻿var currentMenu = "#menu_home";

$(document).ready(function () {
    $('#menuTable a').click(function (e) {
        RemoveCurrentMenu();
        currentMenu = '#' + e.target.id;
        var htmlPage = currentMenu.toString().substring(currentMenu.indexOf('_') + 1, currentMenu.length) + '.html';
        $('#content').load(htmlPage,
                    function () {
                        $(this).css('display', 'none');
                        $(this).fadeIn('slow');
                        PageLoad();
                    }
                );
        SetCurrentMenu();
    });
});

function SetCurrentMenu() {
    var menuItem = $('#menuTable').find(currentMenu);
    menuItem.css('background-image', 'url(images/menu_hover.png)');
    menuItem.css('background-position', 'bottom');
    menuItem.css('background-repeat', 'repeat-x');
}

function RemoveCurrentMenu() {
    var menuItem = $('#menuTable').find(currentMenu);
    menuItem.css('background-image', 'none');
}

function subMenuClick(htmlSubPage) {
    $('#subContent').fadeOut('normal');
    $('#subContent').load(htmlSubPage,
        function () {
            $(this).css('display', 'none');
            $(this).fadeIn('slow');
            PageLoad();
        });
}

function CloseSubPage() {
    $('#subContent').fadeOut('normal');
    var htmlPage = currentMenu.toString().substring(currentMenu.indexOf('_') + 1, currentMenu.length) + '.html';
    $('#content').load(htmlPage,
        function () {
            $(this).css('display', 'none');
            $(this).fadeIn('slow');
        });
}

function CheckMail() {
    $("a[rel='email']").each(function () {
        // Modify the mailto: value
        var mailtoVal = $(this).attr('href');
        mailtoVal = mailtoVal.replace("[email]", "mailto:");
        mailtoVal = mailtoVal.replace("[at]", "@");
        mailtoVal = mailtoVal.replace("[dot]", ".");
        mailtoVal = mailtoVal.replace("[dot]", ".");
        // Auto-generate title tags for users
        var mailtoTitle = mailtoVal.replace("mailto:", "Email: ");
        $(this).attr('title', mailtoTitle);
        // onClick Event
        $(this).click(function () {
            window.location.href = mailtoVal;
            return false;
        });
    });
}

function PageLoad() {
    //When you click on a link with class of poplight and the href starts with a #
    $('img.popup').click(function () {
        var rel = $(this).attr('rel'); 

        //Pull Query & Variables from href URL
        var query = rel.split(',');
        var popupCollection = query[0];
        var popupIndex = query[1];

        //Fade in the Popup and add close button
        $('#popup').fadeIn().prepend('<a href="#" class="closepoup"><img src="images/close.png" class="btn_close" title="Close Window" alt="Close" /></a>');

        //Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
        var popMargTop = ($('#popup').height() + 80) / 2;
        var popMargLeft = ($('#popup').width() + 80) / 2;

        //Apply Margin to Popup
        $('#popup').css({
            'margin-top': -popMargTop,
            'margin-left': -popMargLeft
        });

        //Fade in Background
        $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
        $('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn(); //Fade in the fade layer 
        Shoot(popupCollection, popupIndex);
        return false;
    });

    //Close Popups and Fade Layer
    $('a.closepoup, #fade').live('click', function () { //When clicking on the close or fade layer...
        $('#fade , .popup_block').fadeOut(function () {
            $('#fade, a.closepoup').remove();
        }); //fade them both out

        return false;
    });

    CheckMail();
}

var iPos = 0;
var _images = new Array();
var _path = '';
var imagesCollegas = new Array(
		'01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13');
var pathCollegas = 'Pics/Fotos/Collega/collega';
var imagesVroedVrouw = new Array(
        '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
        '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40',
        '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60',
        '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80',
        '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100',
        '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '120',
        '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '140',
        '141', '142', '143', '144', '145', '146', '147', '148', '149', '150', '151', '152', '153', '154', '155', '156', '157', '158', '159', '160',
        '161', '162', '163', '164', '165', '166', '167', '168', '169');
var pathVroedVrouw = 'Pics/Fotos/Vroedvrouw/vroedvrouw';
var imagesVroedVrouw2009 = new Array(
        '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
        '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40',
        '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60',
        '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76');
var pathVroedVrouw2009 = 'Pics/Fotos/Vroedvrouw2009/vroedvrouw2009_';
var imagesVroedVrouw2010 = new Array(
        '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
        '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40',
        '41', '42', '43', '44', '45', '46', '47');
var pathVroedVrouw2010 = 'Pics/Fotos/Vroedvrouw2010/vroedvrouw2010_';
var imagesVroedVrouw2011 = new Array(
        '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
        '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35');
var pathVroedVrouw2011 = 'Pics/Fotos/Vroedvrouw2011/vroedvrouw2011_';
var imagesBaby = new Array(
        '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
        '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33');
var pathBaby = 'Pics/Fotos/Activiteiten/Baby/baby';
var imagesBaby = new Array(
        '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
        '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33');
var pathBaby = 'Pics/Fotos/Activiteiten/Baby/baby';
var imagesDraagzak = new Array(
        '01', '02', '03', '04', '05', '06', '07', '08', '09');
var pathDraagzak = 'Pics/Fotos/Activiteiten/Draagzak/draagzak';
var imagesmoedergr = new Array(
        '01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19');
var pathmoedergr = 'Pics/Fotos/Activiteiten/Moedergroep/moedergr';
var imagesopendeur = new Array(
        '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
        '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40',
        '41', '42', '43', '44', '45', '46');
var pathopendeur = 'Pics/Fotos/Activiteiten/Opendeur/opendeur';
var imagesosteo = new Array(
        '01', '02', '03', '04'); 
var pathosteo = 'Pics/Fotos/Activiteiten/Osteopatie/osteo';
var imagespostnat = new Array(
        '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13');
var pathpostnat = 'Pics/Fotos/Activiteiten/Postnatale/postnat';
var imagessfeer = new Array(
        '01', '02', '03', '04', '05', '06', '07', '08', '09', '10');
var pathsfeer = 'Pics/Fotos/Activiteiten/Sfeer/sfeer';
var imagesstudent = new Array(
        '01', '02', '03'); 
var pathstudent = 'Pics/Fotos/Activiteiten/Studenten/student';
var imagesyoga = new Array(
        '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
        '21', '22', '23'); 
var pathyoga = 'Pics/Fotos/Activiteiten/Yoga/yoga';
var imageszwanger = new Array(
        '01', '02', '03', '04', '05', '06', '07', '08', '09', '10'); 
var pathzwanger = 'Pics/Fotos/Activiteiten/Zwangerschap/zwanger';


function Next() {
    if ((iPos) == _images.length - 1)
        iPos = 0;
    else
        iPos++;
    ShowItem();
    Preload(1);
}

function Previous() {
    if (iPos == 0)
        iPos = (_images.length) - 1;
    else
        iPos--;
    ShowItem();
    Preload(-1);
}

function Preload(iDelta) {
    var o = new Image();
    o.src = _path + _images[((iPos + iDelta))] + ".JPG";
}

function ShowItem() {
    $("#pic").attr('src', _path + _images[(iPos)] + '.JPG');
    $("#viewerIndex").html(_images[(iPos)] + ' / ' + _images.length);
}

function Shoot(sCollection, sSearch) {
    switch (sCollection) {
        case "collegas":
            _images = imagesCollegas;
            _path = pathCollegas;
            break;
        case "vroedvrouw":
            _images = imagesVroedVrouw;
            _path = pathVroedVrouw;
            break;
        case "vroedvrouw2009":
            _images = imagesVroedVrouw2009;
            _path = pathVroedVrouw2009;
            break;
        case "vroedvrouw2010":
            _images = imagesVroedVrouw2010;
            _path = pathVroedVrouw2010;
            break;
        case "vroedvrouw2011":
            _images = imagesVroedVrouw2011;
            _path = pathVroedVrouw2011;
            break;
        case "baby":
            _images = imagesBaby;
            _path = pathBaby;
            break;
        case "draagzak":
            _images = imagesDraagzak;
            _path = pathDraagzak;
            break;
        case "moedergr":
            _images = imagesmoedergr;
            _path = pathmoedergr;
            break;
        case "opendeur":
            _images = imagesopendeur;
            _path = pathopendeur;
            break;
        case "osteo":
            _images = imagesosteo;
            _path = pathosteo;
            break;
        case "postnat":
            _images = imagespostnat;
            _path = pathpostnat;
            break;
        case "sfeer":
            _images = imagessfeer;
            _path = pathsfeer;
            break;
        case "student":
            _images = imagesstudent;
            _path = pathstudent;
            break;
        case "yoga":
            _images = imagesyoga;
            _path = pathyoga;
            break;
        case "zwanger":
            _images = imageszwanger;
            _path = pathzwanger;
            break;
        default:
            return;
    }
    var i;
    iPos = 0;
    if (sSearch != "") {
        iPos = 0;
        for (i = 0; i < _images.length; i++) {
            if (_images[i] == sSearch) {
                iPos = i;
                i = _images.length + 1;
            }
        }
    }
    
    ShowItem(iPos);
    Preload(1);
}
