/**
 * @filename map.js
 * 
 * @description 
 * 
 * @author Michael Bina
 * @email michael.bina@garmin.com
 *
 * Copyright(c) 2008, Garmin International
 */

function openPopUp(url, name, params) {
	var win = window.open(url, name, params);
}

var ActivityActionsComponentConstants = {
	actionButtons: {		
		SHARE: 'actionShare',
		EXPORT: 'actionExport',
		TCX: 'actionTcx',
		KML: 'actionKml',
		SEND_TO_DEVICE: 'actionSendToDevice'
	},
	
	dropDowns: {
		SHARE: 'shareDropDown',
		EXPORT: 'exportDropDown'
	},
	
	DISABLED_BUTTON_CLASS: 'disabled'
};

ActivityActionsComponent = function(){
	return {
		init : function(){
			this.activityService = new Garmin.service.ActivityClient();
			this.fields = Garmin.form.ActivityFormFields;
		
			this.getPageComponents();
			this.giveButtonsWings();
			this.initializeDropDownAwesomeness();
		},
		
		// Unused...?
		disableMenu: function(buttonElement) {
		    buttonElement.parent().hide();
		    buttonElement.addClass(ActivityActionsComponentConstants.DISABLED_BUTTON_CLASS);
		},
		
		// Unused...?
		enableMenu: function(buttonElement) {
		    buttonElement.parent().show();
			buttonElement.removeClass(ActivityActionsComponentConstants.DISABLED_BUTTON_CLASS);
		},
		
		getPageComponents : function() {
			this.shareButton = Ext.get(ActivityActionsComponentConstants.actionButtons.SHARE);
			
			this.exportButton = Ext.get(ActivityActionsComponentConstants.actionButtons.EXPORT);
			this.exportDropDown = Ext.get(ActivityActionsComponentConstants.dropDowns.EXPORT);
			
			this.tcxButton = Ext.get(ActivityActionsComponentConstants.actionButtons.TCX);
			this.kmlButton = Ext.get(ActivityActionsComponentConstants.actionButtons.KML);
			
			this.sendToDeviceButton = Ext.get(ActivityActionsComponentConstants.actionButtons.SEND_TO_DEVICE);	
		},
		
		initializeDropDownAwesomeness : function() {
			// Export Drop Down		
			Ext.each(
				[this.exportButton, this.exportDropDown],
				function(element) {
					element.on('mouseout', function() {
						this.exportDropDown.hide();
					}.bind(this));
				}.bind(this)
			);
			Ext.each(
				[this.exportButton, this.exportDropDown],
				function(element) {
					element.on('mouseover', function() {
						this.exportDropDown.show();
					}.bind(this));
				}.bind(this)
			);
		},
		
		giveButtonsWings: function() {
			this.actionizeButton(this.tcxButton, this.tcxActivity);
			if(this.kmlButton) this.actionizeButton(this.kmlButton, this.kmlActivity);
			this.actionizeButton(this.sendToDeviceButton, this.sendToDeviceActivity);
		},
		
		actionizeButton: function(element, fnc) {
			element.on('click', fnc.bind(this));
		},
		
		deactionizeButton: function(element, fnc) {
			//element.un('click', fnc.bind(this));
			element.removeAllListeners();
		},

        tcxActivity: function() {
            // TODO fill me in!
        },
        
        kmlActivity: function() {
           // TODO fill me in! 
        },
        
        sendToDeviceActivity: function() {
            // TODO fill me in!
        }
	 };
}();

Ext.EventManager.onDocumentReady(ActivityActionsComponent.init, ActivityActionsComponent, true);