//------------------ Functionality ---------------------------------
function bind_ui_mda(bar_vl, app_page){
	
	//creating the menus
	create_json_menus(json_menus,{for_menu:'0',present_in:'1'});
		
	//we now call the additional features we need for the json menus
	$$('#ul_menu0 li a').each(function(item){
		temp = "<span>" + $(item).innerHTML + "</span>";
		$(item).update("");
		$(item).insert({'top':temp});
	});

	
	app_progress = new JS_BRAMUS.jsProgressBar($('app_progressbar'), bar_vl, {animate: true, width: 138, height: 19, boxImage:'/reg/templates/mda/images/bg-bar.gif', barImage:'/reg/templates/mda/images/bg-bar-l.gif'})
		
	//setting the functionality of the progress bar
	if ($('app_status_bar')){
		$('app_status_bar').observe('click',function(event){
			
			if (logged_in_full()){
				Event.stop(event);
				pa_load_page(app_page)
		//	}else{
		//		new login_lightbox({first:'login'});	
			}
		});
	}
  
			
	if (typeof(login_lightbox_isloaded)!='function'){
		LazyLoad.js("/reg/login/login_lightbox.js");
	}
			
	//------------------- Login functions and actions ----------------------------
	
						
	//binding the login links
	if($('username_link')){
		$('username_link').observe('click',function(event){
			Event.stop(event);
			new login_lightbox({first: 'login'});
		});
	}
	
	
	if($('logout_link')){
		$('logout_link').observe('click',function(event){
			Event.stop(event);
			url=$('logout_link').href;
			new Ajax.Request(url, {
				onSuccess: function() {
					window.location.reload();
				}
			});
		});
	}
	
	
	//binding the login links
//	if($('reg_button_link')){
//		$('reg_button_link').observe('click',function(event){
//			Event.stop(event);
//			new login_lightbox({first: 'reg'});
//		});
//	}
	
//	if($('login_button_link')){
//		$('login_button_link').observe('click',function(event){
//			Event.stop(event);
//			new login_lightbox({first: 'login'});
//		});
//	}
	
	
	//uploading facebook sdk
	window.fbAsyncInit = function() {
		FB.init({appId: '134301923272648', status: true, cookie: true,
				xfbml: true});
	};
	(function() {
		var e = document.createElement('script'); e.async = true;
		e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
		document.getElementById('fb-root').appendChild(e);
	}());
	
	
	
	//enabling share buttons
	$$('a.share_btn').invoke('observe','click', share_function);
	
}


//this function does all the share abilities
	function share_function(){
		var t = escape(document.title);
		var u = escape(document.URL);
		
		$('facebook_share').href="http://www.facebook.com/sharer.php?u=" + u + "&t=" + t;
		$('delicious_share').href="http://delicious.com/post?url=" + u + "&title=" + t + "&notes="
		//$('stumbleupon_share').href="http://www.stumbleupon.com/submit?url=" + u + "&title=" + t
		$('twitter_share').href="http://twitter.com/home?status=Currently reading " + u;
		$('google_share').href="http://www.google.com/bookmarks/mark?op=edit&bkmk=" + u + "&title=" + t + "&annotation="
	}