function ShowBlockSlow(te, se, ClsNameOn, ClsNameOff){
    if(document.getElementById(se)){
        seE = $('#' + se);
        if(te.className == ClsNameOn){
            seE.slideUp('slow');
            te.className = ClsNameOff;
        } else {
            seE.slideDown('slow');
            te.className = ClsNameOn;
        }
    }
}
function ShowBlock(te, se, ClsNameOn, ClsNameOff){
    if(document.getElementById(se)){
        seE = $('#' + se);
        if(te.className == ClsNameOn){
            seE.hide();
            te.className = ClsNameOff;
        } else {
            seE.show();
            te.className = ClsNameOn;
        }
    }
}

var AnonsTimerS   = null;
var AnonsTimerH   = null;
var AnonsIsShow  = 1;

function HideAnons(){
	clearTimeout(AnonsTimerH);
	clearTimeout(AnonsTimerS);
	if(AnonsIsShow){
    $('#MainAnonsC').slideDown('slow');
	$('#MainAnons').slideDown('slow');
	AnonsIsShow = 0;
	}
}
function ShowAnons(){
	clearTimeout(AnonsTimerH);
	clearTimeout(AnonsTimerS);
	if(!AnonsIsShow){
    $('#MainAnonsC').slideUp('slow');
	$('#MainAnons').slideUp('slow');
	AnonsIsShow = 1;
	}
}
function ToggleAnons(show){
	if(show){
		clearTimeout(AnonsTimerS);
		clearTimeout(AnonsTimerH);
		if(!AnonsIsShow){
			AnonsTimerS = setTimeout('ShowAnons()', 500);
		}
	} else {
		if(AnonsIsShow){
			AnonsTimerH = setTimeout('HideAnons()', 500);
		} else {
			AnonsTimerS = setTimeout('ShowAnons()', 500);
		}
	}
}

function js_clock(){
	var clock_time = new Date();
	var clock_hours = clock_time.getHours();
	var clock_minutes = clock_time.getMinutes();
	var clock_seconds = clock_time.getSeconds();
	var clock_suffix = "AM";
	if (clock_hours > 11){clock_suffix = "PM"; clock_hours = clock_hours;}
	if (clock_hours == 0){clock_hours = 12;}
	if (clock_hours < 10){clock_hours = "0" + clock_hours;}
	if (clock_minutes < 10){clock_minutes = "0" + clock_minutes;}
	if (clock_seconds < 10){clock_seconds = "0" + clock_seconds;}
	//var clock_div = document.getElementById('Time');
	//clock_div.innerHTML = clock_hours + ":" + clock_minutes;
	setTimeout("js_clock()", 1000);
}

$(function(){
	$("#MailFormLink").click(function(){
	popupWin = window.open("/form/","popup","width=640,height=530");
	popupWin.focus();
	});
	js_clock();
    var tabContainers = $('div.tabs > div');
    
    $('div.tabs ul.tabNavigation a').click(function () {
        tabContainers.hide().filter(this.hash).show();
        
        $('div.tabs ul.tabNavigation a').removeClass('selected');
        $(this).addClass('selected');
        
        return false;
    }).filter(':first').click();
    
    $('a[rel="_blank"]').click(function(){
        window.open($(this).attr('href'));
        return false;
    });
    
    $('.b-article-text blockquote').each(function(index) {
    	$(this).replaceWith('<dl class="b-notes nm"><dd>'+$(this).text()+'</dd></dl>');
    });
    
    $('#send_news').submit(function(){
    	data = $(this).serialize();
    	$.post('/send_news', data, function(data) {
    		app.show_flash_notice('Ваша новость была отправлена', true);
		$('#send_news').find('input[name],textarea').val('');
		});
    	return false;
    });
    
    $('.b-social_comments-tabs li a').click(function(){
    	$('.b-social_comments-tabs li').removeClass('active');
    	$(this).parent().addClass('active');
    	cm_block_id = $(this).parent().attr('id').replace('_link','');
    	$('#' + cm_block_id).stop().slideDown();
    	if (cm_block_id == 'fb_comments') {
    		$('#vk_comments').stop().slideUp();
    	} else {
    		$('#fb_comments').stop().slideUp();
    	}
    	return false;
    });
    
	$("#contest-register-link").click(function(){
		if ( $(this).hasClass('like-link-on') ) {
			$(this).removeClass('like-link-on').addClass('like-link-off');
			$('#contest-register').stop().slideDown();
		} else {
			$(this).removeClass('like-link-off').addClass('like-link-on');
			$('#contest-register').stop().slideUp();
		}
		$("#contest-login-link").removeClass('like-link-off').addClass('like-link-on');
		$('#contest-login').stop().slideUp();
	});
	$("#contest-login-link").click(function(){
		if ( $(this).hasClass('like-link-on') ) {
			$(this).removeClass('like-link-on').addClass('like-link-off');
			$('#contest-login').stop().slideDown();
		} else {
			$(this).removeClass('like-link-off').addClass('like-link-on');
			$('#contest-login').stop().slideUp();
		}
		$("#contest-register-link").removeClass('like-link-off').addClass('like-link-on');
		$('#contest-register').stop().slideUp();
	});
	$('#NewsForm form').submit(function(){
		alert(1);
	});
});

function PopupBlock(b,c){this.container=$(b);this.link=$(c);this.keep=false;var d=this;if(this.container&&this.link){this.container.click(function(a){d.keep=true});this.link.click(function(a){d.toggle(a)})}}PopupBlock.prototype.toggle=function(a){a.preventDefault();a.stopPropagation();if(this.container.hasClass("hidden")){this.show(a)}else{this.hide(a)}return this};PopupBlock.prototype.show=function(b){this.container.removeClass("hidden");var c=this;this.documentClickHandler=function(a){c.hide(a)};this.documentKeyDownHandler=function(a){c.cancel(a)};$(document).click(this.documentClickHandler);$(document).keydown(this.documentKeyDownHandler)};PopupBlock.prototype.hide=function(a){if(this.keep){this.keep=false;return}this.container.addClass("hidden");$(document).unbind("click",this.documentClickHandler);$(document).unbind("keydown",this.documentKeyDownHandler)};PopupBlock.prototype.cancel=function(a){var b=a.keyCode?a.keyCode:a.which?a.which:null;if(b==27){this.hide(a)}};

function ToggleNewsImg(id){
	iNode = $('#s-img-' + id);
	lNode = $('#link-' + id);
	if(iNode.length){
		na = iNode.parent();
		na.find('a').hide();
		$('#s-img-' + id).show();
	}
	if(lNode.length){
		nl = lNode.parent();
		nl.find('a').removeClass('active');
		$('#link-' + id).addClass('active');
	}
}

