﻿/// <reference path="jquery-1.3.2.min-vsdoc.js" />
var picData = {
    activepicturenr: 0,
    Pictures: [{
        'TargetDivID': 'P1',
        'ImgUrl': '/Content/Media/Image/intro-sierkgreenchoice.jpg',
        'timelength': 100000,
        'IsCached': 0,
        'linkurl': '#'
//    }, {
//        'TargetDivID': 'P2',
//        'ImgUrl': '/Content/Media/Image/thuis_banner_kaart.gif',
//        'timelength': 4000,
//        'IsCached': 0,
//        'linkurl': '#'
//    }, {
//        'TargetDivID': 'P3',
//        'ImgUrl': '/Content/Media/Image/intro-bos.jpg',
//        'timelength': 4000,
//        'IsCached': 0,
//        'linkurl': '#'
}]
    };

    var activeimg = 0;
    $(document).ready(
        function() {
            // functie ziet in 'Scripts/homepagina.js'
            initimages()
        } // eof document function
    );      // eof of document.ready



    var ScrollTimer = 0;
    var btnimg_play = '/Content/Images/btn_play.gif'
    var btnimg_pause = '/Content/Images/btn_pause.gif'

    function UpdatePageNr(PageNr) {
        $('#imgAmount a').removeClass();
        $('#imgAmount a:eq(' + eval(PageNr) + ')').addClass('ImgActive');
    }


    function initimages() {

        var linklist = '';
        for (i = 0; i < picData.Pictures.length; i++) {
            itemnr = i + 1;
            linklist = linklist + '<a href="">' + itemnr + '</a>'
        };
        linklist = linklist + '<a id="btnplay" href=""><img id="imgPause" src="/Content/Images/btn_pause.gif" /></a>'
        $('#imgAmount').html(linklist);
        $('#imgAmount a:eq(0)').addClass('ImgActive');
        $('#imgAmount a').click(function() {
            var i = 0;
            var pnr = $(this).html();

            if (pnr.indexOf(btnimg_pause) > 0) {
                // stop playing
                clearTimeout(ScrollTimer);
                $('#btnplay').html('<img src="' + btnimg_play + '" />')
            } else if (pnr.indexOf(btnimg_play) > 0) {
                // get activepagenr
                pnr = $('.pageselect')[0].id.substring(1, 2)
                var pnr = eval(pnr) + 1;
                if (pnr > picData.Pictures.length - 1) { pnr = 0 }
                showpage(pnr)
                $('#btnplay').html('<img src="' + btnimg_pause + '" />')
            } else {
                // show page
                showimg(pnr);
            }

            return false;
        });

        ScrollTimer = setTimeout('showpage(0);', 0);
    }

    function showpage(PageNr) {
        // init page numbers
        var currentnr = PageNr;
        var nextnr = PageNr + 1;
        if (nextnr > picData.Pictures.length - 1) { nextnr = 0 }

        // init pages
        var currentpage = $('#' + picData.Pictures[currentnr].TargetDivID);

        if (picData.Pictures[currentnr].IsCached == 0) {
            picData.Pictures[currentnr].IsCached = 1;
            currentpage.css('background-image', 'url(' + picData.Pictures[currentnr].ImgUrl + ')');
            currentpage.css('background-repeat', 'no-repeat');
        }

        if (jQuery.browser.msie == true && jQuery.browser.version == "6.0") {
            $('.pageselect').hide();
            $('.pageselect').addClass('pages').removeClass('pageselect');
            currentpage.addClass('pageselect').removeClass('pages');
            currentpage.show();
        } else {
            $('.pageselect').fadeOut(1000, function() {
                $('.pageselect').addClass('pages').removeClass('pageselect')
                currentpage.addClass('pageselect').removeClass('pages')
                currentpage.fadeIn(1000);
            })
        }

        UpdatePageNr(currentnr);

        ScrollTimer = setTimeout('showpage(' + nextnr + ');', picData.Pictures[currentnr].timelength);

        currentnr++;
        if (currentnr > (picData.Pictures.length - 1)) { currentnr = 0 }


    }


    function showimg(nr) {
        currentnr = eval(nr) - 1;
        clearTimeout(ScrollTimer);

        var currentpage = $('#' + picData.Pictures[currentnr].TargetDivID);

        if (picData.Pictures[currentnr].IsCached == 0) {
            picData.Pictures[currentnr].IsCached = 1;
            currentpage.css('background-image', 'url(' + picData.Pictures[currentnr].ImgUrl + ')');
            currentpage.css('background-repeat', 'no-repeat');
        };

        if (jQuery.browser.msie == true && jQuery.browser.version == "6.0") {
            $('.pageselect').hide(500);
            $('.pageselect').addClass('pages').removeClass('pageselect');
            currentpage.addClass('pageselect').removeClass('pages');
            currentpage.show(500);
        } else {
            $('.pageselect').fadeOut(1000, function() {
                $('.pageselect').addClass('pages').removeClass('pageselect')
                currentpage.addClass('pageselect').removeClass('pages')
                currentpage.fadeIn(1000);
            })
        }

        UpdatePageNr(currentnr);

        $('#btnplay').html('<img src="' + btnimg_play + '" />')

    };
