$.widget("ui.modal", {
	_init: function(){
		var inst = this, o = this.options;
		this.element.bind("resize",function(){
			inst.resize();
		});
		this.changeOverflow = false;
		if ( this.element.css("overflow") != 'hidden' ){
			this.changeOverflow = this.element.css("overflow");
			this.element.css("overflow","hidden");
		}
		this.modalDiv = $("<div/>")
		.addClass(o.modalClass)
		.css({
			zIndex: o.zIndex,
			opacity: 0.6
		})
		.appendTo(this.element);
		if ( o.msg ){
			this.msgDiv = $("<div/>")
			.addClass(o.msgClass)
			.css({
				zIndex: o.zIndex+1
			})
			.html(o.msg)
			.appendTo(this.element);
		}
		this.resize();
	},
	resize: function(){
		var o = this.options;
		var wDiff = 0, hDiff = 0;
		/* 	if the selector is the body and is half empty, 
				the modal would take only the size of the part of the page with content,
				so we take the size of the window */
		if ( this.element.get(0) === document.body ){
			var contW = $(window).width();
			var contH = $(window).height();
			var contX = $(window).scrollLeft();
			var contY = $(window).scrollTop();
		}
		else{
			var contW = $(this.element).outerWidth(true);
			var contH = $(this.element).outerHeight(true);
			var contX = $(this.element).position().left;
			var contY = $(this.element).position().top;
		}
		this.modalDiv
		.width(contW)
		.height(contH)
		.css({left: contX +'px', top: contY +'px'});
		if ( this.msgDiv ){
			var msgW = this.msgDiv.outerWidth();
			var msgH = this.msgDiv.outerHeight();
			if ( msgW > contW || msgH > contH ){
				this.msgDiv.hide();
			}
			else{
				this.msgDiv
				.css({
					left: Math.floor((contW-msgW)/2)+wDiff,
					top: Math.floor((contH-msgH)/2)+hDiff
				})
				.fadeIn("slow");
			}
		}
	},
	destroy: function(){
		var o = this.options;
		if ( this.msgDiv ){
			this.msgDiv.fadeOut("fast",function(){
				$(this).prev("."+o.modalClass).fadeOut("fast",function(){
					$(this).remove();
				});
				$(this).remove();
			})
		}
		else{
			this.modalDiv.fadeOut("fast",function(){
				$(this).remove();
			});
		}
		this.element.removeData("modal");
		if ( this.changeOverflow ){
			this.element.css("overflow",this.changeOverflow);
		}
	}
});
$.extend($.ui.modal, {
	version: "1.7.2",
	defaults: {
		modalClass: "ivts_modal",
		msg: false,
		msgClass: "ivts_modal_msg",
		zIndex: 6
	}
});
resizeScreen = function(){
	$(document.body).modal("destroy");
	$(".popup").remove();
	screenW = $(window).width();
	screenH = $(window).height();
	var x = screenW * gb_menu;
	$("#block_site").scrollTo(x+"px", 0, { easing:'easeOutExpo' });
	var num_blocks = $(".block").length;
	$("#container").width(num_blocks*(screenW+10));
	$(".block").width(screenW-30);
};
checkMail = function(str) {
	var check = /^[a-z0-9_-]+\.*[a-z0-9_-]*@[a-z0-9_-]+\.[a-z0-9_-]*\.*([a-z]{2,7})*$/i;
	return check.exec(str);
};

