/*
 * jQuery customzone module v1.0.0 - http://www.onlinetvcast.com/
 *
 *
 */

// FIXME: глобальный рефакторинг
 
 (function($) {
 	function Module_Customzone(options) {
 		var defaults = {};
        this.options = $.extend(defaults, options);
        
 		this.construct();
 	}
 	 	 	
 	Module_Customzone.prototype = {
 		construct: function() {
 			this.customzone_content = $('#customzone .content');
 			this.customzone_wrapper = $('#customzone_wrapper');
 			this.customzone			= $('#customzone');
			this.box 	 			= $(".box");
			this.loading 			= $('.loading', this.box);
			this.current_class		= null;
 		},
 		
 		setContentByRequestInCustomzone: function(url, customzone_type, callback) {		
 			var self = this;
			self.blockPage();
									
			$.ajax({
				url : url,
				type : "POST",
				dataType : 'html',
				timeout : 30000,
				error : function() {
					ajaxError();
				},
				success : function(html) {
					self.customzone.removeClass(self.current_class).addClass(customzone_type);
					self.current_class = customzone_type;
					self.customzone_content.html(html);
					self.loading.hide();
					self.customzone_wrapper.fadeIn('fast');
					if (callback) {
						callback();
					}								
				},
				complete : function() {
				},
				// Parametrs
				data : {}
			});
		},
		
		setCustomzoneContent: function(html) {
			var self = this;
			self.customzone_content.html(html);
		},
		
 		close: function() {
 			var self = this;
 			self.box.height(0);
			// Previous line is not always hides loading (such as twitter login)
			self.loading.hide();
			self.customzone_wrapper.fadeOut('fast', function(){
			self.customzone_content.html('');				
			// While central div to work in all browsers with all player
			$('#center_big .center').show();
				if ($.browser.msie && $.browser.version == '6.0') {
					$('select').css('visibility', 'visible');
				}				
			});
 		},
 		
 		blockPage: function() {
 			var self = this;
 			if ($j.browser.msie && $j.browser.version == '6.0') {
				// for ie6 hiding selects
				$j('select').css('visibility', 'hidden');
			}
			
			self.box.height($(document).height());
			self.loading.show();
 		}
 	}
 	
 	$.Module_Customzone = function(options) {
 		return new Module_Customzone(options);
 	};
 
 })(jQuery);
