cghub.allowedToExecute = [
	'tb_remove', 'alert', 'invalidateFields', 'reloadCaptcha', 'resizeEnd',
	'pictureRemoved', 'updateProfileEnd_personalDetails', 'updateProfileEnd_personalDescriptions',
	'updateProfileEnd_backgroundImage'];
cghub.executeMethods = [];


cghub.executeMethods.tb_remove = function(refresh, redirect, alertMsg) {
	if (typeof alertMsg != 'undefined' && alertMsg) {
		alert(alertMsg);
	}
	
	if (typeof refresh != 'undefined' && refresh == 'refresh') {
		self.parent.cghub.refreshPage();
	}
	
	if (typeof redirect != 'undefined' && redirect != null && redirect != 'null' && redirect != false && redirect != 'false') {
		self.parent.cghub.redirect(redirect);
	}
	
	self.parent.tb_remove();
};


cghub.executeMethods.alert = function(alertMsg) {
	if (typeof alertMsg != 'undefined' && alertMsg) {
		alert(alertMsg);
	}
};



cghub.executeMethods.invalidateFields = function(errors) {
	cghub.invalidateFields(errors);
};

cghub.executeMethods.reloadCaptcha = function(){
	$('img[src*="/captcha/"]').each(function(){
		$(this).attr('src', '/captcha/?'+Math.random());
	})
};


cghub.executeMethods.pictureRemoved = function(model, field, id, oldObjectField) {
	setTimeout(function(){
		cghub.executeMethods.pictureRemoved[model][field](id, oldObjectField);
	}, 1000);
};
cghub.executeMethods.pictureRemoved.Profile = {
	'avatar': function(id, oldAvatar) {
		var cookie = {
			'id':id,
			'avatarUrl':{
				'thumb':'/img/no_avatar.gif',
				'large':'/img/no_avatar100.gif'
			}
		};
		cookie = escape(JSON.stringify(cookie));
		createCookie('liveAvatarUrl', cookie, 7);

		$(self.parent.document).find('#avatar_for_change,#avatarImg').attr('src', '/img/no_avatar100.gif');
			
		self.parent.cghub.user.id = id;
		self.parent.cghub.user.avatarUrl = {'thumb':'/img/no_avatar.gif','large':'/img/no_avatar100.gif'};
			
		cghub.user.liveAvatarUrl();
		
		cghub.executeMethods.tb_remove(false);
	},

	'company_image': function(id, oldComImage) {
		$(self.parent.document).find('img[src="'+oldComImage.large+'"]').hide();
		$(self.parent.document).find('#ProfileCompanyImage').val('');
		
		cghub.executeMethods.tb_remove(false);
	},
	'photo': function(id, oldPhoto) {
		$(self.parent.document).find('img[src="'+oldPhoto.large+'"]').attr('src', '/img/no_avatar100.gif');
        $(self.parent.document).find('#AvatarPhotoSelector').hide().children(':first').addClass('on').next().removeClass('on');
        $(self.parent.document).find('#photoImg').hide().removeClass('on');
        $(self.parent.document).find('#avatarImg').show().addClass('on');

		cghub.executeMethods.tb_remove(false);
	},
	'company_image_big': function(id, oldComImageBig) {
		$(self.parent.document).find('img[src="'+oldComImageBig.large+'"]').hide();
		
		cghub.executeMethods.tb_remove(false);
	},

	'profile_image': function(id, oldProfileImage) {
		$(self.parent.document).find('img[src="'+oldProfileImage.large+'"]').hide();
		$(self.parent.document).find('#profile_image_for_change').hide();

		$('.tooltip_span.remove').hide();

		cghub.executeMethods.tb_remove(false);
	},
	'bg_image': function(id, oldProfileImage) {
		return cghub.executeMethods.updateProfileEnd_backgroundImage();
	}
};


cghub.executeMethods.updateProfileEnd_personalDetails = function() {
	$.ajax({
		'type':'GET',
		'url':'/profiles/personalDetails/render_profile_element:true/?call=ajax',
		'cache':false
	}).success(function(response){
		$('#profile_personal_details').replaceWith(response);
		cghub.executeMethods.tb_remove(false);
	});
};

cghub.executeMethods.updateProfileEnd_personalDescriptions = function() {
	$.ajax({
		'type':'GET',
		'url':'/profiles/personalDescriptions/render_profile_element:true/?call=ajax',
		'cache':false
	}).success(function(response){
		$('#profile_about').replaceWith(response);
		cghub.executeMethods.tb_remove(false);
	});
};

cghub.executeMethods.updateProfileEnd_backgroundImage = function() {
	$.ajax({
		'type':'GET',
		'url':'/profiles/bgImage/get_bg_data_json:true/?call=ajax',
		'cache':false,
		'dataType':'json' //!
	}).success(function(response){
		var style = '';
		if (typeof response.image != 'undefined' && response.image) {
			style += "background-image: url('" + response['image'] + "') !important; ";
			if (response.repeat) {
				style += "background-repeat: " + response.repeat + " !important; "
			}
			if (response.color) {
				style += "background-color: " + response.color + " !important; "
			}
			if (response.align) {
				style += "background-position: " + response.align + " 0px !important; "
			}
			style += "background-attachment:fixed !important;";
		}

		$('body#body').attr('style', style);
		cghub.executeMethods.tb_remove(false);
	});
};
