﻿var play = true;
var Index = 0;
var max = 0;
$(document).ready(function() {

    $('#right').cycle({
    	fx: 'scrollHorz',
        timeout: 0,
        easing: 'backinout',
        pager: '#tumbNav',
        pagerAnchorBuilder: function(idx, slide) {
            max++;
            // return selector string for existing anchor 
            return '#tumbNav span:eq(' + idx + ') a';
        }

    });
    function FF(){
        if(Index == max-1) return;
        Index++;
        $('#right').cycle(Index);
    }
    
    function BW(){
        if(Index == 0) return;
        Index--;
        $('#right').cycle(Index);
    }
    
    if ($("#tumbNav").find("a").length < 8) {
        if ($("#tumbNav").find("a").length < 2) {
            $("#toolbox").hide(1);
            $("#ctl00_MainBodyRegion_pnlToolbox").height(350);
        }

        $("#leftPil").css("display", "none");
        $("#rightPil").css("display", "none");
    }
    else {
        if ($("#toolbox").is(':visible'))
            $("#toolbox").scrollable();
    }

    $("#CloseButton").click(function() {
        $("#OverLaying").hide(10);
    });

    $(window).keydown(function(e){
            if(e.which == 37){ $('#PrevLeft').click();BW();}
            else if(e.which == 39){ $('#NextRight').click();FF();}
        });
    
    $("#fullscreen").click(function() {
        setSize();
        $("#OverLaying").show(10);
        $("#right2").html($("#right").html());
       

        $('#right2').cycle({
            fx: 'fade',
            speed: 300,
            timeout: 3000,
            after: onAfter,
            next: '#NextRight',
            prev: '#PrevLeft',
            keyboard: true
           
        });
        


        $("#PlayButton").click(function() {
            if (!play) {
                $("#PlayButton").css("background", "transparent url(/Templates/images/playPause.gif) no-repeat scroll -12px 0");
                $('#right2').cycle('resume');
                play = true;
            }
            else {
                $("#PlayButton").css("background", "transparent url(/Templates/images/playPause.gif) no-repeat scroll 0 0");
                $('#right2').cycle('pause');
                play = false;
            }
        });
    });

});

    
    function onAfter() { 
        $('#ImageText').html(this.alt);
        
    }
    
    function setSize()
    {
       var off = $("#right").offset();
       if (off) {
            $("#OverLaying").css("width", $(document).width());
            $("#OverLaying").css("height", $(document).height()); 
       }
    }     
