var dWindowZIndex = 100;

var dWindow = new Class({
	options: {
		minWidth : 150,
		minHeight : 150,
		width : 200,
		height : 200,
		top : 0,
		left : 0,
		resizable : true,
		statusBar : true,
		content : '',
		id : ''
	},
	
	handle : null,
	
	drag : null,
	
	dragParams : {},

	// конструктор класса
	initialize: function(options){
		this.setOptions(options);
	},
	
	
	_create : function(id){
		var target = $(id);
		if (!target)
			return;
		
		this.handle = new Element('div', {
								'class':'dWindow',
								'id' : this.options.id,
								styles : {
									'width':this.options.width + 2,
									'left':this.options.left,
									'top':this.options.top,
									'z-index':dWindowZIndex
								}
							});
		dWindowZIndex++;
		this.handle.addEvent('mousedown', this.up.bind(this));
		
		var bar = new Element('div', {'class':'topBar'});
		var closeBtn = new Element('div', {'class':'closeBtn'});
		closeBtn.addEvent('click', this.close.bind(this));
		closeBtn.injectInside(bar);

		var table = new Element('table',{
			'class':'dContainer',
			'cellpadding':0,
			'cellspacing':0,
			'border':0
		});

		var tbody = new Element('tbody');

		// первый ряд
		var row = new Element('tr');
		
		
		var center = new Element('td');
		var content = new Element('div',{'class':'centralArea', styles : {'width':this.options.width, 'height':this.options.height}});
		content.set('html',this.options.content);
		center.adopt(content);
		
		row.adopt([ center]);

		var row2 = new Element('tr');
		var statusBar = new Element('td',{'class':'statusBar'});
		
		statusBar.injectInside(row2);
		
		var row3 = new Element('tr');
		var bottomBorder = new Element('td', {'class':'bottomBorder'});
		bottomBorder.injectInside(row3);
		
		row.injectInside(tbody);
		row2.injectInside(tbody);
		row3.injectInside(tbody);
		
		tbody.injectInside(table);
		
		this.handle.adopt([bar, table]);

		
		this.handle.injectInside(target);
		
		
		
		var that = this;
		
		
	},
	
	_destroy : function(){
		if ($type(this.handle) == 'element'){
			this.handle.destroy();
		}
		this.handle = null;
	},
	
	open : function(elem){
		if (!this.handle)
			this._create(elem);
	},
	
	close : function(){
		this._destroy();
	},

	up : function(){
		this.handle.setStyle('z-index', ++dWindowZIndex);
	},
	
	// заимствуем методы классов Options и Events
	Implements : [Options, Events]
});
function hideBtn() {
  
          $("sendmes").innerHTML = "Подождите, идет загрузка…";
  
      }
function delete_img(div) {
  
          $(div).innerHTML = "";
  
      }  
function delete_vid(div) {
  
          $(div).innerHTML = "";
          $('video_int').value = "";
  
      }       
  
      function handleResponse(mes) {
  
          
  			$("sendmes").innerHTML = "";
          $("sendBtn").innerHTML =
  
              "<input type=\"file\" id=\"foto\" name=\"userfile\" /><input type=\"submit\" value=\"Загрузить\" />";
  
          if (mes.error != null) {
  				
              $("sendmes").innerHTML += "Возникли ошибки во время загрузки файла: " + mes.error;
  
          }
  
          else {
  
              $('res').innerHTML += mes.ok;
  
          }
  
      }
var open = 0;      
var count = 0;
var dw = new dWindow({
		id:'newone_'+count,
		content:'<div id="mediaspace"></div>',
		width: 740,
		height: 265,
		minWidth: 100,
		minHeight: 50,
		left: '40%',
		top: '30%'
		
	});
function dwopen(event){
	
			if(open) {
				dw.close();
				open=0;
				$('mainer').removeEvent('click', dwopen);
			}else{
				open++;
			}
		}	
function create(catid){
	$('mainer').addEvent('click', dwopen);
	dw.open($(document.body));
	
	var s1 = new SWFObject("http://neotoy.ru/media/theme/flvplayer.swf","ply","740","260","9");

				s1.addVariable("skin", "http://neotoy.ru/media/theme/modieus.swf");
				s1.addParam("allowfullscreen","true");
				s1.addVariable("autostart","true");
				s1.addVariable("width","390");
				s1.addVariable("height","320");
				s1.addParam("allowscriptaccess","always");
				s1.addVariable("file","http://www.neocubic.ru/media/video/"+catid+".xml");
				s1.addVariable("playlist","right");
				s1.addVariable("fullscreen","true");
				s1.addVariable("backcolor","000000");
				s1.addVariable("frontcolor","ffffff");
				s1.addVariable("playlistsize","380");
				s1.addVariable("controlbar","over");
				s1.write("mediaspace");
	s1.write("mediaspace");
	count++;
	return false;
}
