/**
 *  Updated 19.09.2011
 *  - escCancel;
 *  - zIndex functions;
 *  - fix movable functions;
 *  - compatiblity with IE;
 */
function popUp(options){
    this.checkIE = checkIE();
    this.minZ = this.calculateMinZ();
    this.active = false;
    this.cururl = null;
    this.bgDiv = null;
    this.popContainer = null;
    this.popDiv = null;
    this.titleDiv = null;
    this.waitingDiv = null;
    this.top = null;
    this.left = null;
    this.movable = false;
    this.preLoadAnimation = true;
    this.move = false;
    this.savePosition = false;
    this.cachedData = null;
    this.locked = 0;
    this.options = {
	title: '',
	data: 'new popup',
	params: {},
	bgDisplay: true,
	type: 'GET',
	callback: function(){},
        onclose: function(){},
	buttons: {},
	bgOpacity: '0.0',
	movable: false,
	preLoadAnimation: true,
	cache: false,
	savePosition: false,
	minimizeButton: false,
        inBackground: false,
        dataType: 'html',
        zPosition: 'auto',
        escCancel: true
    };
    this.postClear = false;
    this.userOptions = {};
    this.cache = false;
    this.minimizeButton = false;
    this.callback = function (){};
    this.maximizeImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8x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sAAAAACAAIAAABc0gJo5kaZ5oqq5s676OIsyC4rypMu28wkKLgXCwgJAEPJ7ggSg4C4gHaSGpWhfH5E6AiHi/CNLAah1ktYLC91sQk6vmERKtXkfao/E7Lpon03Z3bntnf3VreCJ6ZHwYfkqHbIOMhZCBiRiLZZVbkV6YmnCcE4B2oG8SjY+dl5ObclqknoJ5qKqxpYiuorB0rbWEvYa/irajuZLAlMKWprupx7OnwX24XXZhyq/VaExPUFIjVG9YzFs/QUNFxzgoOlo+7SYxNDU38vj5+u0hACH5BAkIABgALAAAAAAgACAAAAXIICaOZGmeaKqubOu+cCy30DLcwwIZhOVbBAPpgSgYC4gHaSFpOheEi3RKICEi2CyCNHA6B5bp1EIqZLMFrrcJFkvJI/M5kh511203XCQ/10V3Xnliexh9aGp4YXplc3SJgouEjXN/GIFfkmOUfpCZbheFh1iWmGyab5yIdmsSg5txjqWtr6mxlZ6noKKyua6ooaqkvrXBt52sirvCj8mRy8ergLRRblUjV3Nbzl88P0BCI0RHSEojTGsLMyU1ODkQ6/Hy8/T19SEAIfkEBQgAGAAsAAAAACAAIAAABbAgJo5kaZ5oqq5s675wLM+iQVi4RRikneu80QNRKBYQD8JlySSQlMylc4SIWK8IS3RpIWm33VHhei18o2HRmZnGjMkR8/bSXnNJb7Ic7J2382V2dH18YnBxgnV+eId7aISPhnCObJCVknqJlneYgYsjmp1WlJxqnyKAo6GmhaiNqxiwqYinsbWzpIOgt6+1so1QUVMiwU0kVXAIPjk7PTfMQSJDRkcPNNfY2drb3N0kIQAh+QQFFAAYACwYAAYACAAUAAAFKKBBWKRFiFeqjqpKtukLyy3tWvBlx/jc179bbqcL8obG4pCQO41KpxAAOw==';
    this.closeImg = 'data:image/gif;base64,R0lGODlhDwAtAKIHANbe63aSu5itzMjT4////8HO4GWFs////yH5BAEAAAcALAAAAAAPAC0AAAN0eLrc/jAuQhp1tKr8OIfZJX1RqHUXyZDqdrpSLM8KUNx4jtt67/+9AUFHGPQyOOSRUlD6TMCb8welM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5paWQ6NkJERTczRDFCRjM5MTFFMEE2RTZFMkQxQzY4MjkxRjUiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NkJERTczRDJCRjM5MTFFMEE2RTZFMkQxQzY4MjkxRjUiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz7CxdvQAAAAP0lEQVR42mJsnbGfgYGB5eHT9yDq77//IOrffzD1H0YBSQYmBjBg+QdR8h9KMUA1gOUYoBQDVA5JH90ogAADAPV3HMUrJn8PAAAAAElFTkSuQmCC';
    this.title = 'popUp';
    this.data = '<div style="">\n\
		<h2>Wellcome to "popUp" object!</h2>\n\
		<p>You can configure this popup with folowing options: </p>\n\
		<p>([<b>string or url</b>], [{<b>object</b>} of options])</p>\n\
		<p>OPTIONS:</p>\n\
		<ul>\n\
		    <li>[<b>showTitle</b>] = "true": true or false, show/hide title bar.</li>\n\
		    <li>[<b>title</b>] = "popUp": string of popup title.</li>\n\
		    <li>[<b>left</b>] = automatic: int of left</li>\n\
		    <li>[<b>top</b>] = automatic: int of top</li>\n\
		    <li>[<b>preLoadAnimation</b>] = "true": show or not animation before request complete.</li>\n\
		    <li>[<b>movable</b>] = "false": allow user to move popup.</li>\n\
		    <li>[<b>cache</b>] = "false": try to find loading data in a cache.</li>\n\
		    <li>[<b>bgColor</b>] = "#000": color of backgound.</li>\n\
		    <li>[<b>bgOpacity</b>] = "0.5": opacity of backgound.</li>\n\
		    <li>[<b>hideButton</b>] = "true": show or not close popup button.</li>\n\
		    <li>[<b>minBtn</b>] = "false": show or not minimize popup button.</li>\n\
		    <li>[<b>onclose</b>] = function(){}: function, that running after popup close.</li>\n\
		    <li>[<b>type</b>] = "GET": type of method to load url("POST" or "GET").</li>\n\
		    <li>[<b>params</b>] = {}: object of params to request (if popup get the url in first param)</li>\n\
		    <li>[<b>buttons</b>]: array of buttons object.\n\
			<ul>\n\
			    <li>[<b>value</b>]: string.</li>\n\
			    <li>[<b>clickFunction</b>]: function onclick this button</li>\n\
			    <li>[<b>id</b>]: if you want apply specific id</li>\n\
			</ul>\n\
		    </li>\n\
		    <li>[<b>callback</b>] = function(){}: function, that running after cnontent are loaded.</li>\n\
		</ul>\n\
		</div>';
    this.type = 'GET',
    this.params = {},
    this.bgDisplay = true;
    this.waitingStyle = {
        display: 'none',
        zIndex: this.minZ + 1,
        position:'fixed',
        width:'160px',
        height:'40px',
        backgroundColor:'#000',
        opacity:'0.5',
	textAlign: 'center',
	paddingTop: '20px',
	borderRadius: '5px',
	boxShadow:'0 0 10px #fff'
    };
    this.buttonsDiv = null;
    this.bgStyle = {
        display: 'none',
        zIndex: this.minZ,
        top:'0px',
        left:'0px',
        position:'fixed',
        width:'100%',
        height:'100%',
        backgroundColor:'#000',
        opacity:'0.0'
    };
    this.containerStyle = {
        display: 'none',
        zIndex: this.minZ + 1,
        top:'0px',
        left: '0px',
        position:'fixed',
        margin: '0px',
        boxShadow:'0 0 1px #fff',
        borderRadius:'8px',
        backgroundColor:'#fff',
	overflow: 'hidden',
	border: '10px solid rgba(82, 82, 82, 0.7)'
    };
    this.popStyle = {
        display: 'block',
        zIndex: this.minZ + 1,
        position:'relative',
        margin: '0px',
        padding: '10px',
	overflowY:'auto',
        overflowX:'hidden'
    };
    this.titleStyle={
        display:'block',
        zIndex: this.minZ + 1,
        position: 'relative',
        top: '0px',
        left: '0px',
        height: '10px',
	fontFamily: '"lucida grande", "tahoma", "verdana", "arial", sans-serif',
        backgroundColor: '#6d84b4',
        boxShadow: '0 0 0 #3b5998',
        fontWeight: '700',
        color: '#fff',
        padding: '5px',
	paddingBottom: '10px',
        paddingLeft: '10px',
	paddingRight: '30px',
        fontSize: '14px',
	border: '1px solid #3b5998'
    };
    this.btnStyle={
        display:'block',
        zIndex: this.minZ + 1,
        position: 'absolute',
        top: '3px',
        right: '5px',
        width: '12px',
        height: '12px',
	overflow: 'hidden',
        borderTopRightRadius: '10px',
        fontWeight: '600',
        color: '#fff',
        padding: '2px',
        fontSize: '10px',
	cursor: 'pointer'
    };
    this.mnmzStyle={
        display:'none',
        zIndex: this.minZ + 1,
        position: 'absolute',
        top: '3px',
        right: '22px',
        height: '12px',
	overflow: 'hidden',
        borderTopRightRadius: '10px',
        fontWeight: '600',
        color: '#fff',
        padding: '2px',
        fontSize: '10px',
	cursor: 'pointer'
    };
    this.maximizeStyle={
        display:'none',
        zIndex: this.minZ + 1,
        position: 'absolute',
        top: '3px',
        right: '17px',
        width: '12px',
        height: '12px',
	overflow: 'hidden',
        borderTopRightRadius: '10px',
        fontWeight: '600',
        color: '#fff',
        padding: '3px',
        fontSize: '10px',
	cursor: 'pointer'
    };
    
    this.buttonsDivStyle = {
	display: 'block',
	position: 'relative',
	padding: '5px',
	textAlign: 'right',
	background: 'none repeat scroll 0 0 #F2F2F2',
	borderTop: '1px solid #CCCCCC'
    };
    this.miniDivStyle = {
	display: 'none',
	position: 'fixed',
	fontFamily: '"lucida grande", "tahoma", "verdana", "arial", sans-serif',
        backgroundColor: '#6d84b4',
	right: '2px',
	bottom: '0px',
	color: '#fff',
	fontWeight: '700',
	padding: '4px',
	border: '2px solid #868686',
	fontSize: '11px'
    };
    this.btnElementStyle = {
	background: 'none repeat scroll 0 0 #4F6AA3',
	borderBottomColor: '#29447E',
	color: '#FFFFFF',
	fontSize: '13px',
	fontFamily: "'Lucida Grande',Tahoma,Verdana,Arial,sans-serif",
	fontWeight: 'bold',
	marginLeft: '2px',
	marginRight: '2px',
	outline: 'medium none',
	whiteSpace: 'nowrap',
	borderStyle: 'solid',
	lineHeight: 'normal',
	textAlign: 'center',
	textDecoration: 'none',
	height: 'auto',
	borderColor: '#29447E #29447E #1A356E',
	borderWidth: '1px',
	padding: '2px 6px',
	backgroundImage: 'url('+this.btnBackgroundImg+')',
	backgroundRepeat: 'repeat-x',
	cursor: 'pointer'
    };
    this.lockDivStyle = {
	backgroundColor: '#000',
	opacity: '0.1',
	position: 'absolute',
	width: '100%',
	height: '100%',
	display: 'none',
	top: '0px',
	left: '0px',
	zIndex: this.minZ + 2
    };
    this.inBackground = false;
    this.lockDiv = null;
    this.init();
    this.setOptions(options);
    this.history = new Array;
    this.buttons = null;
    this.onclose = function(){};
}
popUp.prototype.calculateMinZ = function(){
    var brosers = getObjectsByClass(popUp);
    var minZ = 1;
    for (var i in brosers){
        if (brosers[i].minZ >= minZ && brosers[i].active == true){
            minZ = brosers[i].minZ + 1;
        }
    }
    return minZ+1;
}
popUp.prototype.setZPosition = function(minZ){
    if (minZ == 'auto')
        minZ = this.minZ;
    this.bgDiv.style.zIndex = minZ;
    this.waitingDiv.style.zIndex = minZ*1 + 1;
    this.popContainer.style.zIndex = minZ*1 + 1;
    this.popDiv.style.zIndex = minZ*1 + 1;
    this.titleDiv.style.zIndex = minZ*1 + 1;
    this.closeBtn.style.zIndex = minZ*1 + 1;
    this.minimizeBtn.style.zIndex = minZ*1 + 1;
    this.minMinimizeBtn.zIndex = minZ*1 + 1;
    this.lockDiv.style.zIndex = minZ*1 + 2;
    this.minZ = minZ;
}
popUp.prototype.preLoad = function(){
    if (this.bgDisplay == true) $(this.bgDiv).fadeIn('fast');
    this.showWaiting();
}
popUp.prototype.load = function(string, options){
        if (this.bgDiv==null && this.popDiv==null)this.init();
	this.data = string || this.data;
	if (typeof(options) == 'object' && options.cache == true){
	    var data = this.getCache(this.data, options);
	    if (data != false){
		this.data = data;
	    }
	}
	if (typeof(options) == 'object' && options.savePosition == true && this.left && this.top){
	    options.left = parseInt(this.popContainer.style.left);
	    options.top = parseInt(this.popContainer.style.top);
	}
	
	this.setOptions(options);
        this.setActions();
	this.createButtons();
	if (this.preLoadAnimation == true) 
	    this.preLoad();
	var that = this;
	if (this.movable == true)
	    this.activateMove();
	else
	    this.deactivateMove();
	if (this.locked == 1) this.unlock();
        if (this.data.match(/^[a-z0-9\/\?\.=&:\-_]{1,100}$/)){
	    this.url = this.data;
            $.ajax({
                type: that.type,
                url: that.data,
		data: that.params,
                dataType: that.dataType,
                success: function(responseText, xmlHttpObj){
                    try{
                        that.popDiv.innerHTML = '';
                        if (that.dataType != 'json'){
                            try {
                                $(that.popDiv).html(responseText)  
                            } catch (e) {
                                that.popDiv.innerHTML = responseText;
                            }
                        }else{
                            $(that.popDiv).html(that.data);
                        }  
                        that.history.push({data:that.data, content:responseText,params: that.params});
                        if (that.preLoadAnimation == true) 
                            that.hideWaiting();
                        if (/*that.minimized != true &&*/ that.inBackground != true)
                            that.show();
                        that.callback(responseText);
                    }catch(error){
                        showObject(error);
//                        that.setContent(error.message); 
//                        that.show();
                    }
                },
                error: function(xmlHttp, textStatus, errorThrown){
		    that.hideWaiting();
                    that.setContent(getErrorText(xmlHttp, textStatus, errorThrown));    
                    that.show();
		}
            });
        }else{
	  this.popDiv.innerHTML = '';
	  $(that.popDiv).html(this.data);
	  this.history.push({data:this.data,content:this.data, params: {}});
	  this.hideWaiting();
          if (/*that.minimized != true && */that.inBackground != true)
                this.show(); 
	  this.callback();
        }
        this.setZPosition(this.calculateMinZ());
    };
