$(function() {

	// prepend the overlay html to the body tag
	$('<div id="wcavidovr" class="apple_overlay ovrblack"><iframe height="450px" frameborder="0" width="100%" src="" class="wcavidwrapper"></iframe></div>').prependTo('body');

	// if the function argument is given to overlay,
	// it is assumed to be the onBeforeLoad event listener
	$('a[rel]').filter('a[rel!="nofollow"]').overlay({

		mask: '#000000',
		effect: 'apple',

		onBeforeLoad: function() {

			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".wcavidwrapper");

			// load the page specified in the trigger
			wrap.attr('src', this.getTrigger().attr("href"));
			// shut up ie !
			var closebtn = this.getOverlay().find("a.close");
			closebtn.click(function() {
				
				var ifrm = $(this).parent().find(".wcavidwrapper");
				ifrm.attr("src", "");
			});
		}

	});
	
	$("a[rel]").filter('a[rel!="nofollow"]').each(function() {
		var el = $(this);
		el.find('button').remove();
		el.append('<img width="85" src="http://video.walnutcreekarchery.com/images/wcavid_btn.jpg" />');
		$("div#productMainImage").append(this);
		el.css('display', 'block');
		el.css('margin-top', '15px');
	});
});
