show div only if have a related post inside

move the div section from the start to after the if(have_posts()) { line, and move the corresponding closing divs to just before the closing bracket } of this if statement;

full code:

<?php     
global $post;     
    $terms = get_the_terms( $post->ID , 'movies', 'string');     
    $do_not_duplicate[] = $post->ID;      
    if(!empty($terms)){         
        foreach ($terms as $term) {             
        query_posts( array(             
            'movies' => $term->slug,             
            'showposts' => 4,             
            'caller_get_posts' => 1,             
            'post__not_in' => $do_not_duplicate 
            ) );    

            if(have_posts()){ ?>
        <div id="related_box" class="related">     
        <div class="movie_header">     
        <div id="featured"><h2>Related</h2>      
        </div>          
            <?php while ( have_posts() ) : the_post(); 
            $do_not_duplicate[] = $post->ID; ?>     
            <div class="related">     
                <div class="inner">     
                    <div class="thumb"><?php if ( has_post_thumbnail()) the_post_thumbnail('movie-thumb'); ?></div>     
                <h2 class="description">text</h2>     
                <a href="https://wordpress.stackexchange.com/questions/58480/<?php the_permalink(); ?>"><h1 class="title" ><?php the_title(); ?> </h1></a>   
                </div>     
            </div>                 
            <?php endwhile; wp_reset_query(); ?>        
        </div>       
        </div>          
            <?php } //ends: if(have_posts())
        }     
    }     
?>