popUp.prototype.setContent = function(string){
    if (string){
        $(this.popDiv).html(string);
        return true;
    }else{
        return false;
    }
}
popUp.prototype.getCache = function(url, options){
    for (var object in this.history){
	var currentParams = (this.history[object].params)?(this.history[object].params):({});
	var newParams = (options.params)?(options.params):({});
	var flagParams = compareObjects(currentParams, newParams);
	if (this.history[object].data == url && flagParams){
	    var content = this.history[object].content;
		return content;
	}    
    }
    return false; 
} 
popUp.prototype.setUserOptions = function(options){
    if (typeof (options) == 'object' && typeof(options.from) == 'undefined')
	this.userOptions = options;
}
popUp.prototype.reload = function(){
    if (this.url){
	var options = this.userOptions;
	    options.cache = false;
	    options.from = 'me';
	    options.left = parseInt(this.popContainer.style.left);
	    options.top = parseInt(this.popContainer.style.top);
            options.inBackground = true;
	if (isScript('waiting.js')){
	    var that = this;
	    this.meWaiting = new waiting();
	    this.meWaiting.load(this.popContainer);
	    var thisCallback = function(){};
	    if (typeof(options.callback)=='function')
		thisCallback = options.callback;
	    
	    options.callback = function(){
		thisCallback();
		that.meWaiting.hide();
	    }
	}
	this.load(this.url, options);
    }
}
popUp.prototype.createButtons = function(buttons){
    var buttons = buttons || this.buttons;
    this.buttonsDiv.innerHTML = '';
    if (typeof(buttons) == 'object' && buttons != null){
	
	for (var button in buttons){
	    if (typeof (buttons[button] == 'object')){
		var btnElementId = '';
		if (buttons[button].id){
		    btnElementId = buttons[button].id;
		}else{
		    var uid = Math.floor(Math.random()*0x100000).toString(16);
		    btnElementId = 'button_' + uid;
		}
		var btnElementStyle = this.btnElementStyle;
		if (typeof(buttons[button].style) == 'object')
		    btnElementStyle = buttons[button].style;
		var btnElement = cE('button', {id:btnElementId, className: 'popup_button'}, btnElementStyle);
		if (typeof(buttons[button].clickFunction) == 'function')
		    btnElement.onclick = buttons[button].clickFunction;
		var value = 'button';
		if (buttons[button].value)
		    value = buttons[button].value;
		    btnElement.innerHTML = value;   
		this.buttonsDiv.appendChild(btnElement);
	    }
	}
	this.buttonsDiv.style.display = 'block';
    }else{
	this.buttonsDiv.style.display = 'none';
    }
};
popUp.prototype.hideButtons = function(num, animate){
    var buttons = this.buttonsDiv.getElementsByTagName('button');
    var animate = animate || false;
    if (num){
	if (buttons[num-1])
	    if ($ && animate == true)
		$(buttons[num-1]).slideUp('normal');
	    else
		buttons[num-1].style.display = 'none';
            return true;
    }else{
        if ($ && animate == true)
            $(buttons).slideUp('normal');
        else
            for (var i=0; i<buttons.length; i++){
                buttons[i].style.display = 'none';
            }
        return true;
    }
}
popUp.prototype.showButtons = function(num, animate){
    var buttons = this.buttonsDiv.getElementsByTagName('button');
    var animate = animate || false;
    if (num){
	if (buttons[num-1])
            if ($ && animate == true)
		$(buttons[num-1]).slideDown('normal');
	    else
		buttons[num-1].style.display = 'inline-block';
    }else{
        if ($ && animate == true)
            $(buttons).slideDown('normal');
        else
            for (var i=0; i<buttons.length; i++){
                buttons[i].style.display = 'inline-block';
            }
        return true;
    }
}
popUp.prototype.init = function(){
        var that = this;
        var uid = Math.floor(Math.random()*0x100000).toString(16);
	var waitingId = 'waitingDiv_' + uid;
        var bgId = 'bgDiv_' + uid;
	var contId = 'contDiv_' + uid;
        var popId = 'popDiv_' + uid;
        var btnId = 'btnCls_' + uid;
	var btnMinId = 'btnMnmz_' + uid;
	var minDivId = 'minDiv_' + uid;
        var titleId = 'titleDiv_' + uid;
	var buttonsDivId = 'butonsDiv_' + uid;
	var minimizedBtnId = 'minimizedBtn_' + uid;
	var minimizedMinBtnId = 'minimizedMinBtn_' + uid;
	var minTitleDivId = 'minTitleDiv_' + uid;
	var lockDivId = 'lockDiv_' + uid;
	
	this.waitingDiv = cE('div',{id:waitingId, className: 'popup_waiting_div'},this.waitingStyle);
        this.waitingDiv.innerHTML = '<img src="' + this.waitingImg +'"/>';
        this.bgDiv = cE('div',{id:bgId, className: 'popup_bg_div'},this.bgStyle);
	this.popContainer = cE('div',{id:contId, tabIndex: '0', className: 'popup_pop_container'},this.containerStyle);
        this.popDiv = cE('div',{id:popId, className: 'popup_content_div'},this.popStyle);
	this.buttonsDiv = cE('div', {id: buttonsDivId, className: 'popup_buttons_div'}, this.buttonsDivStyle);
        this.titleDiv = cE('div',{id:titleId, className: 'popup_title_div'},this.titleStyle);
        this.titleDiv.innerHTML = this.title;
        this.closeBtn = cE('div', {id:btnId, className: 'popup_close'},this.btnStyle);
        this.closeBtn.innerHTML = '<img src="' + this.closeImg + '"/>';
	this.minimizeBtn = cE('div', {id:btnMinId, className: 'popup_minimize'},this.mnmzStyle);
        this.minimizeBtn.innerHTML = '<img src="' + this.minimizeImg + '"/>';
	this.lockDiv = cE('div', {id: lockDivId, className: 'popup_lock'}, this.lockDivStyle);
	this.miniDiv = cE('div', {id:minDivId, className:'popup_minimized_div'}, this.miniDivStyle);
	this.minTitleDiv = cE('div', {id:minTitleDivId, className: 'popup_minimized_title'},{display:'inline-block', marginRight: '55px'});
	this.minTitleDiv.innerHTML = this.title;
	this.minCloseBtn = cE('div', {id:minimizedBtnId, className: 'popup_minimized_close'},this.btnStyle);
	this.minCloseBtn.innerHTML = '<img src="' + this.closeImg + '"/>';
	this.minMinimizeBtn = cE('div', {id:minimizedMinBtnId, className: 'popup_minimized_minimize'},this.maximizeStyle);
	this.minMinimizeBtn.innerHTML = '<img src="' + this.maximizeImg + '"/>';
	this.miniDiv.appendChild(this.minTitleDiv);
	this.miniDiv.appendChild(this.minCloseBtn);
	this.miniDiv.appendChild(this.minMinimizeBtn);
        this.popDiv.innerHTML = '';
	this.popContainer.appendChild(this.titleDiv);
	this.popContainer.appendChild(this.closeBtn);
	this.popContainer.appendChild(this.minimizeBtn);
        this.popContainer.appendChild(this.popDiv);
        this.popContainer.appendChild(this.buttonsDiv);
	this.popContainer.appendChild(this.lockDiv);
        this.popDiv.innerHTML = this.data;
	document.body.appendChild(this.miniDiv)
        document.body.appendChild(this.bgDiv);
        document.body.appendChild(this.popContainer);
	document.body.appendChild(this.waitingDiv);
        
    };

