jSlide = {
    init: function( config )
    {
        var THIS = this;
        
        THIS.idDiv     = config.idDiv;
        THIS.width_px  = config.width_px;
        THIS.height_px = config.height_px;
        THIS.images    = config.images;
        THIS.showLogo  = config.showLogo || false;
        THIS.buttons   = config.buttons || {
            active:  'resources/images/jSlide/slide_active.png',
            inactive:'resources/images/jSlide/slide_inactive.png'
        };
        
        THIS.slideCurrent = 0;
        THIS.countAutomatic = 0;
        
        THIS.buildSlides();
        THIS.runAutomatic();
    },
    buildSlides: function()
    {
        var THIS = this;
        
        var nImages = THIS.images.length;
        
        $( "#"+THIS.idDiv ).css({ position:'relative' });
        
        //IMAGES
        var tmpHTML = "";
        for( var i = 0; i < nImages; i++ )
        {
            tmpHTML +=
                '<div id="jSlide_slide_'+i+'" style="position:absolute; left:0; top:0; width:'+THIS.width_px+'px; height:'+THIS.height_px+'px; display:'+( i==0?'block':'none' )+'; z-index:'+( i==0?10:0 )+'; ">' +
                    '<img src="'+THIS.images[i]+'" width="'+THIS.width_px+'" height="'+THIS.height_px+'" border="0" />'+
                '</div>';
        }
        
        //BUTTONS
        var btnHTML = '<div style="position:absolute; z-index:200; right:20px; top:228px;">';
        var styleBtn = "float:left; cursor:pointer; margin:1px; ";
        for( var j = 0; j < nImages; j++ )
        {
            if( j == 0 )
                btnHTML +=
                    '<div id="jSlide_btn_'+j+'" order="'+j+'" style="'+styleBtn+'">' +
                        '<img src="'+THIS.buttons.active+'" width="16" height="15" border="0">' +
                    '</div>';
            else
                btnHTML +=
                    '<div id="jSlide_btn_'+j+'" order="'+j+'" style="'+styleBtn+'">' +
                        '<img src="'+THIS.buttons.inactive+'" width="16" height="15" border="0">' +
                    '</div>';
        }
        btnHTML += '<div style="clear:both;"></div>';
        btnHTML += '</div>';
        
        //BORDERS
        var brdLeft =
            '<div style="position:absolute; z-index:10; left:-16px; top:0px;">' +
                '<img src="resources/images/jSlide/border_left_slide.png" width="33" height="250" border="0">'+
            '</div>';
        var brdRight =
            '<div style="position:absolute; z-index:10; left:702px; top:0px;">' +
                '<img src="resources/images/jSlide/border_right_slide.png" width="33" height="250" border="0">'+
            '</div>';
        
        //LOGO
        var logoHTML = ( !THIS.showLogo ) ? '' :
            '<div style="position:absolute; z-index:102; left:504px; top:185px;">' +
                '<img src="resources/images/banner/mini_logo.png" width="155" height="53" border="0">'+
            '</div>';
        
        $( "#"+THIS.idDiv ).html( tmpHTML + btnHTML + brdLeft + brdRight + logoHTML );
        
        for( var k = 0; k < nImages; k++ )
        {
            $( "#jSlide_btn_"+k ).click(function(){
                THIS.showSlide( $(this).attr("order") );
            });
        }
    },
    runAutomatic: function()
    {
        var THIS = this;
        
        var nImages = THIS.images.length;
        
        THIS.idInterval = setTimeout( function(){
            THIS.countAutomatic++;
            
            if( nImages == THIS.countAutomatic ) THIS.countAutomatic = 0;
            
            THIS.showSlide( THIS.countAutomatic );
            clearInterval( THIS.idInterval );
            THIS.runAutomatic();
        }, 3000);
    },
    showSlide: function( nSlide )
    {
        var THIS = this;

        clearInterval( THIS.idInterval );
        
        if( THIS.slideCurrent == nSlide )
            return;
        
        $('#jSlide_slide_'+THIS.slideCurrent).css({ 'z-index':0 });
        $('#jSlide_btn_'+THIS.slideCurrent+" img").attr({ "src": THIS.buttons.inactive });
        
        $('#jSlide_slide_'+nSlide).css({ 'z-index':10 });
        $('#jSlide_btn_'+nSlide+" img").attr({ "src": THIS.buttons.active });
        
        $('#jSlide_slide_'+THIS.slideCurrent).fadeOut('slow', function() {});
        $('#jSlide_slide_'+nSlide).fadeIn('slow', function() {});
        
        THIS.slideCurrent = nSlide;
        THIS.countAutomatic = nSlide;
        
        THIS.idInterval = setTimeout( function(){
            THIS.runAutomatic();
        }, 3000);
    }
};

