How can I pull tags assigned to post that attachment is linked to?

I am working on a custom template file that pulls all images in my Media Library with a specific tag. I was able to get this working with some help from the community, it also shows the title of the post that the image is associated with. I need to pull the tags for post the image is attached to as a class name on a container. This is my code:
http://pastebin.com/epireefR

This line: echo '<aside class="work_item" data-id="id-' . get_the_ID() . '" data-type="' . $posttags . '">'; is where I am trying to get the posts tags (ie: hvac, contractor... for example). On another custom template file I use the following code:

data-type="<?php $posttags = get_the_tags(); if ($posttags) { foreach ($posttags as $tag) { echo str_replace('-','_',$tag->slug . ' '); } } ?> <?php $posttags = get_the_terms($post->ID, 'type'); if ($posttags) { foreach($posttags as $tag) { echo str_replace('-','_',$tag->slug . ''); } } ?>"

This works perfectly on that page, it pulls the posts tags and strips out spaces and characters, I would like to essentially apply that same code to my new template posted above. Of course all help is greatly appreciated!