var indexPage = {
	//параметры фильтра
	indexFilterValues: {
		showArticle: 1,
		showQuestion: 1,
		showSolution: 1,
		showTutorialLesson: 1,
		showCommunity: 1,
		showCrequest: 1,
		size: 50
	},
	/**
	 * устанавливает параметра фильтра
	 */
	setFilterOption: function (name, status) {
		indexPage.indexFilterValues[name] = status;
	},
	/**
	 * фильтрует материалы главной страницы по типу
	 */
	filterEssence: function (essence, status) {
	    $("#" + essence + "IndexFiler").val(status);
	    if (status == 1) {
	        $(".filter_essence_" + essence + " .filterJS").attr('href', 'javascript:indexPage.filterEssence(\'' + essence + '\', 0);');
	        $(".filter_essence_" + essence + " img").attr('src', W_IMAGES + 'background/index_filter_tab_plus.png');
	    }
	    else {
	        $(".filter_essence_" + essence + " .filterJS").attr('href', 'javascript:indexPage.filterEssence(\'' + essence + '\', 1);');
	        $(".filter_essence_" + essence + " img").attr('src', W_IMAGES + 'background/index_filter_tab_minus.png');
	    }
	    $('#universalInferenceFilter').stopTime('timerIndex');
	    $('#universalInferenceFilter').oneTime(400, 'timerIndex', function () {
	        indexPage.update();
	    });
	},
	/**
	 * Полностью обновляет страницу, а также сохраняет 
	 * значения опций фильтра, если они изменились
	 */
	update: function () {
	    var article = $("#articleIndexFiler").val();
	    var question = $("#questionIndexFiler").val();
	    var solution = $("#solutionIndexFiler").val();
	    var tutorialLesson = $("#tutorialLessonIndexFiler").val();
	    var community = $("#communityIndexFiler").val();
	    var crequest = $("#crequestIndexFiler").val();
	    var size = $("#sizeIndexFiler").val();
	
	    if (indexPage.indexFilterValues.showArticle != article) {
	        setUserVariable('indexFilterArticle', article);
	        indexPage.indexFilterValues.showArticle = article;
	    }
	    if (indexPage.indexFilterValues.showQuestion != question) {
	        setUserVariable('indexFilterQuestion', question);
	        indexPage.indexFilterValues.showQuestion = question;
	    }
	    if (indexPage.indexFilterValues.showSolution != solution) {
	        setUserVariable('indexFilterSolution', solution);
	        indexPage.indexFilterValues.showSolution = solution;
	    }
	    if (indexPage.indexFilterValues.showTutorialLesson != tutorialLesson) {
	        setUserVariable('indexFilterTutorialLesson', tutorialLesson);
	        indexPage.indexFilterValues.showTutorialLesson = tutorialLesson;
	    }
	    if (indexPage.indexFilterValues.showCommunity != community) {
	        setUserVariable('indexFilterCommunity', community);
	        indexPage.indexFilterValues.showCommunity = community;
	    }
	    if (indexPage.indexFilterValues.showCrequest != crequest) {
	        setUserVariable('indexFilterCrequest', crequest);
	        indexPage.indexFilterValues.showCrequest = crequest;
	    }
	    if (indexPage.indexFilterValues.size != size) {
	        setUserVariable('indexFilterSize', size);
	        indexPage.indexFilterValues.size = size;
	    }
	
	    $.post(W_AJAX + "indexUpdate.php", {
	        article: article,
	        question: question,
	        solution: solution,
	        tutorialLesson: tutorialLesson,
	        community: community,
	        crequest: crequest,
	        size: size
	    }, indexPage.insert, 'json');
	
	},
	insert: function (retur) {
	    if (retur) $(".bottom_border").replaceWith(retur);
	    else $(".bottom_border").empty();
	},
	getFullInfo: function (type, id) {
	    //$('#open_' + type + '_' + id).attr('href', 'javascript:console.log(1)');
	    $.post(W_AJAX + "indexGetEssenceFullInfo.php", { type: type, id: id }, indexPage.insertFullInfo, 'json');
	},
	insertFullInfo: function (retur) {
	    //if(retur.info) $('#' + retur.type + '_' + retur.id).empty();
	    if (retur.info) $('#' + retur.type + '_' + retur.id).append(retur.info);
	    $('#' + retur.type + '_' + retur.id).show();
	    $('#open_' + retur.type + '_' + retur.id + ' img').attr('src', W_IMAGES + 'background/bg_qwestion_minus.gif');
	    $('#open_' + retur.type + '_' + retur.id).attr('href', 'javascript:indexPage.closeFullInfo(\'' + retur.type + '\', ' + retur.id + ')');
	    jqTable = $('.universalInference').length ? $('.universalInference') : $('.bottom_border');
	    $('.code').css('width', jqTable.width() - 100);
	},
	closeFullInfo: function (type, id) {
	    $('#' + type + '_' + id).hide();
	    $('#open_' + type + '_' + id + ' img').attr('src', W_IMAGES + 'background/bg_qwestion_plus.gif');
	    $('#open_' + type + '_' + id).attr('href', 'javascript:indexPage.insertFullInfo({id: ' + id + ', type: \'' + type + '\'})');
	}
}
