var BasketShortcut = {};
BasketShortcut.Fader = new Utilities.UI.Fader();
BasketShortcut.Fader.Speed = 10;

BasketShortcut.BasketLink = null;
BasketShortcut.ActiveLayer = null;
BasketShortcut.ShadowLayer = null;
BasketShortcut.OnReloadPage = null;

BasketShortcut.ShowBasket = function(Link){

	BasketShortcut.BasketLink = (Link != null) ? Link : document.getElementById("BasketLink");
	
	var HttpRequest = new CHttpRequest();
	HttpRequest.Additional = BasketShortcut.BasketLink;
	HttpRequest.AddProperty("AjaxType", "HTML");
	HttpRequest.AddProperty("RequestFile", "Passport.UI.Basket");
	HttpRequest.AddProperty("MethodName", "XGetSeeWireLayer");
	HttpRequest.onReturn = "BasketShortcut.ShowBasket_Callback";
	HttpRequest.Send();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BasketShortcut.ShowBasket_Callback = function(HttpRequest, state){
	var Link = state;
	var arCoords = Utilities.DOM.GetCoordinates(Link);
	
	BasketShortcut.ShadowLayer = document.createElement("DIV");
	BasketShortcut.ShadowLayer.style.position = "fixed";
	BasketShortcut.ShadowLayer.style.top = "0px";
	BasketShortcut.ShadowLayer.style.left = "0px";
	BasketShortcut.ShadowLayer.style.zIndex = 502;
	BasketShortcut.ShadowLayer.style.width = "100%";
	BasketShortcut.ShadowLayer.style.height = "100%";
	BasketShortcut.ShadowLayer.style.backgroundColor = "#000000";
	Controls.UI.Effects.SetOpacity(BasketShortcut.ShadowLayer, 50);
	
	var Layer = document.createElement("DIV");
	Layer.id = "BasketLayer";
	Layer.className = "BasketLayer";
	Layer.style.top = arCoords[1] + Link.offsetHeight +"px";
	Layer.style.left = (arCoords[0] + Link.offsetWidth - 350) + "px";
	Layer.style.zIndex = 503;
	
	Layer.style.width = "300px";
	
	var oShadow = new Utilities.UI.LayerShadow();
	oShadow.Object = Layer;
	
	Layer.innerHTML = HttpRequest.responseText;
	BasketShortcut.ActiveLayer = Layer;
	document.body.insertBefore(Layer, document.body.childNodes[0]);
	document.body.insertBefore(BasketShortcut.ShadowLayer, Layer);
	
	//BasketShortcut.Fader.SetOpacity(Layer, 100);
	//BasketShortcut.Fader.Fade(Layer.id, 10, 1);
	
	//oShadow.Render();
	
	Utilities.Events.RegisterEventHandler(Layer, "onclick", BasketShortcut.Layer_Click);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BasketShortcut.Layer_Click = function(pEvtObj){
	Utilities.Events.CancelBubble(pEvtObj);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BasketShortcut.Body_Click = function(pEvtObj){
	if(BasketShortcut.ActiveLayer == null)
		return;
	
	Utilities.DOM.RemoveNode(BasketShortcut.ActiveLayer);
	Utilities.DOM.RemoveNode(BasketShortcut.ShadowLayer);
	BasketShortcut.ActiveLayer = null;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BasketShortcut.Body_KeyPress = function(pEvtObj){
	if(pEvtObj.keyCode == 27)
		BasketShortcut.Body_Click(pEvtObj);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Utilities.Events.RegisterEventHandler(document.documentElement, "onclick", BasketShortcut.Body_Click);
Utilities.Events.RegisterEventHandler(document.documentElement, "onkeypress", BasketShortcut.Body_KeyPress);
