
	$j(document).ready(function() {
		$j("a._blank").attr('target', '_blank');
		$j("img.absmiddle").attr('align', 'absmiddle');
		
		// TODO: вынести в Module_TV
		$j.Module_Facebook().init();
		$j.Module_Twitter().init();
		
		// Banners
		activateBanners();
	});
		
	// -- Index --
		
	function activateIndexPage() {
	}
	
	// -- facebook --
	
	function activateFacebookRegistration() {
		activateCalendar();
		$('.submit_registration_form').live('click', function(){
			$j("#registrationForm").submit();
		});
	}
	
	function closeFacebookRegistration() {
		$j.Module_Facebook().closeWindowOauth();
	}
	
	// -- twitter --
	
	function activateTwitterRegistration() {
		activateCalendar();
		$j('.submit_registration_form').live('click', function(){
			$j("#registrationForm").submit();
		});
	}
	
	function closeTwitterRegistration() {
		$j.Module_Twitter().closeWindowOauth();
	}
			
	// -- Video Content --
	
	function activateAddithionalVideoFunctions() {
		$j.Module_TV().activateAddithionalVideoFunctions();
	}
	
	// -- Index page --
	
	function activateIndexPage() {
		$j.Module_Index().construct();
	}
		
	// -- Tv page --
	
	function activateTvPage() {
		$j.Module_TV().construct();
	}
	
	function activateTvPageForAdmin() {
		$j.Module_TV().constructForAdmin();
	}
	
	function activateTvOnePage() {
		$j.Module_TV().constructForcedOpen();
	}
	
	function activateTvOnePageForAdmin() {
		$j.Module_TV().constructForcedOpenForAdmin();
	}
	
	// -- Shows page --
	
	function activateShowsPage() {
		$j.Module_Shows().construct();		
	}
	
	function activateShowsPageForAdmin() {
		$j.Module_Shows().constructForAdmin();		
	}
	
	function activateShowsPageForNewQueue() {
		$j.Module_Shows().constructForNewQueue();		
	}
	
	function activateShowsOnePage() {
		$j.Module_Shows().constructForcedOpen();		
	}
	
	function activateShowsOnePageForAdmin() {
		$j.Module_Shows().constructForcedOpenForAdmin();		
	}
	
	// -- Movies page --
	
	function activateMoviesPage() {
		$j.Module_Movies().construct();
	}
	
	function activateMoviesPageForAdmin() {
		$j.Module_Movies().constructForAdmin();
	}
	
	function activateMoviesPageForNewQueue() {
		$j.Module_Movies().constructForNewQueue();		
	}
	
	function activateMoviesOnePage() {
		$j.Module_Movies().constructForcedOpen();
	}
	
	function activateMoviesOnePageForAdmin() {
		$j.Module_Movies().constructForcedOpenForAdmin();
	}
			
	// -- Channels page --
	
	function activateChannelsPage() {
		$j.Module_Channels().construct();
	}
		
	function activateChannelsPageForAdmin() {
		$j.Module_Channels().constructForAdmin();
	}
		
	// -- Channel Video Page --
	
	function activateChannelVideoPage() {
		$j.Module_ChannelVideo().construct();
	}
	
	function activateChannelVideoPageForAdmin() {
		$j.Module_ChannelVideo().constructForAdmin();
	}
	
	function activateChannelVideoOnePage() {
		$j.Module_ChannelVideo().constructForcedOpen();
	}
	
	function activateChannelVideoOnePageForAdmin() {
		$j.Module_ChannelVideo().constructForcedOpenForAdmin();
	}
		
	// -- MyQueue page --
	
	function activateMyQueuePage() {
		$j.Module_MyQueuePage().construct();
	}
	
	// -- Banners --
		
	function activateBanners() {
		//$j('.bannner_line.top .banner').html($j('#ads_top_hidden').html());
		//$j('#ads_left').html($j('#ads_left_hidden').html());
	}
		
	var source = ''; 
	var sourceLoaded = false;
	function getTagsForBanners() {	
		if (! sourceLoaded) {
			var $ellements = $j('.description_wrapper a');
			$ellements.each(function(i, item) {
				var curr_text = $j(item).text();
				// Если IE обрезаем описание еллемента до 2600(принимает IE) / 16 (всего эллементов) = 
				if ($j.browser.msie) {
					if ($ellements.size() > 1) {
					} else {
					}
				}
	 			source += ' ' + curr_text;
			});
			if (source.length > 0)
				sourceLoaded = true;
		}
		return encodeURIComponent(source);
	}
							
	// -- Png fix --
	
	function activatePngFix() {
	}
				
	// -- Addithional --
	
	function showGrowl($div, status) {
		var color = '#000';
		if (status == 'ok') {
			color = 'green';
		} else if (status == 'warning') {
			color = '#EBC217'
		} else if (status == 'error') {
			color = 'red'
		}
	
		$j.blockUI({ 
			message: $div, 
			fadeIn: 700, 
            fadeOut: 700, 
            timeout: 7000, 
            showOverlay: false, 
            centerY: false,
			css: { 
                width: '350px', 
                top: '25px', 
                left: '', 
                right: '10px', 
                border: 'none', 
                padding: '5px', 
                backgroundColor: color, 
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                opacity: .6, 
                color: '#fff' 
            } 
		});
	}
	
	function slideFlashMessanger(message) {
		jQuery('#messages').hide();
		
		if(message) {
			jQuery('#messages ul li:first').html(message);
		}
		
		jQuery('#messages').slideDown();
	     setTimeout(function(){
	        jQuery('#messages').slideUp();
	    }, 3200);
	}
	
	function activateCheckboxes() {
		// ":not([safari])" is desirable but not necessary selector
	    var $checkbox_checkbox_not_safari = $j('input:checkbox:not([safari])');
	    if ($checkbox_checkbox_not_safari.size()>0) {
			$checkbox_checkbox_not_safari.checkbox({empty:'/js/checkbox/empty.png'}).show();
	    }
	    	   
		var $checkbox_checkbox_safari =  $j('input[safari]:checkbox');
		if ($checkbox_checkbox_safari.size()>0) {
		   $checkbox_checkbox_safari.checkbox({cls:'jquery-safari-checkbox'}).show();
	    }
	}
	
	function addAjaxIndicator(obj) {
		$j(obj).html('<img src="/images/ajax_load.gif" class="ajax_load" />');
	}
	
	function blockElement(obj) {
		$j(obj).block({ 
			message: '<h1>Processing</h1>', 
			css: { border: '3px solid #a00' } 
		});
	}
	
	function unblockElement(obj) {
		$j(obj).unblock();
	}
		
	function activateCalendar() {	
		$j(".calendar-input").datepicker( {
			mandatory : true,
			yearRange : '1920:2020',
			dateFormat : $j.datepicker.ATOM,
			changeYear: true,
			changeMonth: true
		}).attr("readonly", "readonly");
	
		$j(".calendar-image").bind('click', function() {
			$j(this).prev().focus();
		}).css("cursor", "pointer");
	}
			
	function ajaxError(){
		alert("Error in data transfer! Try again");
	}
	
	function reloadPage(){
		window.location.reload();
		return;
	}
	
	function checkResponse(json) {	
		if (typeof (json) == 'undefined') {
			alert("Error in data transfer! Try again");
			return false;
		}
			
		// var json = eval("(" + responseText + ")");	
		if (typeof (json) != 'object' && typeof (json) != 'array') {
			alert("Error in data transfer! Try again");
			return false;
		}
	
		return json;
	}
			
	function var_dump(obj) {
		  var result = null;
		  for (var i in obj)
		  result += 'object' + '.' + i + ' = ' + obj[i] + '\n';
		  return result;
	}
	 
	function activateblock(){
		$j.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: '.5', 
            color: '#fff'				
        }, overlayCSS:{'z-index': 1007} }); 
	}
	
	function deactivateblock(){
		$j.unblockUI();
	}
	
	function you_are_sure(str) {
		if ($j(str).size() == 0) {
			str = 'You are sure?';
		}
		return confirm(str);
	}
