var PopupCart = function(frame_name){

	this.over_layer;
	this.cart_layer;

	window.onresize = OnWindowResize;

	// OVER LAYER
		this.over_layer = document.createElement('div');
		this.over_layer.style.position = 'absolute';
		this.over_layer.style.display  = 'none'; 
		this.over_layer.style.backgroundColor = '#000000';
		this.over_layer.onclick = CloseLayer;
		document.getElementsByTagName("body").item(0).appendChild(this.over_layer); 

	// CART FRAME
		this.cart_layer = document.getElementById(frame_name);

	var me = this;

	PopupCart.prototype.Show  = function(){ ShowLayer();  }
	PopupCart.prototype.show  = function(){ ShowLayer();  }
	PopupCart.prototype.Close = function(){ CloseLayer(); }
	PopupCart.prototype.close = function(){ CloseLayer(); }

	function ShowLayer(){

		var ps = GetPageSize();
		if(ps[2] < 800){ me.cart_layer.style.width  = Math.floor(ps[2] * 0.9) + 'px'; } else { me.cart_layer.style.width  = '840px'; }
		if(ps[3] < 600){ me.cart_layer.style.height = Math.floor(ps[3] * 0.9) + 'px'; } else { me.cart_layer.style.height = '640px'; }

		SetOpacity(me.cart_layer, 1);
		with(me.cart_layer.style){
			zIndex  = 303;
			display = '';
		}

		posX = Math.floor((ps[2] - me.cart_layer.offsetWidth) / 2);  if(posX < 0){ posX = 0; } posX += ps[4];
		posY = Math.floor((ps[3] - me.cart_layer.offsetHeight) / 2); if(posY < 0){ posY = 0; } posY += ps[5];

		SetOpacity(me.over_layer, 70);
		with(me.over_layer.style){
			zIndex  = 301;
			width   = ps[0] + 'px';
			height  = ps[1] + 'px';
			left    = '0px';
			top     = '0px';
			display = '';
		}

		with(me.cart_layer.style){
			zIndex  = 303;
			left    = posX + 'px';
			top     = posY + 'px';
			display = '';
		}
		SetOpacity(me.cart_layer, 100);

	}

	function CloseLayer(){
		me.over_layer.style.display = 'none';
		me.cart_layer.style.display = 'none';
	}

	function SetOpacity(elem, opacity){
		if(document.all){
			elem.style.filter = 'Alpha(opacity=' + opacity + ')';
		} else {
			opacity = opacity/100;
			elem.style.opacity = opacity;
		}
	}

	function OnWindowResize(){
	    if(me.over_layer.style.display != 'none'){
			me.ShowLayer()
		}
	}

	function GetPageSize(){
	    var pageWidth, pageHeight;
	    if (window.innerHeight && window.scrollMaxY) {  
	        pageWidth = window.innerWidth + window.scrollMaxX;
	        pageHeight = window.innerHeight + window.scrollMaxY;
	    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	        pageWidth = document.body.scrollWidth;
	        pageHeight = document.body.scrollHeight;
	    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	        pageWidth = document.body.offsetWidth;
	        pageHeight = document.body.offsetHeight;
	    }
	    var windowWidth, windowHeight;
	    if (self.innerHeight) { // all except Explorer
	        windowWidth = self.innerWidth;
	        windowHeight = self.innerHeight;
	    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	        windowWidth  = document.documentElement.clientWidth;
	        windowHeight = document.documentElement.clientHeight;
	    } else if (document.body) { // other Explorers
	        windowWidth  = document.body.clientWidth;
	        windowHeight = document.body.clientHeight;
	    }   
	    var scrollX, scrollY;
	    scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
	    scrollY = document.documentElement.scrollTop || document.body.scrollTop;
	    if(pageWidth  < windowWidth) { pageWidth  = windowWidth;  }
	    if(pageHeight < windowHeight){ pageHeight = windowHeight; }
	    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight, scrollX, scrollY) 
	    return arrayPageSize;
	}

}
