

/**
 * Проверка измнения размеров окна для выравнивания флеша
 */
function _rePositionFlash()
{
	var wW = $(window).width();
	var fW = $(".flashcontainer").width();
	if (wW < fW)
	{
		$(".flashcontainer").css('margin-left','-'+(fW-wW)/2+'px');
	}
	else
		$(".flashcontainer").css('margin-left','0px');
}


function showWindowLangSelect()
{
	if (_PAGE_URI!='/' && _PAGE_URI!='/en') return;
		
	var currentLang = $.cookie('currLang');
	
	if (!currentLang)
	{
		$('body').append("<div id='langwindow'><table><tr><td><a href='/' class='selectRU'>РУССКИЙ</a></td><td><a href='/en' class='selectEN'>ENGLISH</a></td></tr></table></div>");
		_rePositionLangs();
		$("#langwindow .selectRU, #langwindow .selectEN").click(function(){
			$.cookie('currLang','yes',{'expires':7,'path':'/'});
			document.href.location = $(this).attr('href');
			return false;
		});
	}
}


function _rePositionLangs()
{
	if ($("#langwindow"))
		$("#langwindow").css({
			'left':$(window).width()/2-$("#langwindow").width()/2+'px',
			'top':$(window).height()/3-$("#langwindow").height()/2+$(window).scrollTop()+'px'
		});
}



$(document).ready(function(){
	_rePositionFlash();
	$(window).resize(function(){_rePositionFlash(); _rePositionLangs(); });
	setInterval("_rePositionFlash(); _rePositionLangs();",500);
	showWindowLangSelect();
	
});















/**
 * Планиг для работы с ookie
 * Ставит куки и проверяет наличие
 */

jQuery.cookie = function (key, value, options) {
    
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '/',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
