<?php $attachments = get_children( array('post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order ASC') ); ?>
<?php $gallery = get_post_meta($post->ID, "gallery", true); ?>
<?php $gallery_title = get_post_meta($post->ID, "gallery_title", true) ? get_post_meta($post->ID, "gallery_title", true) : __('Gallery', TS_DOMAIN); ?>

<?php // photo gallery with custom field 'gallery' (comma-separated media file IDs => 12,34,69)
	if($gallery) : $images = explode(',',$gallery); ?>

<div id="gallery" class="clearfix clear">

    <h3 class="gallery-title"><?php echo $gallery_title; ?></h3>

    <?php foreach ($images as $image_id) : $src = wp_get_attachment_image_src($image_id, 'full'); $image_post = get_post($image_id); ?>
        
	<div class="img"><div class="box3-top"></div><div class="box3-con"><a href="<?php echo $src[0]; ?>" rel="prettyPhoto[gallery]" title="<?php echo $image_post->post_content; ?>"><?php echo wp_get_attachment_image($image_id, 'dl-thumb'); ?></a></div><div class="box3-bot"></div></div>
        
	<?php endforeach; ?>

</div><!-- end gallery -->

<?php // photo gallery with attachments
	elseif($attachments && get_post_meta($post->ID, "attachments", true)) : ?>
	
<div id="gallery" class="clearfix clear">

    <h3 class="gallery-title"><?php echo $gallery_title; ?></h3>
        
    <?php $$i=1; foreach($attachments as $attachment_id => $attachment) : $src = wp_get_attachment_image_src($attachment_id, 'full'); ?>
	
	    <div class="box clearfix <?php if($i%2==0) : ?>box-alt<?php endif; ?>">
	    
	    	<a href="<?php echo $src[0]; ?>" rel="prettyPhoto[gallery]" title="<?php echo $attachment->post_content; ?>"><?php echo wp_get_attachment_image($attachment_id, 'dl-thumb'); ?><span class="overlay2"></span></a>
	    	
	    </div><!-- end box -->
    
    <?php $i++; endforeach; ?>

</div><!-- end attachments -->

<?php endif; // endif gallery ?>