A1plus = {};
A1plus.YoutubePopup = new Class({
    Implements: [Events, Options],

	el: null,

    body: null,
    popup: null,


	options: {
		type: '1',
        url: '',
        uploadUrl: ''
	},

    initialize: function (options) {

        options = options || {};
		this.setOptions(options);

        this.el = this._createElement().setStyle('z-index', 100).inject($(document.body));
        this.popup = this.el;
		this.popup.setStyle('display', 'none');
        this.setPos();
    },

    close: function () {
        this.popup.getChildren('iframe').destroy();
		
		this.popup.setStyle('display', 'none');
	},

    show: function(){
        this.popup.setStyle('display', 'block');
		var ptop = window.getScroll().y + window.getHeight() / 2 - this.popup.getHeight() / 2 - 10;
		if ( ptop < 0 ){
			ptop = 10;
		}
        this.popup.setStyle('top', ptop);
    },

    setUrl: function (url) {
        this.options.url = url;
    },
  

    _createElement: function () {
        var className = 'popup'
		
		return new Element('div', {
			'class': className
		});
	},

    getType: function(){
        return this.options.type;
    },


    getUploadUrl: function(){
        return this.options.uploadUrl;
    },


    getSize: function () {
		return {
			width: this.popup.getWidth(),
			height: this.popup.getHeight()
		};
	},

    setPos: function () {
        this.popup.setStyles({ left: $(document.body).getWidth() / 2 - (this.getSize().width) / 2 - 300, top: window.getScroll().y + window.getHeight() / 2 - this.popup.getHeight() / 2 - 10});
	}
    
});



A1plus.YoutubePopup.Ajax = new Class({
	Extends: A1plus.YoutubePopup,

	load: function (url) {
        this.content = this.el;
        var tmpObj = this;
        var content = this.content;
        
		new Request({
			url: url,
			method: 'get',
			evalScripts: true,
			onSuccess: function (resp) {
				content.set('html', resp);


				


                tmpObj.show();
				this.fireEvent('ready');
                $$('.popupCross').addEvent('click',function(e) {
                    e.stop();
                    tmpObj.close();
                });
			}.bind(this)
		}).send();
	}
});





