/*
 * torShadow jQuery Plugin
 * Tor Løkken
 * http://www.enonic.com
 */

(function($) {
    $.fn.torShadow = function(options) {
        var opts = $.extend({}, $.fn.torShadow.defaults, options);
        
        return this.each(function() {
        	$(this).click(function(e) {
        		var overlay = $(document.createElement('div')).attr('class', 'tor-shadow-overlay').css('height', $(document).height());
        		var shadowBox = $(document.createElement('div')).attr('class', 'tor-shadow-box');
    			//shadowBox.css({'width' : opts.width + 'px', 'height' : opts.height + 'px', 'top' : ($(window).height() - opts.height) / 3 + 'px', 'left' : ($(window).width() - opts.width) / 2 + 'px'});
    			shadowBox.css({'width' : opts.width + 'px', 'height' : opts.height + 'px', 'top' : '100px', 'left' : ($(window).width() - opts.width) / 2 + 'px'});
    			var closeButton = $(document.createElement('a')).attr('class', 'close').attr('href', '#').text('Lukk');
    			shadowBox.append(closeButton);
        		$.fn.torShadow.iframe(shadowBox, $(this).attr('href'), opts);
        		$('body').prepend(overlay);
        		$('body').prepend(shadowBox.show());
        		$('.tor-shadow-overlay, .tor-shadow-box .close').click(function(e) {
        			$('.tor-shadow-overlay, .tor-shadow-box').hide();
        			e.preventDefault();
        		});
        		
        		
        		e.preventDefault();
        	});
        });
    };
    
    $.fn.torShadow.iframe = function(box, url, opts) {
    	var boxContent = $(document.createElement('iframe')).attr('src', url);
    	if (!opts.scroll) {
    		boxContent.attr('scrolling', 'no');
    	}
      	box.append(boxContent);
    }
    
    $.fn.torShadow.defaults = {
        width: 1000,
        height: 700,
        scroll: false
    };

})(jQuery);