popUp.prototype.deactivateMove = function (){
    var that = this;
    that.titleDiv.onmousedown = function(){
    }
    that.titleDiv.onmouseup = function(){
    }
    that.titleDiv.onmousemove = function(){
    }
    that.popContainer.onmouseup = function(){

    }
}
popUp.prototype.activateMove = function(){
    var that = this;
    that.movePop = function(event){
	var event = event || window.event;
	var moveX = that.currentX + (event.clientX - that.cursorPositionX);
	var moveY = that.currentY + (event.clientY - that.cursorPositionY);
	if (that.moveNow == true){
	    that.popContainer.style.left = moveX + 'px';
	    that.popContainer.style.top = moveY + 'px';
	}
    }
    that.upMouse = function (e){
	that.titleDiv.style.cursor = 'default';
	that.moveNow = false;
	that.left = parseInt(that.popContainer.style.left);
	that.top = parseInt(that.popContainer.style.top);
	$(document).unbind('mouseup', that.upMouse);
	$(document).unbind('mousemove', that.movePop);
    }
    that.titleDiv.onmousedown = function(e){
	var e = e || window.event;
	this.style.cursor = 'move';
	that.moveNow = true;
	that.currentX = parseInt(that.popContainer.style.left);
	that.currentY = parseInt(that.popContainer.style.top);
	that.cursorPositionX = e.clientX;
	that.cursorPositionY = e.clientY;
	$(document).bind('mousemove', that.movePop);
	$(document).bind('mouseup', that.upMouse);
    } 
}    
popUp.prototype.show = function(){
	var that = this;
        if (this.minimized == true) this.maximize();
        if (this.bgDiv==null && this.popContainer==null)this.init();
	$(this.waitingDiv).css({display: 'none'});
	$(this.popContainer).fadeIn('fast', function(){that.active = true});
	this.centralize();
        $(this.popContainer).focus();
};
popUp.prototype.minimize = function(){
    this.minimized = true;
    $(this.popContainer).fadeOut('fast');
    var right = 2 + this.getRightPosition();
    $(this.miniDiv).css({right:right+'px'});
    $(this.miniDiv).fadeIn('fast');
}
popUp.prototype.getRightPosition = function(){
    var right = 0;
    var objects = $('*').filter(function() { 
	return $(this).css('position') == 'fixed' && $(this).css('display') == 'block' && parseInt($(this).css('bottom')) == '0' && parseInt($(this).css('right')) < '140';
    }); 
    if (objects.length>0){
	for (var i=0; i<objects.length; i++){
	    right = right + parseInt(objects[i].style.right);
	    right = right + objects[i].clientWidth*1;
	}
	right = right*1+4;
    }
    
    return right;
}
popUp.prototype.moveMyBrotherRight = function(){
    var myWidth = this.miniDiv.clientWidth + parseInt(this.miniDiv.style.right);
    var objects = $('*').filter(function() { 
	return $(this).css('position') == 'fixed' && $(this).css('display') == 'block' && parseInt($(this).css('bottom')) == '0' && parseInt($(this).css('right')) > myWidth;
    });
    if (objects.length>0){
	$(objects).animate({right:-myWidth});
    }
    
}
popUp.prototype.maximize = function(){
    var that = this;
    this.minimized = false;
    $(this.popContainer).fadeIn('fast');
    
    $(this.miniDiv).fadeOut('fast', function(){
	that.moveMyBrotherRight();
    });
}
popUp.prototype.hideMinimized = function(){
    $(this.miniDiv).fadeOut('fast');
}
popUp.prototype.hide = function(){
	var that = this;
	that.hideWaiting();
	that.hideMinimized();
        $(this.bgDiv).fadeOut('fast');
        $(this.popContainer).fadeOut('fast',function(){
	    that.active = false;
            that.minimized = false;
	    that.onclose();
	    if (that.postClear == true){
		that.clearMe();
	    }
	});
    },
