$(document).ready(function() {
	appStart();
});


var command_location ="";

function appStart() { 

	components_selector_binding();


}

/* this is sort of the early stage to the declaratie approach that allows 
   events, bindings, markup transformations ( ala trmplate style ) and events based
   transformations in runtme with declarative annotations */

function components_selector_binding() { 

	/* We can move all this to be events-based. So then if you need to kick start a bunch of things
 	in startup time, yu just kick the events */

	components_apply("div.button.navigation", class_components_hoverEntry, "togglePanel" );

	components_apply(".button", class_components_hoverEntry, null);
	components_apply(".button", class_components_execInnerClick, null ) ;

} 

function components_apply(a,b,c) { 

	$(a).each( function() {
                 b($(this),c);

	});

	
	//b($(a), c);	
}


// Synchronous
function addEvent(evtObj, typeEvent) { 
	runEvents(evtObj, typeEvent);
} 

var eventsHash = new Array();

function events_apply( eventType, functionCallback, param) { 

	// need to fix this to support hash of hash?
	eventsHash[eventType] = { callback: functionCallback, param:param } 
	
} 

function runEvents( evtObj, typeEvent )  { 
	eventsHash[typeEvent].callback( evtObj.attr( eventsHash[typeEvent].param ) );	
} 

function class_components_execInnerClick ( currObj ) { 
  currObj.find("a").click( function () { return false;  } );
  var innerAnchor = currObj.find("a").attr("onclick");
  currObj.click(function() {
       innerAnchor();	
   });
}

function class_components_clickInner ( currObj, followObj ) { 
  currObj.click(function() {
	if(followObj) { 
		followObj.callback();
	} 
   });
}  

function class_components_enablePanel ( id ) { 
	$("#"+id).css("display","block");
} 

function class_components_togglePanel ( id ) { 
	var targetElement = id.split("-")[1];
	$(".panel").css("display","none");
	$("#panel-"+targetElement).css("display","block");
} 


function class_components_hide( currObj) { 
	currObj.css("display","none");
} 

function class_components_hoverEntry( currObj, event) { 

   currObj.hover(function() {
                $(this).addClass("button-highlight");
			if(event) { 
			addEvent( $(this) , event);
			}
                },function(){
        $(this).removeClass("button-highlight");
   });

   currObj.click(function() {
   });

} 





