$(function(){

	/**
	* Fixing Wmode to avoid youtube popping up over fancybox
	*/

	// FireFox is easy to handle
	$("embed").attr("wmode", "opaque");
	
	// IE requires more work
	var embedTag;
	$("embed").each(function(i) {
		embedTag = $(this).attr("outerHTML");
		if ((embedTag != null) && (embedTag.length > 0)) {
			embedTag = embedTag.replace(/embed /gi, "embed wmode=\"opaque\" ");
			$(this).attr("outerHTML", embedTag);
		}
	});
	/**
	* Done fixing wmode
	*/
  

$(".post").prepend('<div class="PostBrand"></div>');

$(".post .entry-content").each(function(i){
	
	var no = i;
	
	$(this).append('<div class="imgGallery"></div>');
	
	//var f = $(this).find("img").length;
		
		$(this).find("img").each(function(){
			
			var ul = $(this).parents(".entry-content").find(".imgGallery");
			var src= $(this).attr('src');
			
			if($(this).hasClass("size-thumbnail")) {
			
				src = $(this).parents('a').attr("href");
			
			};
			
			$(this).next("br").remove();
			$(this)
				.remove()
				.removeAttr("width")
				.removeAttr("height")
				.appendTo(ul)
				.wrap('<a href="'+src+'" rel="'+no+'_gallery"></a>');

		});
	
	$(".imgGallery a").fancybox();
	$(".post img").show();
		
});


});
