
/* cookie.js */

function getExpDate(days, hours, minutes) {
	var expDate = new Date();
	
	if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
		expDate.setDate(expDate.getDate() + parseInt(days));
		expDate.setHours(expDate.getHours() + parseInt(hours));
		expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
		
		return expDate.toGMTString();
    }
	
	return null;
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)	endstr = document.cookie.length;
	
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)	return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	
	return null;
}

function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "")+
		((domain) ? "; domain="+domain : "") +
		((secure) ? "; secure" : "");
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
		document.cookie = name + "="+
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain="+domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}



// Падающие снежинки в слое, версия 2.0
// © 2009 Селезнёв Д. Л., info@webfilin.ru
// Лицензия: GNU PL

function SnowDiv(element) {
	if (typeof element == 'string') {
        this.conElement = document.getElementById(element);
    }
	else {
        this.conElement = element;
    }
	
	var isIE6 = (window.navigator.userAgent.search(/MSIE 6/) == -1) ? false : true;
	this.prefixId = 'dot-' + this.id + '-';

    this.dx = [];
    this.xp = [];
    this.yp = [];
    this.zp = [];
    this.am = [];
    this.stx = [];
    this.sty = [];
    this.stz = [];
    this.isStop = false;
    this.isHide = false;
	
	for (var i = 0; i < this.snowN; i++) {
		this.dx[i] = 0;
		this.xp[i] = Math.random() * (this.conWidth - this.dotWidth);
		this.yp[i] = Math.random() * this.conHeight;
        this.stz[i] = 0;
        this.zp[i] = Math.floor(Math.random() * 4);
		this.am[i] = Math.random() * 20;
		this.stx[i] = 0.02 + Math.random() / 10;
		this.sty[i] = 0.7 + Math.random();
		
		var div = document.createElement('div'),
            st = div.style;
            
		div.id = this.prefixId + i;
        this.defaultStyle(div);
		st.width = this.dotWidth + 'px';
		st.height = this.dotHeight + 'px';
		st.left = '0';
		st.zIndex = i;
        
        var left = '-' + Math.floor(Math.random() * this.typeSnowN) * this.dotWidth + 'px';
		if (isIE6) {
            var divInner = document.createElement('div'),
                stInner = divInner.style;
                
            this.defaultStyle(divInner);
            stInner.width = this.imageWidth + 'px';
            stInner.height = this.dotHeight + 'px';
            stInner.left = left;
			stInner.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.imageUrl + '\',sizingMethod=crop)';
			stInner.background = st.background = 'none';
            st.overflow = 'hidden';
            div.appendChild(divInner);
		}
		else {
			st.background = 'url(\'' + this.imageUrl + '\') no-repeat ' + left + ' 0px';
		}
		
		this.conElement.appendChild(div);
	}
	
	this.id = this.id;
	SnowDiv.prototype.id++;
}

SnowDiv.prototype.conElement = null; //  Контейнер (DOM-элемент) для размещения снежинок
SnowDiv.prototype.conWidth = 240; // Ширина контейнера, 0 - вся ширина окна браузера
SnowDiv.prototype.conHeight = 180;	// Высота контайнера, 0 - вся высота окна браузера
SnowDiv.prototype.snowN = 10; // Количество снежинок в контейнере
SnowDiv.prototype.typeSnowN = 9; // Количество видов снежинок
SnowDiv.prototype.dotWidth = 16; // Ширина снежинки
SnowDiv.prototype.dotHeight = 18; // Высота снежинки
SnowDiv.prototype.imageUrl = './images/snow.png'; // Картинка со снежинками
SnowDiv.prototype.imageWidth = 144; // Ширина картинки со снежинками
SnowDiv.prototype.sin = true; // Перемещаем снежики по синусоиде
SnowDiv.prototype.timer = 20;
SnowDiv.prototype.id = 0;

SnowDiv.prototype.defaultStyle = function(obj) {
    var st = obj.style;
    st.position = 'absolute';
    st.lineHeight = '0';
    st.fontSize = '0';
    st.top = '0';
    st.visibility = 'visible';  
}

