PhotoGallery={
    Initialize:function(){
        $('#photogallery img').load(function(){
            PhotoGallery.TooglePhoto($(this));
        });    
        $('#photogallery a').click(function(){
            PhotoGallery.TooglePhoto($('#photogallery #'+$(this).attr('id').substring(0, 6)));
            return false;
        });
        $('#photogallery #photo1').attr('src',$('#photogallery #photo1_swith').attr('href'));
    },
    PhotoTimeout:0,
    NextPhoto:function(){
        sp=$('#photogallery_viewer .select_photo');
        if(sp.length==0)return;
        if(sp.attr('id')=='photo5'){
            PhotoGallery.TooglePhoto($('#photogallery #photo1'));        
        }else{
            PhotoGallery.TooglePhoto(sp.next('img'));
        }
    },
    TooglePhoto:function(photo){
        clearTimeout(PhotoGallery.PhotoTimeout);
        photoSw=$('#photogallery #'+photo.attr('id')+'_swith');
        if(!photo.attr('src')){
            photo.attr('src',photoSw.attr('href'));
            return;
        }    
        sph = $('#photogallery_viewer .select_photo');
        ssw = $('#photogallery_scroller .select_whitch');
        phgal=$('#photogallery');
        sph.css({
            'position':'absolute',
            'top':phgal.offset().top+'px',
            'left':phgal.offset().left+'px'
        });    
        photo.css({
            'position':'absolute',
            'top':phgal.offset().top+'px',
            'left':phgal.offset().left+'px'
        });
        sph.removeClass('select_photo');
        ssw.removeClass('select_whitch');
        photo.addClass('select_photo');   
        photoSw.addClass('select_whitch');
        sph.fadeOut(1000);
        photo.fadeIn(1000, function(){
            $(this).css({
                'position':'static'
            });
        });
        PhotoGallery.PhotoTimeout = setTimeout("PhotoGallery.NextPhoto();",5000);    
    }
}
