DND_InterfaceFix = new (function(){
	
	var embed = function(context){
		var configureEmbed = function($embed) {
    		$embed.css('width', '100%')
    			.attr('wmode', 'transparent');
    	};
    	
    	var configureObject = function($object) {
    		$object.css('width', '100%');
    	};
    	
    	$('embed', context).each(function(){
    		var $clone = $(this).clone();
    		configureEmbed($clone);
    		$(this).replaceWith($clone);
    	});
    	
    	$('object', context).each(function() {
    		var $node;
    		if ( $(this).is(':visible') )
    		{
    			$node = $(this).clone(); 
    		}
    		else
    		{
    			$node = $(this);
    		}

    		configureObject($node);
    		configureEmbed($node.find('embed'));
    		$(this).replaceWith($node);
    	});
	};
	
	var image = function(context) {

		var $context = $(context);
		var cWidth = $context.innerWidth();
		
		var resize = function(img) {
			var $img = $(img);
			
			if ( img.default_width === undefined ) {
				img.default_width = $img.width();
			}
						
			if ( img.default_width > cWidth ) {
				$img.css('width', '100%');
			} else {
				$img.css('width', img.default_width);
			}
			$img.show();
		};
		
		$context.find('img').hide().each(function(){
			
			if (this.naturalWidth == 0) {
				$(this).load(function(){
					resize(this);
				});
			} else {
				resize(this);
			}
		});
	};
	
	
	var iframe = function(context){
		var $iframe = $('iframe', context);
		var cWidth = $(context).innerWidth();
		if ( $iframe.width() > cWidth )
		{
			$iframe.css('width', '100%');
		}
	};
	
	this.fix = function(context) {
		this.embed(context);
		this.image(context);
		this.iframe(context);
	};
		
	this.embed = function(context) {
		$(context).each(function(){
			embed(this);
		})
	};
	
	this.image = function(context) {
		$(context).find('.ow_rss_widget, .ow_custom_html_widget').each(function(){
			image(this);
		});
	};
	
	this.iframe = function(context) {
		$(context).each(function(){
			iframe(this);
		});
	};

})();
