﻿Type.registerNamespace('JetShop.StoreControls.AddToCartInformationPopup'); 

JetShop.StoreControls.AddToCartInformationPopup = function(element)
{
    JetShop.StoreControls.AddToCartInformationPopup.initializeBase(this, [element]);
    
    this._infoTextHolder = null;
    this._frame = null;
    this._timer = null;
    this._onTickHandler = null;
    this._closeHandler = null;
    this._targetControlID = "";
    this._displayDuration = 15000;
    this._showAnimationID = "";
    this._closeButton = null;
    this._closeAnimationID = "";
    this._closeButtonImage = null;
    this._closeButtonToolTipText = null;
}

JetShop.StoreControls.AddToCartInformationPopup.prototype = 
{
    initialize : function() 
    {
        // initialize the base
        JetShop.StoreControls.AddToCartInformationPopup.callBaseMethod(this,'initialize');
        
        this._onTickHandler = Function.createDelegate(this, this._onTick);
        this._closeHandler = Function.createDelegate(this, this._close);
        
        this._timer = $create(Sys.Timer, {enabled:false,id:"timer1",interval:this._displayDuration}, {tick:this._onTickHandler}, null, null);
        this.hide();
        this._createLayout();
    },
	    
    dispose : function() 
    {
        JetShop.StoreControls.AddToCartInformationPopup.callBaseMethod(this,'dispose'); 
        
        if (this._closeButton != null)
        {
			$clearHandlers(this._closeButton);
		}
    },
    
    get_displayDuration : function()
    {
		return this._displayDuration;
    },
    
    set_displayDuration : function(value)
    {
		this._displayDuration = value;
		
		if (this._timer != null)
		{
			this._timer.set_interval(value);
		}
    },
    
    get_closeButtonToolTipText : function()
    {
		return this._closeButtonToolTipText;
    },
    
    set_closeButtonToolTipText : function(value)
    {
		this._closeButtonToolTipText = value;
    },
    
    get_closeButtonImage : function()
    {
		return this._closeButtonImage;
    },
    
    set_closeButtonImage : function(value)
    {
		this._closeButtonImage = value;
    },
    
    get_targetControlID : function()
    {
		return this._targetControlID;
    },
    
    set_targetControlID : function(value)
    {
		this._targetControlID = value;
    },
    
    get_showAnimationID : function()
    {
		return this._showAnimationID;
    },
    
    set_showAnimationID : function(value)
    {
		this._showAnimationID = value;
    },
    
    get_closeAnimationID : function()
    {
		return this._closeAnimationID;
    },
    
    set_closeAnimationID : function(value)
    {
		this._closeAnimationID = value;
    },
    
    show : function()
    {
		// Move object relative to targetcontrol
		
		// First, determine how much the visitor has scrolled 
        var scrolledX, scrolledY;
        if( self.pageYoffset )
        {
            scrolledX = self.pageXoffset; 
            scrolledY = self.pageYoffset;
        }
        else if( document.documentElement && document.documentElement.scrollTop )
        {
            scrolledX = document.documentElement.scrollLeft;
            scrolledY = document.documentElement.scrollTop;
        }
        else if( document.body )
        {
            scrolledX = document.body.scrollLeft;
            scrolledY = document.body.scrollTop;
        }

        // Next, determine the coordinates of the center of browser's window 
        var centerX, centerY;
        if( self.innerHeight )
        {
            centerX = self.innerWidth;
            centerY = self.innerHeight;
        }
        else if( document.documentElement && document.documentElement.clientHeight )
        {
            centerX = document.documentElement.clientWidth;
            centerY = document.documentElement.clientHeight;
        }
        else if( document.body )
        {
            centerX = document.body.clientWidth;
            centerY = document.body.clientHeight;
        }

        //var leftoffset = scrolledX + centerX;
        //var topoffset = scrolledY + centerY;
        
        var leftoffset = scrolledX + (centerX - 250)/2;
        var topoffset = scrolledY + (centerY - 150)/2;
		
		var obj = $get(this._targetControlID);
		
		if (obj)
		{
			var bounds = Sys.UI.DomElement.getBounds(obj);
			
			//Sys.UI.DomElement.setLocation(this.get_element(), bounds.x + 100, bounds.y - 50);
			
			Sys.UI.DomElement.setLocation(this.get_element(), Math.round(leftoffset), Math.round(topoffset));
		}
		
		this.set_visible(true);
		
		$find(this.get_showAnimationID()).OnClick();
		
		this._timer.set_enabled(true);
    },
    
    hide : function()
    {
		this.set_visible(false);
    },
    
    setText : function(textValue)
    {
		this._infoTextHolder.innerHTML = textValue;
    },
    
    _close : function(e)
    {
		this._timer.set_enabled(false);

		$find(this.get_closeAnimationID()).OnClick();
    },
    
    _onTick : function()
    {
		this._timer.set_enabled(false);

		$find(this.get_closeAnimationID()).OnClick();
    },
    
    _createLayout : function()
    {
		this._frame  = this.get_element();
		
		this._frame.style.position = "absolute";
		this._frame.style.zIndex = "5000";
		this._frame.style.fontSize = "11px";
		this._frame.style.padding = "5px";
		this._frame.style.width = "250px";
		
		var objOuterFrame = document.createElement('div');
		objOuterFrame.className = "InfoMsgHeader";
		this._frame.appendChild(objOuterFrame);
		
		var objShadow = document.createElement('div');
		objShadow.className = "InfoMsgShadow";
		this._frame.appendChild(objShadow);
		
		var objWrapper = document.createElement('div');
		objWrapper.className = "InfoMsgBodyWrapper";
		objShadow.appendChild(objWrapper);
		
		var objBodyHeader = document.createElement('div');
		objBodyHeader.className = "InfoMsgBodyHeader";
		objWrapper.appendChild(objBodyHeader);
		
		this._closeButton = document.createElement("img");
		objBodyHeader.appendChild(this._closeButton);
		this._closeButton.src = this._closeButtonImage;
		this._closeButton.alt = this._closeButtonToolTipText;
		
		$addHandler(this._closeButton, "click", this._closeHandler);
		
		var objBodyContent = document.createElement('div');
		objBodyContent.className = "InfoMsgContent";
		objWrapper.appendChild(objBodyContent);
		
		this._infoTextHolder = document.createElement('span');
		objBodyContent.appendChild(this._infoTextHolder);
		
		this._isCreated = true;
    }
}

// register the class
JetShop.StoreControls.AddToCartInformationPopup.registerClass('JetShop.StoreControls.AddToCartInformationPopup', Sys.UI.Control);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();