popUp.prototype.setOptions = function(options){
	if (typeof(options) == 'object'){
		var that = this;
		that.setUserOptions(options);
                if (options.escCancel == false) this.escCancel = options.escCancel; else this.escCancel = this.options.escCancel;
		if(options.postClear == false){
			this.postClear = false;
		}
		if(options.postClear == true){
			this.postClear = true;
		}
		if(options.bgDisplay == false){
			this.bgDisplay = false;
			this.bgDiv.style.display = 'none';
			}
		if(options.bgDisplay == true){
			this.bgDisplay = true;
			if (this.active == true)this.bgDiv.style.display = 'block';
			}
                if (options.inBackground) this.inBackground = options.inBackground; else this.inBackground = this.options.inBackground;
                if (options.dataType) this.dataType = options.dataType; else this.dataType = this.options.dataType;
                if (options.zPosition) {this.zPosition = options.zPosition;} else {this.zPosition = this.options.zPosition;}
                    this.setZPosition(this.zPosition);
		if (options.top) this.top = options.top;
		if (options.left) this.left = options.left;
		if (options.bgOpacity)this.bgDiv.style.opacity = options.bgOpacity;
		    else
			this.bgDiv.style.opacity = this.options.bgOpacity;
		if(options.bgColor)this.bgDiv.style.backgroundColor = options.bgColor;
		if(options.width){
		    this.popContainer.style.width = options.width;
		    this.width = options.width;
		};
		if(options.height){
		    this.popContainer.style.height = options.height;
		    this.height = options.height;
		};
		if(options.type)this.type = options.type; else this.type = this.options.type;
		if(options.preLoadAnimation == false || options.preLoadAnimation == true)this.preLoadAnimation = options.preLoadAnimation; else this.preLoadAnimation = this.options.preLoadAnimation;
		if(options.params && typeof(options.params)=='object')this.params = options.params; else this.params = this.options.params;
		if(options.movable) this.movable = options.movable; else  this.movable = this.options.movable;
		if(options.cache) {this.cache = options.cache} else  this.cache = this.options.cache;
		if(options.showTitle == true) {
		    this.titleDiv.style.display = 'block';
		}
		if(options.showTitle == false) {
		    this.titleDiv.style.display = 'none';
		}
		
		if(options.savePosition) {this.savePosition = options.savePosition} else  this.savePosition = this.options.savePosition;
                if(typeof(options.title) == 'string'){
                    this.title = options.title;
                    this.titleDiv.innerHTML = options.title;
		    this.minTitleDiv.innerHTML = options.title;
                }
		if(options.title == false){
                    this.titleDiv.style.display = 'none';
                }
		if(options.hideButton == false){
			
			this.closeBtn.style.display = 'none';
		}
		if(typeof(options.callback) == 'function'){
			this.callback = options.callback;
		}else{
                    this.callback = this.options.callback;
                }
		if(typeof(options.onclose) == 'function'){
			this.onclose = options.onclose;
		}else{
                    this.onclose = this.options.onclose;
                }
		if(options.minBtn == false){
			this.minimizeBtn.style.display = 'none';
			this.minMinimizeBtn.style.display = 'none';
		}
		if(options.minBtn == true){
			this.minimizeBtn.style.display = 'block';
			this.minMinimizeBtn.style.display = 'block';
		}
		if(options.hideButton == true){
			this.closeBtn.style.display = 'block';
		}
		if (typeof(options.buttons) == 'object')
		    this.buttons = options.buttons;
		else
		    this.buttons = null;
	}
    };