SnowDiv.prototype.refresh = function() {
	var el;
	for (var i = 0; i < this.snowN; i++) {
		this.yp[i] += this.sty[i];
		el = this.dot(i);
		if (this.yp[i] > this.conHeight - this.dotHeight) {
			this.xp[i] = Math.random() * (this.conWidth - this.am[i] - this.dotWidth * 1.5);
			this.yp[i] = - this.dotHeight;
			this.stx[i] = 0.02 + Math.random() / 10;
			this.sty[i] = 0.7 + Math.random();
		}

        this.stz[i] += this.zp[i];    
        if (this.stz[i] > 360) {
            this.stz[i] -= 360;
        }

		this.dx[i] += this.stx[i];

        var x, y;		
		if (this.sin) {
            x = this.xp[i] + this.am[i] * Math.sin(this.dx[i]);
        }
		else {
            x = this.xp[i] + this.am[i];
        }
        
        x = Math.floor(x);
		y = Math.floor(this.yp[i]);
		
		if (x > this.conWidth) {
            x = this.conWidth;
        }
		if (y > this.conHeight) {
            y = this.conHeight;
        }
		el.style.top = y + 'px';
		el.style.left = x + 'px';
		el.style.WebkitTransform = el.style.MozTransform = 'rotate(' + this.stz[i] + 'deg)';
	}
	
	var cl = this;
	if (!this.isStop) {
        setTimeout(function () {cl.refresh();}, this.timer);
    }
}

SnowDiv.prototype.start = function ()  {
	this.isStop = false;
	this.refresh();
}

SnowDiv.prototype.stop = function ()  {
	this.isStop = true;
}

SnowDiv.prototype.show = function () {
	if (this.isHide) {
		this.isHide = false;
		for (var i = 0; i < this.snowN; i++) {
			this.dot(i).style.display = 'block';
		}
	}
}

SnowDiv.prototype.hide = function () {
	this.stop();
	if (!this.isHide) {
		this.isHide = true;
		for (var i = 0; i < this.snowN; i++) {
			this.dot(i).style.display = 'none';
		}
	}
}

SnowDiv.prototype.dot = function(i) {
    return document.getElementById(this.prefixId + i);
}﻿


/* other.js */
var isFlashBlock = false;
function checkForFlash(version) {
	var flashIsInstalled = false, flash;
        
	if (window.ActiveXObject) {
		try {
			flash = new ActiveXObject(('ShockwaveFlash.ShockwaveFlash.' + version));
			flashIsInstalled = true;
		}
		catch(e) {
		}
	}
	else if (navigator.plugins && navigator.mimeTypes.length > 0) {
		flash = navigator.plugins['Shockwave Flash'];
		if (flash){
			var flashVersion = navigator.plugins["Shockwave Flash"].description.replace(/.*\s(\d+\.\d+).*/, "$1");
			if (flashVersion >= version) {
				flashIsInstalled = true;
			}
		}
	}
	return flashIsInstalled;
}

function getRandom(n) {
	return Math.floor(Math.random() * n);
}

function isInside(container, element) {
	var x11 = $(container).offset().left;
	var y11 = $(container).offset().top;
	var x12 = x11 + $(container).width();
	var y12 = y11 + $(container).height();
	
	var x21 = $(element).offset().left;
	var y21 = $(element).offset().top;
	var x22 = x21 + $(element).width();
	var y22 = y21 + $(element).height();
	
	var x = false,
		y = false;
	
	if (x21 >= x11 && x21 <= x12)	x = true;
	if (x22 >= x11 && x22 <= x12)	x = true;
	if (x21 < x11 && x21 < x12 && x22 > x11 && x22 > x12)	x = true;
	
	if (y21 >= y11 && y21 <= y12)	y = true;
	if (y22 >= y11 && y22 <= y12)	y = true;
	if (y21 < y11 && y21 < y12 && y22 > y11 && y22 > y12)	y = true;
	
	if (x && y)	return true;
	
	return false;
}

