$(document).ready(function() {
	// Vartical centrin main menu
/*
	var aaa = 0;
	$('ul.main-nav li').each(function() {
		aaa += $(this).outerWidth();
	});
xxx = $('ul.main-nav li').length;
zzz = ((((762-aaa)/xxx))/ 2);
*/
	$('ul.main-nav li span').each(function() {
		var p = ((82 - $(this).height()) / 2)+15;
		//alert ($(this).height());
		$(this).parent().css('height', /*92 - p*/ 50 + 'px');
		$(this).parent().css('padding-top', /*p*/ 42 + 'px');
	});

//	$('ul.main-nav li a').each(function() {
//		$(this).css('padding-left', zzz + 'px');
//		$(this).css('padding-right', zzz + 'px');
//	});

	// Left menu
	$('.leftmenu ul').css('display', 'none');
	$('.leftmenu .current').parent().css('display', 'block');

});


	$('#language').click(function() {
		if ($('#languageSelect').css('display')	== "none") {
			$('#languageSelect').slideDown('slow');
		} else {
			$('#languageSelect').slideUp('slow');	
		}
		return false;
	});


$('.lightcell td').hover(
	function () {
		$(this).css('background','#F2F2F3');
	}, 
	function () {
		$(this).css('background','none');
	}
);



// LavaLamp
$(function() { $(".lavaLamp").lavaLamp({ fx: "backout", speed: 700 })});




// Showing different tabs and their content on click.

$( '.tabs>h2' ).click(function() {
	if( $( this ).parents( '.tabs' ).hasClass( 'tabbed' ) ) {
		return;
	}
	var tabNo = 0;
	var thisHdr = this;
	$('.tabs>h2').each(function() {
		$( '#tab' + tabNo ).css('display', 'none');
		$(this).removeClass("selected");
		if ($(thisHdr).hasClass( 'header-tab' + tabNo )) {
			$('#tab' + tabNo).css('display', 'block');
			$(thisHdr).addClass('selected');
		}
		tabNo++;
	});
});

$('.lavaLamp li a').click(function() {
    var href = $(this).attr('href').substr(1);
    var tabContent = $(this).parent().parent().parent();
    
    $('.lavaLamp-module', tabContent).each(function() {    
            if ($(this).css('display') == 'block') {
                $(this).hide();
                $('#' + href).show();
            }
    });
    return false;
});

/* Permalink */

$('.tab-content a.link').each(function() {
	if ($(this).parents( '.lavaLamp-module' ).attr('id')){
		link = '?tab='+$(this).parents( '.tab-content' ).attr('id').substr(3,1)+'&slider='+$(this).parents( '.lavaLamp-module' ).attr('id');
		$(this).attr('href',link);
	} else{
		link = '?tab='+$(this).parents( '.tab-content' ).attr( 'id' ).substr(3,1);
		$(this).attr('href',link);
	}
});

/**
 * Currys a function and arguments. Takes a function as the first argument,
 * and returns a zero-arugument function that calls the provided function
 * with the provided arguments.
 */
function curryFunction() {
	var f = arguments[0];
	var args = [];
	for (i = 1; i < arguments.length; i++) {
		args[i-1] = arguments[i];
	}
	return function() {
		return f.apply(this, args);
	}
}

/* block optimize
$(document).ready(function() {
    $('#why').html( $('#optimize').html() );
    $('#optimize').remove();
    $('#foru').html( $('#optimize2').html() );
    $('#optimize2').remove();
});
*/

$( document ).keydown(
	function( ev ) {
		ev = ev || window.event;
		code = ev.keyCode || ev.charCode;
		if( 
			code != 17 &&
			code == 112 &&
			ev.altKey == 1
		) {
			ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
			(function(){
				window.open( '/ru/chat/','support','toolbar=no,resizable=yes,status=no,menubar=no,location=no,width=600,height=500' );
			}());
		}
	}
);