popUp.prototype.checkFB = function(){
    if (typeof(FB) != 'undefined' && typeof(FB.Canvas) != 'undefined'){
        var pageInfo = FB.Canvas.getPageInfo();
        if (pageInfo.clientHeight != 0 || pageInfo.clientWidth != 0){
            return pageInfo;
        }else{
            return false;
        }
    }else{
        return false;
    }
}
popUp.prototype.centralize = function(el){
	var el = el || this.popContainer;
	var maxHeight = (window.innerHeight)?(window.innerHeight):(document.documentElement.clientHeight)-50;//this.bgDiv.clientHeight-50-this.titleDiv.clientHeight;
	var maxWidth  = (window.innerWidth)?(window.innerWidth):(document.documentElement.clientWidth)-50;
	//TODO
    //TEMPORARY FIX FOR BLOCKING LOGIN
    /*var pageInfo = this.checkFB();
	if (pageInfo){
	    var maxFBHeight = pageInfo.clientHeight;
	    var currentScroll = pageInfo.scrollTop;
	   
	}*/
	var buttonsHeight = 0;
	    if (this.buttonsDiv.style.display != 'none')
		buttonsHeight = (this.buttonsDiv.innerHeight)?(this.buttonsDiv.innerHeight):(this.buttonsDiv.clientHeight);
        el.style.maxHeight = (maxHeight-25)+'px';
	el.style.maxWidth = (maxWidth-25)+'px';
	if (this.left && this.top && el == this.popContainer)
	    {
		var left = this.left;
		var top = this.top;
	    }else{
		
		var left = ((maxWidth/2)-(el.clientWidth/2)).toFixed(0);
		var top = 20;
        //TODO
        //TEMPORARY FIX FOR BLOCKING LOGIN
		/*if (maxFBHeight){
		    top = (maxFBHeight/2*1 - el.clientHeight/2*1).toFixed(0);
		    if (currentScroll)
			top = top*1 + currentScroll*1;
		    if (top<100)
			top = 100;
		}else{*/
		    top = ((maxHeight/2)-(el.clientHeight/2)).toFixed(0);
		//}
	    }
	el.style.left = left+'px';
	el.style.top = top+'px';
	if (el == this.popContainer)
	    {
		if (!this.width){
		    this.popContainer.style.width = (this.popContainer.clientWidth)?(this.popContainer.clientWidth):(this.popContainer.offsetWidth*1-20) + 'px';
		}
		if (!this.height){
		    this.popDiv.style.maxHeight = (maxHeight-top-100-buttonsHeight)+'px';
		}
	    }
    }
