


var StartPageGallery = function(edit)
{
    this.edit = edit;
    var that = this;
    this.total = gallerylist.length;
    this.currimage = 0;
    var currid = '#g1';
    var nextid = '#g2';
    var wait = 6000;
    this.updatepage = function()
    {
        $('a[name=gallery]').css('font-weight','normal');
        if($('a[name=gallery]')[that.currimage])
            setTimeout("$($('a[name=gallery]')["+that.currimage+"]).css('font-weight','bold');",1000);
    }
   
    
    this.next = function()
    {        
        if(that.currimage==that.total)
            that.currimage=0;
        that.updatepage();
        $(nextid).css('background-image','url("/design/gallery/'+gallerylist[that.currimage].Name+'/'+gallerylist[that.currimage].Imgname+'")');

        if(that.edit) $('#debug').text(gallerylist[that.currimage].Name+'/'+gallerylist[that.currimage].Imgname + '   W:'+gallerylist[that.currimage].Height + ' L: '+gallerylist[that.currimage].Width);
        
        $('#savelen').data('item',gallerylist[that.currimage]);
        $('#boxheight').val(gallerylist[that.currimage].Height);
        $('#boxlen').val(gallerylist[that.currimage].Width);


        $(nextid).animate({
            opacity:1
        },2000);
        $(currid).animate({
            opacity:0
        },4000);
        that.switchid();
        if(currid=='#g1'){
            $('#boxtext1').text(gallerylist[that.currimage].Text);

            if(gallerylist[that.currimage].Height==0)
            {
                $('#boxtext1').hide(0);
            }else
            {
                $('#boxtext2').show(0);
                $('#boxtext1').height(gallerylist[that.currimage].Height);
                $('#boxtext1').width(gallerylist[that.currimage].Width);
            }

            if(gallerylist[that.currimage].Clickurl!="")
            {
                $('#boxtext1').css('cursor','pointer');
                var tempclickurl1 = gallerylist[that.currimage].Clickurl;
                $('#boxtext1').unbind('click');
                $('#boxtext1').click(function()
                {
                    window.open(tempclickurl1);
                });
            }

        }
        if(currid=='#g2'){
            $('#boxtext2').text(gallerylist[that.currimage].Text);
            
            if(gallerylist[that.currimage].Height==0)
            {
                $('#boxtext2').hide(0);
            }else
            {
                $('#boxtext2').show(0);
                $('#boxtext2').height(gallerylist[that.currimage].Height);
                $('#boxtext2').width(gallerylist[that.currimage].Width);
            }

            $('#boxtext2').height(gallerylist[that.currimage].Height);
            $('#boxtext2').width(gallerylist[that.currimage].Width);


            if(gallerylist[that.currimage].Clickurl!="")
            {
                $('#boxtext2').unbind('click');
                $('#boxtext2').css('cursor','pointer');
                var tempclickurl2 = gallerylist[that.currimage].Clickurl;
                $('#boxtext2').click(function()
                {
                    window.open(tempclickurl2);
                });
            }
        }        
        that.currimage++;

        if(!this.edit) setTimeout('gallery.next();',wait);
    }


    $('#boxlen').blur(function(){
        if(currid=='#g2')
            $('#boxtext2').width($('#boxlen').val()+'px');
        if(currid=='#g1')
            $('#boxtext1').width($('#boxlen').val()+'px');
    });
    $('#boxheight').blur(function(){
        if(currid=='#g1')
            $('#boxtext1').height($('#boxheight').val()+'px');
        if(currid=='#g2')
            $('#boxtext2').height($('#boxheight').val()+'px');
    });
    

    $('#debuga').click(function () {
        that.next();
    });

    this.switchid = function(){
        var r = currid;
        r = currid;
        currid = nextid;
        nextid = r;
    }    
}
