Core = {
	__doAction: function(name){
		$('<input type="hidden">').attr('name', name).attr('value', name).appendTo('#PostBackForm');
		$('#PostBackForm').get(0).submit();
	},
	__uploadFile: function(name, postUpload){
		$("#" + name + "_loader").ajaxStart(function(){
			$("#" + name + "_ErrorLabel").html('');
			$(this).show();
		}).ajaxComplete(function(){
			$(this).hide();
		});
		$.ajaxFileUpload({
			url: '/api/content/upload/',
			secureuri: false,
			fileElementId: name,
			dataType: 'json',
			param: {
				elementName: name
			},
			success: function(data, status){
				if (typeof(data.error) != 'undefined') {
					$("#" + name + "_ErrorLabel").html(data.error);
				}
				else{
					postUpload();
				}
			},
			error: function(data, status, e){
				$("#" + name + "_ErrorLabel").html(e);
			}
		});
	},
	__createItemList: function(listLocal, controlName, view){
		$('#'+controlName+'_gallery').show();
		$(listLocal).each(function(){
			$('<div></div>')
				.attr('class', 'galleryItemView')
				.attr('id', controlName + 'galleryControl_' + this.id)
				.appendTo('#'+controlName+'_gallery');
			$('<div></div>')
				.attr('id', controlName + 'galleryItem_' + this.id)
				.attr('number', this.id)
				.attr('class', 'galleryItemImage')
				.appendTo('#'+controlName+'galleryControl_' + this.id);
			if(view == 1){
				$('<a>')
					.attr('id', controlName + 'galleryLink_' + this.id)
					.attr('href', this.url)
					.appendTo('#'+controlName+'galleryItem_' + this.id);
				$('<img>')
					.attr('src', this.icon)
					.appendTo('#'+controlName+'galleryLink_' + this.id);
			}
			if(view == 2){
				$('<a>'+this.filename+'</a>')
					.attr('href', this.url)
					.appendTo('#'+controlName+'galleryItem_' + this.id);
			}
			$('<div><a href="#" onclick="return Core.__deleteUploadItem('+this.id+', param'+controlName+');"><img src="/images/remove.png" alt="remove" class="actionImage"></a></div>')
				.attr('id', 'command' + controlName + 'galleryItem_' + this.id)
				.attr('class', 'galleryCommandLayer')
				.appendTo('#' + controlName + 'galleryControl_' + this.id);
				
		});
	},
	__loadItems: function(param){
		$('#' + param.controlName + '_gallery').empty();
		$.post(
			'/api/content/',
			param,
			function(data)
			{
				Core.__createItemList(data.listContent, param.controlName, param.view);
			}, 'json'
		);
	},
	__deleteUploadItem: function(id, param){
		$.post(
			'/api/content/remove/',
			$.extend({id: id}, param),
			function(data){
				$('#' + data.controlName + 'galleryControl_' + data.id).hide();				
			}, 'json'
		);
		return false;
	},
	__goto: function(url){
		location.href = url;		
		return false;
	},
	__translate: function(source, receiver){
		$(source).bind('change', {receiver: receiver}, Core.__translateHandler);
	},
	__translateHandler: function(event){
		$.post('/api/translate/', {str: this.value}, function(data, status){ 
			$(event.data.receiver).val(data);
		}, 'json');
	},
	__equalHeight: function(css){
	    tallest = 0;
	    $(css).each(function() {
	        thisHeight = $(this).height();
	        if(thisHeight > tallest) {
	        tallest = thisHeight;
	        }
	    });
	     $(css).height(tallest);		
	},
	__zoomImage: function(url)
	{
		return true;
	},
	__initTinyMCE: function(name){
		tinyMCE.init({
			// General options
			mode : "textareas",
			theme : "advanced",
			plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
			language : 'ru',

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,justifyleft,justifycenter,justifyright,justifyfull,numlist,bullist,fontsizeselect,fontselect,formatselect,outdent,indent,image,link,unlink",
			theme_advanced_buttons2 : "",
			theme_advanced_buttons3 : "",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_resizing : true,
		});
	}
};