popUp.prototype.setActions = function(){
    var that = this;
    var btnId = this.closeBtn.id;
    var minBtnId = this.minimizeBtn.id;
    var minCloseBtnId = this.minCloseBtn.id;
    var minMiniId = this.minMinimizeBtn.id;
    var miniDivId = this.miniDiv.id;
    
    document.getElementById(btnId).onclick = function(){that.hide()};
    document.getElementById(btnId).getElementsByTagName('img')[0].onclick = function(){that.hide()}; 
    document.getElementById(minBtnId).onclick = function(){that.minimize()};
    document.getElementById(minCloseBtnId).onclick = function(){that.hide()};
    document.getElementById(minMiniId).onclick = function(){that.maximize()};
    if (this.escCancel == true){
//        this.popContainer.onmouseover = function (){
//            this.focus();
//        }
//        this.popContainer.onmouseout = function (){
//            this.blur();
//        }
        this.popContainer.onkeypress = function (event){
            var event = event || window.event;
            if (event.keyCode == 27){
                that.hide();
            }
        }
    }
}
popUp.prototype.back = function(reload){
    var reload = reload || true;
    if (this.history[this.history.length-2]){
        if (reload==true){
            var data = this.history[this.history.length-2].data;
            this.history.splice(this.history.length-2,2);
            this.load(data);
        }else{
            var data = this.history[this.history.length-2].content;
            this.history.splice(this.history.length-2,2);
            this.load(data);
        }
    }
}    
popUp.prototype.showWaiting = function(){
    $(this.waitingDiv).fadeIn('fast');
    this.centralize(this.waitingDiv);
} 
popUp.prototype.hideWaiting = function(){
    $(this.waitingDiv).fadeOut('fast');
} 
popUp.prototype.lock = function(){
    if (this.active == true){
        $(this.lockDiv).fadeIn('normal');
    }else{
        this.lockDiv.style.display = 'block';
    }
    this.locked = 1;
}
popUp.prototype.unlock = function (){
    if (this.active == true){
        $(this.lockDiv).fadeOut('normal');
    }else{
        this.lockDiv.style.display = 'none';
    }
    this.locked = 0;
}
popUp.prototype.toggleLock = function (){
    if (this.locked == 1){
	this.unlock();
    }else{
	this.lock();
    }
}
popUp.prototype.clearMe = function(){
    this.popDiv.innerHTML = '';
    return true;
}
