﻿Type.registerNamespace('Kingpin');

Kingpin.FeedbackTab = function(element) {	
	Kingpin.FeedbackTab.initializeBase(this, [element]);
	
	this._modalClickDelegate;
	this._modalPopup;
	this._button;
	this._cancelButton;
	this._hoverDelegate;
	this._unhoverDelegate;
};

Kingpin.FeedbackTab.prototype = {
	get_cancelButtonID : function() {
		return this._cancelButton?this._cancelButton.id:null;
	},
	
	set_cancelButtonID : function(value) {
		this._cancelButton = $get(value);
	},
		
	initialize : function() {
		Kingpin.FeedbackTab.callBaseMethod(this, 'initialize');
			
		var e = document.createElement('a');
		document.body.appendChild(e);		
		this._button = e;
		
		
		this._hoverDelegate = Function.createDelegate(this, this._hoverHandler);
		$addHandler(e, 'mouseover', this._hoverDelegate);
		
		this._unhoverDelegate = Function.createDelegate(this, this._unhoverHandler);
		$addHandler(e, 'mouseout', this._unhoverDelegate);
										
		e.style.position = 'fixed';
		e.style.right = '0';
		e.style.top = '40%';
		e.style.width = '36px';
		e.style.height = '100px';
		e.style.border = 'none';
		e.style.zIndex = '1000';
		e.style.cursor = 'pointer'
		
		this._modalPopup = $create(AjaxControlToolkit.ModalPopupBehavior, {"BackgroundCssClass":"modalBackground","DropShadow":false,"PopupControlID":this.get_element().id,"id": this.get_id() + "_modalPopup","CancelControlID": this.get_cancelButtonID()}, null, null, e); 
		
		if (this._modalPopup._backgroundElement) {
			this._modalClickDelegate = Function.createDelegate(this, this._modalClickHandler);
			$addHandler(this._modalPopup._backgroundElement, 'click', this._modalClickDelegate);
		}
		
		this._setBg('/App_Themes/TechIT/Images/feedbacktab.png');
	},
	
	dispose : function() {
		try {
			$removeHandler(this._modalPopup._backgroundElement, 'click', this._modalClickDelegate);
		}
		catch(e){}		
		$removeHandler(this._button, 'mouseout', this._unhoverDelegate);
		$removeHandler(this._button, 'mouseover', this._hoverDelegate);
									
		document.body.removeChild(this._button);		
		
		Kingpin.FeedbackTab.callBaseMethod(this, 'dispose');
	},
		
	_modalClickHandler : function() {
		this._modalPopup.hide();
	},
	
	_setBg : function(bg) {
		if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7) {
			this._button.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + bg + '", sizingMethod="crop");';
		}
		else {
			this._button.style.backgroundImage = "url('" + bg + "')";
		}
	},
	
	_hoverHandler: function() {
		this._setBg('/App_Themes/TechIT/Images/feedbacktab_ovr.png');
	},
	
	_unhoverHandler : function() {
		this._setBg('/App_Themes/TechIT/Images/feedbacktab.png');
	}
};

Kingpin.FeedbackTab.registerClass('Kingpin.FeedbackTab', Sys.UI.Behavior);