function cacheBackgroundIE() {
	// background image cache for Internet Explorer
	var m = document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand;
	try {
		if (!!m) {
			m("BackgroundImageCache", false, true);
		}
	}
	catch (e) {};
}

/* © 2009 Seleznev Denis, info@webfilin.ru
*   Graphics by Selezneva Luba
*/

/* elka.js */

window.elka = {
	ajaxUrl: './index.php?action=save',
	soundPath: '/elka/sounds/',
	swfPath: '/elka/js/',
	limit: 50
};

(function($) {
    var isPreloader = true,
		win = window,
		doc = document;
    
    $(doc).ready(function() {
        var npre = 0,
            ndots = 0,
            dot = $('#preloader div.text span'),
            branch = $('#preloader div').not('#preloader div.text');
            
        function preloader() {
            setTimeout(function() {
                if (!isPreloader) {
                    return;
                }
                
                npre--;
                if (npre < 0) {
                    npre = branch.length;
                }
                
                branch.hide();
                for (var i = branch.length; i >= npre; i--) {
                    branch.eq(i - 1).show();
                }
                
                ndots += 0.2;
                if (ndots > dot.length) {
                    ndots = 0;
                }
                
                dot.css('visibility', 'hidden');
                for (var i = 0; i < ndots; i++) {
                    dot.eq(i).css('visibility', 'visible');
                }
                
                preloader();
            }, 200);
        }
        
        $('#preloader').show();
        preloader();
    });

    $(win).load(startElka);
    
    function startElka() {
        isPreloader = false;
        
        function showBallon(el, ballon) {
            var l = $(el).offset().left,
                t = $(el).offset().top,
                w = $(el).width(),
                h = $(el).height();
            
            if (!ballon) {
                ballon = '#ballon';
            }
            
            $(ballon).css({left: l + 'px'}).show();
			var ballonHeight = $(ballon).outerHeight();
            $(ballon).css({top: (t > 600 ? (t - ballonHeight) : (t + h)) + 'px'});
        }

        function hideBallon(ballon) {
            if (!ballon) {
                ballon = '#ballon';
            }
            
            $(ballon).hide();
        }

        function closeBox() {
            $('#toys .down').hide();
            $('#kr').show().css({left: '', width: '', height: '', top: ''});
            $('#box-container').animate({left:'-10px'}, 1000);
        }
        
        function openBox(anim) {
            if (typeof anim == 'undefined')	anim = true;
            
            $('#kr').animate({left:'-450px', width: '230px', top: '-30px', height: '230px'}, 2000);
            
            if (anim) {
                setTimeout(function() {
                    if ($.browser.msie)	$("#ded").show();
                    else	$("#ded").fadeIn(200);
                }, 500);
                
                setTimeout(function() {
                    if ($.browser.msie)	$("#blue-box").show();
                    else $("#blue-box").fadeIn(200);
                }, 1000);
                
                setTimeout(function() {
                    if ($.browser.msie)	$("#snowman").show();
                    else	$("#snowman").fadeIn(200);
                }, 1500);
                
                setTimeout(function() {
                    if ($.browser.msie)	$("#yellow-box").show();
                    else $("#yellow-box").fadeIn(200);
                }, 2000);
                
                setTimeout(function() {
                    if ($.browser.msie)	$("#yellow-mishka").show();
                    else	$("#yellow-mishka").fadeIn(200);
                }, 2500);
                
                setTimeout(function() {
                    if ($.browser.msie)	$("#snegurochka").show();
                    else	$("#snegurochka").fadeIn(200);
                }, 3000);
                
                setTimeout(function() {
                    if ($.browser.msie)	$("#linux").show();
                    else	$("#linux").fadeIn(200);
                }, 2500);

                setTimeout(function() {
                    if ($.browser.msie)	$("#firefox").show();
                    else	$("#firefox").fadeIn(200);
                }, 3000);
            }
        }

        // --- Снег за окном ----------------------------------
        (new SnowDiv('snow-container')).start();
        
        var nsb = (getCookie('nsb') == '1' || win.elka.isReadOnly) ? true : false;
        nsb = true;
        
        // --- Календарь ---------------------------------
        var months = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'];
        var d = new Date();
        var day = d.getDate();
        var month = d.getMonth();
        
        $('#month').html(months[month]);
        $('#day').html(day);
        $('#calendar').show();
        
        // --- Ввод пожелания ---------------------------------
        $('#message, #author').val('');
        $('#input-message .close').click(function() {
            $('#input-message').hide();
            $('#elka-container .toy:last').remove();
            $('#toys .toy').show();
            $('#box-container').animate({left: '-10px'}, 1000);
        });
        
        var maxlength = win.elka.maxLengthMessage || 150,
            ml = $('#input-message .max-length').html(maxlength);
        
        $('#input-message textarea').keypress(function() {
            var txt = $(this).val() || '';
            var len = maxlength - txt.length;
            
            if (len < 0)    len = 0;
            ml.html(len);
            
            if (len <= 0) {
                return false;
            }
        });

        $('#bg-cap, #preloader').hide();

        cacheBackgroundIE();
        
        var isFlashInstalled = checkForFlash(8);
        if (isFlashBlock)	isFlashInstalled = false;
        if (!isFlashInstalled) {
            $('#cat-tail-hover, #switcher-sound').hide();
        }
        
        if ((day == 31 && month == 11) || (day == 1 && month == 0) || (day == 7 && month == 0)) $('#calendar').addClass('holiday');

        $('#box-container').fadeIn(500).animate({left:'-10px'}, 2000, null, (!nsb) ? openBox : null);
        
        $('#switcher-gir').click(girToggle);
        
        $('#toys > div').draggable({start: function() {
            if ($(this).hasClass('elka'))	{
                $('#elka-bg').show();
            }
            else {
                $('#helper-toys').show();
            }
            
            if (!$(this).data('oldZIndex')) {
                $(this).data('oldZIndex', $(this).css('z-index'));
                $(this).data('oldLeft', $(this).css('left'));
                $(this).data('oldTop', $(this).css('top'));
            }
            
            $(this).css('z-index', 100);
        }, drag: function() {
            if ($(this).hasClass('elka')) {
                if (isInside($('#elka-bg'), this)) {
                    $('#elka-bg').addClass('hover');
                }
                else {
                    $('#elka-bg').removeClass('hover');
                }
            }
            else {
                if (isInside($('#helper-toys'), this)) {
                    $('#helper-toys').addClass('hover');
                }
                else {
                    $('#helper-toys').removeClass('hover');
                }
            }
        }, stop: function() {
            $('#elka-bg').hide();
            $('#helper-toys').hide();
            
            if (($(this).hasClass('elka') && $('#elka-bg').hasClass('hover')) || (!$(this).hasClass('elka') && $('#helper-toys').hasClass('hover'))) {
                $('#box-container').animate({left: '-200px'}, 1000);
                $('#input-message').show().find('textarea').focus();

                function checkFields() {
                    if ($.trim($('#message').val()) == '' || $.trim($('#author').val()) == '') {
                        $('#submit')[0].disabled = true;
                    }
                    else {
                        $('#submit')[0].disabled = false;
                    }
                }
                
                $('#message, #author').unbind('blur keyup').bind('blur keyup', checkFields);
                
                $('#input-message input:button').unbind('click').click(function() {
                    if (this.disabled) {
                        return;
                    }
                    
                    $('#petard').remove();
                    $('#sham').play();
                    $('#bokal-container').fadeIn('normal');
                    
                    $('#input-message').hide();
                    win.elka.messages.push({text: $('#message').val(), author: $('#author').val()});
                    
                    setCookie('nsb', '1', getExpDate(30, 0, 0));
                    closeBox();

                    ajaxParam.text = $('#message').val();
                    ajaxParam.author = $('#author').val();
                    
                    $.post(win.elka.ajaxUrl, ajaxParam, function(data) {
                        //if (data.error) {
                            //alert('Error: ' + data.error);
                        //}
                    }, 'json');				
                });
                checkFields();
                
                var e = $('#elka-container').offset(),
                    t = $(this).offset(),
                    toys = $('#elka-container .toy').length,
                    toy = $(this).attr('id'),
                    x = t.left - e.left,
                    y = t.top - e.top;

                var ajaxParam = {
                    x: x,
                    y: y,
                    toy: toy
                }
                
                $(this).clone().appendTo('#elka-container').removeClass('elka').addClass(toy).attr('id', 'toy' + (toys - 1)).css({left: x + 'px', top: y + 'px'});
                $(this).css({left: $(this).data('oldLeft'), top: $(this).data('oldTop')}).hide();
            }
            else {
                $(this).animate({left: $(this).data('oldLeft'), top: $(this).data('oldTop')}, 300);
            }
            
            $('#helper-balls, #helper-toys').removeClass('hover');
            $(this).css('z-index', $(this).data('oldZIndex'));
        }});
        
        $('#poly').mouseover(function() {
            $('#elka').css('opacity', '0.5');
        }).mouseout(function() {
            $('#elka').css('opacity', '1');
        });	
        
        // --- (c) --------------------------------
        $(doc).click(function() {$('#copyright').hide('fast')});
        $('#sym-copyright').click(function () {$('#copyright').toggle('fast'); return false;});
        
        // --- Звезда на елке ---------------------
        $('#star').hover(function(e) {
            showBallon(this, '#ballon-star');
        }, function(e) {
            hideBallon('#ballon-star');
        }).mouseover(function() {
            $(this).css({opacity: 0.5});
        }).mouseout(function() {
            $(this).css({opacity: 1});
        });

        // --- Снегирь на елке ---------------------
        $('#bullfinch').hover(function(e) {
            showBallon(this, '#ballon-bullfinch');
        }, function(e) {
            hideBallon('#ballon-bullfinch');
        });

        // --- Игрушки на елке ---------------------
        function buildToys() {
            for (var i = 0; i < win.elka.messages.length && i < win.elka.limit; i++) {
                $('<div id="toy' + i + '" style="z-index:' + (i + 1) + '; left:' + win.elka.messages[i].x + 'px; top:' + win.elka.messages[i].y + 'px;" class="toy ' + win.elka.messages[i].toy + '"><div></div></div>').appendTo('#elka-container');
            }
        }
        
        buildToys();
        
        $('#elka-container .toy').live('mouseover', function() {
            var id = parseInt(this.id.replace(/toy/, ''));
            if (win.elka.messages[id]) {
                $('#ballon .ballon-text').text(win.elka.messages[id].text);
                $('#ballon .ballon-author').text(win.elka.messages[id].author);
                $(this).css('opacity', 0.6);
                showBallon(this);
            }
        }).live('mouseout', function() {
            $(this).css('opacity', 1);
            hideBallon();
        });
        
        // --- Говорящий тигр ------------------------
        function showTiger() {
            $('#tiger div').animate({right: '-40px'}, 1000, function() {$('#tiger-description').fadeIn('fast')});
            setTimeout(function() {
                $('#tiger-description').fadeOut('fast');
                $('#tiger div').animate({right: -$('#tiger div').width() + 'px'});
            }, 10000);
        }
        
        if (!nsb) {
            setTimeout(showTiger, 5000);
        }
        
        // --- Музыка и звуки -----------------------
        if (isFlashInstalled) {
            $('#music').jPlayer({
                ready: function () {
                    $(this).setFile(win.elka.soundPath + 'small_elka.mp3');
                },
				swfPath: win.elka.swfPath
            });
            
            $('#mur').jPlayer({
                ready: function () {
                    $(this).setFile(win.elka.soundPath + 'cat.mp3').volume(50);
                },
				swfPath: win.elka.swfPath
            });
            
            $('#bum').jPlayer({
                ready: function () {
                    $(this).setFile(win.elka.soundPath + 'petard.mp3');
                },
				swfPath: win.elka.swfPath
            });	
            
            $('#sham').jPlayer({
                ready: function () {
                    $(this).setFile(win.elka.soundPath + 'sham.mp3');
                },
				swfPath: win.elka.swfPath
            });	            
            
            $('#zepa').jPlayer({
                ready: function () {
                    $(this).setFile(win.elka.soundPath + 'zepa.mp3');
                },
				swfPath: win.elka.swfPath
            });	            

            $('#cat-tail-hover').hover(function() {
                $('#cat-tail').show();
                $('#mur').play();
            }, function() {
                $('#cat-tail').hide();
                $('#mur').stop();
            });
            
            var isSound = false;

            $('#switcher-sound .ajax').click(function() {
                isSound = !isSound;
                if (isSound) {
                    $('#music').play();
                    $(this).addClass('active');
                }
                else {
                    $('#music').stop();
                    $(this).removeClass('active');
                }
            }).hover(function() {
                $(this).addClass('hover');
            }, function() {
                $(this).removeClass('hover');
            });
        }
        
        // --- Петарда с конфетти -----------------------------
        setTimeout(function() {
            $('#petard').fadeIn('normal');
        }, 8000);
        
        $('#bokal').click(function() {
            $(this).unbind('click').fadeOut('slow');
            $('#zepa').play();
            setTimeout(function() {
                $('#bokal-container').fadeOut('normal');
            }, 10000);            
        });
        
        $('#petard').hover(function() {
            var el = $('img', this);
            if (!el.hasClass('bum')) {
                el.addClass('hover');
            }
        }, function() {
            var el = $('img', this);
            if (!el.hasClass('bum')) {
                el.removeClass('hover');
            }
        }).one('click', function() {
            var el = $('img', this);
            el.removeClass('hover').addClass('bum').unbind('hover');
            
            if (isFlashInstalled)	{
                $('#bum').play();
            }
            
            el.animate({opacity: 0.2, left: '0', top: '0', width: '250px', height: '440px'}, 300, null, function() {
                $('#petard').fadeOut();
                
                var coord = $('#petard').position(),
                    text = [],
                    x = coord.left + 150,
                    y = coord.top + 150;
                    
                for (var i = 0; i < 50; i++) {
                    text.push('<div class="color' + (getRandom(7) + 1) + '" style="left:' + x + 'px; top:' + y + 'px; margin-left:' + (40 - getRandom(80)) + 'px; margin-top:' + (40 - getRandom(80)) + 'px;"><div></div></div>');
                }
                
                var size = 11,
                    winWidth = $(win).width() - size;
                    winHeight = $(win).height() - size;
                
                $('#confetti').html(text.join('')).find('> div').each(function() {
                    var time = getRandom(800) + 500,
                        obj = {};
                    
                    switch(getRandom(4)) {
                        case 0:
                            obj = {left: 0, top: getRandom(winHeight), marginLeft: 0, marginTop: 0};
                        break;
                        case 1:
                            obj = {left: getRandom(winWidth), top: 0, marginLeft: 0, marginTop: 0};
                        break;
                        case 2:
                            obj = {left: winWidth, top: getRandom(winHeight), marginLeft: 0, marginTop: 0};
                        break;
                        default:
                            obj = {left: getRandom(winWidth), top: winHeight, marginLeft: 0, marginTop: 0};
                        break;
                    }
                    $(this).animate(obj, time, function() {$(this).hide();});
                });
            });
        });
        
        // --- Гирлянда -------------------------------
        var aGir = ['#FFFF00', '#FF9000', '#FF0000', '#FF006F', '#FF706F', '#FFE06F', '#FF70CF', '#FF00EF'],
            cGir = ['yellow', 'red', 'blue', 'green', 'sky', 'orange', 'pink'],
            xyGir = [
                        [241,128],[256,137],
                        [236,193],[251,208],[268,219],[289,229],
                        [207,289],[226,304],[247,316],[278,322],[301,323],
                        [170,370],[192,385],[213,397],[241,404],[269,411],[302,411],[332,412],[357,412],
                        [127,438],[145,456],[167,468],[191,477],[219,485],[248,491],[278,493],[307,496],[338,494],[369,493],
                        [82,535],[99,550],[121,562],[144,570],[172,577],[199,583],[230,588],[262,593],[291,595],[321,595],[353,594],[380,588],[409,585]
                    ];
                    
        var nGir = 0,
            showGir = false;

        function girToggle() {
            showGir = !showGir;
            if (showGir) {
                gir();
            }
            else {
                $('img.gir').css('visibility', 'hidden');
            }
        }

        function gir() {
            if (!showGir) {
                return;
            }
            
            if (nGir > 0) {
                nGir = 0;
            }
            else {
                nGir ++;
            }
            
            $('img.gir').css('visibility', 'hidden');		
            $('#g' + (nGir + 1)).css('visibility', 'visible');
            
            setTimeout(gir, 1000);
        }				
                    
        function initGir() {
            var c = 0;
            for (var i = 0; i < xyGir.length; i++) {
                $('#gir' + (i + 1)).css({left: xyGir[i][0] + 'px', top: xyGir[i][1] + 'px'});
            }
            
            c = 0;
            $('#gir div').each(function() {
                $(this).attr('class', cGir[c])
                c++;
                if (c == cGir.length)	c = 0;
            });
        }
        
        initGir();
        
        var isHoverGir = false, isGir = false;
        
        function startGir() {
            function classRotate(context) {
                var div = $('div', context);
                var firstClass = div.eq(0).attr('class');
                for (var i = 0; i < div.length - 1; i++) {
                    $(div[i]).attr('class', $(div[i + 1]).attr('class'));
                }
                
                $(div[div.length - 1]).attr('class', firstClass);
            }
            
            classRotate($('#gir'));
            
            if (isGir) setTimeout(startGir, 150);
        }
        
        function hoverGir() {
            if (isHoverGir) {
                var c = aGir[getRandom(aGir.length)];
                $('#switcher-gir .ajax').css({color: c, borderColor: c});
                setTimeout(hoverGir, 100);
            }
        }
        
        $('#switcher-gir .ajax').click(function() {
            isGir = !isGir;
            if (isGir) {
                $(this).css({color: '', borderColor: ''});
                $('#gir').show();
                isHoverGir = false;
                startGir();
            }
            else {
                $('#gir').hide();
            }
            
            $(this).removeClass('off');
        }).hover(function() {
            isHoverGir = true;
            if (isGir) {
                $(this).addClass('off');
            }
            else {
                hoverGir();
            }
        }, function() {
            isHoverGir = false;
            $(this).css({color: '', borderColor: ''});
            $(this).removeClass('off');
        });

        // --- Показать все сообщения списком ----------------------
        $('#switcher-all-messages').click(function() {
            $('#all-messages').show();
            $('#shadow-all-messages').fadeIn();
            showAllMessages();
        });

        $('#all-messages').click(function() {
            $('#all-messages, #shadow-all-messages').hide();
        });
        
        function showAllMessages() {
            var text = '<div class="ballon-star"><div class="star toy"><div></div></div><div class="ballon-text"></div><div class="ballon-author"></div></div>';
            for (var i = win.elka.messages.length - 1;  i >= 0; i--) {
                var m = win.elka.messages[i];
                text += '<div class="ballon"><div class="toy ' + m.toy + '"><div></div></div><div class="ballon-text">' + m.text + '</div><div class="ballon-author">' + m.author + '</div></div>';
            }
            
            $('#all-messages > div.container').html(text);
            var el = $('#all-messages div.ballon-star');
            $('.ballon-text', el).html($('#ballon-star .ballon-text').html());
            $('.ballon-author', el).html($('#ballon-star .ballon-author').html());
        }
    }
})(jQuery);