function addScope(elem)
{
	window.open(URL+'/admin/content_scopes/add/popup:true',null,'width=500,height=420,scrollbars=yes');
}
function updateOptionsNow(type)
{	
	var scopeObjs = $('.scope_model_select option[value="'+type+'"]:selected').parent();
		scopeObjs.each(function(){
		var filterObject = $(this).parent().next().children('select');
		var presentValue = filterObject.val();
		$(this).bind("afterFetchingOptions",function(){
			filterObject.val(presentValue);
			$(this).unbind("afterFetchingOptions");
		})
		updateOptions($(this));
	})
}

$(function(){
	if(/\/admin\/modules\/+/.test(window.location.href) || typeof MODULE_EDITOR_MODE != "undefined")
	{
		$('.tabbed_module_select').live('beforeFetchingOptions',function(){
			$(this).data('dynamicOptionUrl','/cms/getOptions/ModuleTab.model/');
		})
	}
	
})

function setAsSortable(selector,itemsSelector,onFinish)
{
	$(selector).addClass('sortable_selector');
	$(selector).find(itemsSelector).addClass('ui-state-default').css({'font-size':'14px','height':'18px'});
	$(selector).sortable({items:itemsSelector,stop:onFinish,placeholder: 'ui-state-highlight'}).disableSelection();
}

function fbUserInitAfterCallback()
{
	FbHelper.perms = "email,user_about_me,user_website,user_location,user_hometown,user_birthday";
	FbHelper.loginUrl = URL+'/users/login/fbLogin:1';
	FbHelper.attachLoginEventIfNotLoggedIn(null,true);
}

function doUserFbLogin()
{
	FbHelper.login(function(){
		
		window.location = URL+'/users/login/fbLogin:1';
	})
}
