(function(window, $, undefined) {

if (typeof $ !== 'function') {
	return console.error('AW Overlay: jQuery is missing, load it please');
}

var AWOverlay = function () {
	var inner = {
		self: this,
		initialized: false,
		settings: {},
	};




	this.load = function (settings) {

		$("<link/>", {
		   rel: "stylesheet",
		   type: "text/css",
		   href: "https://aw-overlay.pripravujeme.eu/assets/css/screen.css"
		}).appendTo("head");
		inner.settings = settings;

		// Using YQL and JSONP
		$.ajax({
		    url: "https:\/\/aw-overlay.pripravujeme.eu\/index\/overlay",
		 
		    // The name of the callback parameter, as specified by the YQL service
		    jsonp: "callback",
		 
		    // Tell jQuery we're expecting JSONP
		    dataType: "jsonp",
		 
		    // Tell YQL what we want and that we want JSON
		    data: settings,
		 
		    // Work with the response
		    success: function( response ) {
		        $('body').append(response);

		        if(settings.onLoad)
		        	settings.onLoad(inner.self);
		    }
		});
		
	};

	this.open = function() {
		//e.preventDefault();
		$('.aw-overlay').fadeIn();
		$('#aw-overlay-full').fadeIn();
		$('#aw-overlay-short').fadeOut();
		$('#aw-main-content').addClass('open').removeClass('close');

		//return false;
	};

	this.close = function() {
		$('.aw-overlay').fadeOut();
		$('#aw-overlay-full').fadeOut();
		$('#aw-overlay-short').fadeIn();
		$('#aw-main-content').addClass('close').removeClass('open');
		if(inner.settings.onClose)
			inner.settings.onClose(this);
		//return false;
	};

	this.closeImmediate = function(){
		$('.aw-overlay').hide();
		$('#aw-overlay-full').hide();
		$('#aw-overlay-short').show();
		$('#aw-main-content').addClass('close').removeClass('open');		
	}

};

window.awOverlay = new AWOverlay();


})(window, window.jQuery);