var LightboxForm=new Class({
	initialize:function (name,properties,lightboxProperties) {
		this.name=name;
		this.properties=properties;
		this.lightboxProperties=$merge(LightboxForm.lightboxProperties,lightboxProperties);
	},
	show:function (name,callback) {
		Mantis.FormGenerator.FormGeneratorService.GetFormSource(this.name,this.properties || null,function (source) {
			var form=Element.fromMarkup(source,{ callback:function () {
				new Lightbox(form,this.lightboxProperties).show();
				if (callback) callback();
			}.bind(this) });
		}.bind(this));
	}
});
$extend(LightboxForm,{
	show:function (name,properties,lightboxProperties) { new LightboxForm(name,properties,lightboxProperties).show(); }
});

LightboxForm.lightboxProperties={ };

var Home={
	init:function(){
		Home.initPlayer();
	},
	
	initPlayer:function(){
		Home.player=new Swiff(Config.siteUrl + "flash/player.swf?rnd="+Math.random()*10000, {
			width: 890,
			height: 510,
			id: "VideoPlayer",
			params:{
				allowFullScreen:"true",
				allowScriptAccess:"always",
				bgcolor:"#000000",
				wmode:"window",				
				flashvars:"version=homepage&siteUrl="+Config.siteUrl
			},
			container: $("player")
		});
	}
};

var Work={
	flashIsReady:function(){
		Home.player.object.playVideo(Home.videoFile,"",Home.videoImageFile);
	}
};

$domready(Home.init);
var UserManager={
	init:function() {
		if($("footer-client-zone") && !UserManager.isLogIn){
			$("footer-client-zone").addReplacingEvent("click",function (e) {
				UserManager.openLogin();
			});
		}
		if($("user-logout")){
			$("user-logout").addReplacingEvent("click",function (e) {
				UserManager.logout();
			});
		}
	},

	loginLoaded:function() {
		var top=$("footer-client-zone").getTop()-214;
		var lb = new Lightbox(UserManager._loginFormElement,{opacity:0.4,hideOnEnter:false,hideOnEsc:true,fixedTop:top,contentClass:"login-lightbox-content"});
		lb.show();
		UserManager._loginFormElement.getElement(".close").addEvent("click",function(e) {
			Login.clearMessages();
			lb.hide();
		});
	},

	openLogin:function () {
		// if already got source
		if (UserManager._loginFormElement) UserManager.loginLoaded();
		// otherwise fetch source from server
		else Mantis.Web.Services.UserService.GetLoginFormSource(function (source) {
			UserManager._loginFormElement=Element.fromMarkup(source);
			UserManager.loginLoaded();
		});
	},
	openResetPassword:function () {
		UserManager.openLogin();
	},
	logout:function () {
		WebService.AuthenticationService.logout();
	},
	sendPassword:function (userName,callback) {
		Mantis.Web.Services.UserService.SendPassword(userName,function (success) {
			if (callback) callback(success);
		});
	}
};

$domready(UserManager.init);


