﻿/* ------------- BASE ------------- */
var metaTags = document.getElementsByTagName('meta'), BASE = '/';
for (var i = 0; i < metaTags.length; i++) if (metaTags[i].getAttribute('name') == 'base') {BASE = metaTags[i].getAttribute('content'); break;}



/* ------------- Cufon ------------- */
Cufon.replace('.site-hotline .title', {fontFamily: 'a_FuturaRound', fontSize: '13px', fontWeight: 'bold', separate: 'none'});
Cufon.replace('.site-hotline .number', {fontFamily: 'a_FuturaRound', fontSize: '33px', fontWeight: 'bold', separate: 'none'});
Cufon.replace('.site-phone .number', {fontFamily: 'a_FuturaRound', fontSize: '22px', fontWeight: 'bold', separate: 'none'});
Cufon.replace('.ibox .phone .title', {fontFamily: 'a_FuturaRound', fontSize: '10px', separate: 'none'});
Cufon.replace('.ibox .phone .number', {fontFamily: 'a_FuturaRound', fontSize: '22px', separate: 'none'});
Cufon.replace('.ibox .worktime .days', {fontFamily: 'a_FuturaRound', fontSize: '13px', separate: 'none'});
Cufon.replace('.ibox .worktime .time', {fontFamily: 'a_FuturaRound', fontSize: '15px', separate: 'none'});
Cufon.replace('.contacts .phone .title', {fontFamily: 'a_FuturaRound', fontSize: '10px', fontWeight: 'bold', separate: 'none'});
Cufon.replace('.contacts .phone .number', {fontFamily: 'a_FuturaRound', fontSize: '18px', fontWeight: 'bold', separate: 'none'});
Cufon.replace('.nopage .phone .title', {fontFamily: 'a_FuturaRound', fontSize: '12px', fontWeight: 'bold', separate: 'none'});
Cufon.replace('.nopage .phone .number', {fontFamily: 'a_FuturaRound', fontSize: '24px', fontWeight: 'bold', separate: 'none'});
Cufon.replace('.movie .nearest .phone .title', {fontFamily: 'a_FuturaRound', fontSize: '10px', separate: 'none'});
Cufon.replace('.movie .nearest .phone .number', {fontFamily: 'a_FuturaRound', fontSize: '22px', separate: 'none'});



/* ------------- DOM Ready ------------- */
var teasersTopStart = 1;
$(function(){
// teasers-top carousel
    var $teasersTopList = $('.teasers-top .list'),
        $teasersTopPrev = $('.teasers-top .control-prev'),
        $teasersTopNext = $('.teasers-top .control-next');
    $('.teasers-top .list ul').jcarousel({
        scroll: 7,
        animation: 500,
        easing: 'easeOutExpo',
        start: teasersTopStart,
        initCallback: function(carousel, state){
            $teasersTopList.addClass('list-carousel');
            $teasersTopPrev.click(function(){
                carousel.prev();
            });
            $teasersTopNext.click(function(){
                carousel.next();
            });
        },
        buttonPrevCallback: function(carousel, button, enabled){
            if (enabled) {
                $teasersTopPrev.removeClass('control-disabled');
            } else {
                $teasersTopPrev.addClass('control-disabled');
            }
        },
        buttonNextCallback: function(carousel, button, enabled){
            if (enabled) {
                $teasersTopNext.removeClass('control-disabled');
            } else {
                $teasersTopNext.addClass('control-disabled');
            }
        }
    });

// slideshow carousel
    var $slideshowPrev = $('.slideshow .control-prev'),
        $slideshowNext = $('.slideshow .control-next');
    $('.slideshow .list ul').jcarousel({
        scroll: 1,
        animation: 300,
        easing: 'easeOutExpo',
        start: 1,
        initCallback: function(carousel, state){
            $slideshowPrev.click(function(){
                carousel.prev();
            });
            $slideshowNext.click(function(){
                carousel.next();
            });
        },
        buttonPrevCallback: function(carousel, button, enabled){
            if (enabled) {
                $slideshowPrev.removeClass('control-disabled');
            } else {
                $slideshowPrev.addClass('control-disabled');
            }
        },
        buttonNextCallback: function(carousel, button, enabled){
            if (enabled) {
                $slideshowNext.removeClass('control-disabled');
            } else {
                $slideshowNext.addClass('control-disabled');
            }
        }
    });

// slideshow fancybox
    $('.slideshow .list a').fancybox({
        overlayOpacity: .8,
        overlayColor: '#ff9800',
        padding: 0
    });

// single image pop-up (fancybox)
    $('a.popup').fancybox({
        overlayOpacity: .8,
        overlayColor: '#ff9800',
        padding: 0
    });

// galleries-type jSelect
    $('.galleries-type select').jSelect({speed: 50});

// galleries-date jSelect
    $('.galleries-date select').jSelect({speed: 50});

// hall-select jSelect
    $('.hall-select select').jSelect({speed: 50});

// programs jCheckbox
    $('.programs .input-checkbox input').jCheckbox();

// gallery fancybox
    $('.gallery .list a').fancybox({
        overlayOpacity: .8,
        overlayColor: '#ff9800',
        padding: 0
    });

// video-box fancybox
/*
    $('.video-box .img a').fancybox({
        overlayOpacity: .8,
        overlayColor: '#ff9800',
        padding: 0
    });
*/

    $('.video-box .img a').click(function() {
        $.fancybox({
            overlayOpacity: .8,
            overlayColor: '#ff9800',
            padding: 0,
            width : 640,
            height : 480,
            href : this.href.replace(new RegExp('([0-9])', 'i'), 'moogaloop.swf?clip_id=$1') + '&amp;title=0&amp;byline=0&amp;portrait=0&amp;color=e87f00',
            type : 'swf'
        });

        return false;
    });



// programs programExpand
    $('.programs .list').programExpand({speed: 300});

// programs programTotal
    $('.programs .total').programTotal();

// mapSelect
    $('.map-select').mapSelect({speed: 300});

// scheduleSelect
    $('.schedule-select').scheduleSelect({speed: 200});

// contacts equalHeaight
    $('.contacts .i').equalHeight(4);
    $('.contacts .xtra').css({'position': 'absolute'});

// vacancies equalHeaight
    $('.vacancies .i').equalHeight(3);

// articles equalHeaight
    $('.articles .i').equalHeight(3);
    $('.articles .xtra').css({'position': 'absolute'});

// contacts equalHeaight
    $('.galleries .i').equalHeight(3);
    $('.galleries .xtra').css({'position': 'absolute'});

// events equalHeaight
    $('.events .i').equalHeight(3);
    $('.events .xtra').css({'position': 'absolute'});
    $('.autoclub-list .i').equalHeight(4);

// posters-big equalHeaight
    $('.posters-big .list .i').equalHeight(3);
    $('.posters-big .list .times').css({'position': 'absolute'});

// stars equalHeaight
    $('.stars .list .i').equalHeight(4);
    $('.stars .list').starsDescr();

// feedback jSelect
    $('.feedback select').jSelect({speed: 50});

// calendar fbox
    $('.calendar .event-descr').fBox({speed: 140});

// feedback formPost
    $('.feedback form').formPost({url: BASE + 'contacts?ajax=1', speed: 300});

// club-signup formPost
    $('.club-signup form').formPost({url: BASE + 'services/concierge?ajax=1', speed: 300});

// placeHolder
    $('label.placeholder').placeHolder();

// tooltip
    $('.lang .tooltip').tooltip({
        delay: 0,
        fade: 100,
        track: true,
        showURL: false,
        extraClass: 'lang-tooltip png'
    });

// tooltip
    $('.m1 .tooltip').tooltip({
        delay: 0,
        fade: 100,
        track: true,
        showURL: false,
        extraClass: 'm1-tooltip png'
    });

// tooltip
    $('.teasers-top .tooltip').tooltip({
        delay: 0,
        fade: 100,
        track: true,
        showURL: false,
        extraClass: 'teasers-top-tooltip png'
    });

// hint
    $('.movie-times td').hint({speed: 300});

// calc
    $('.calc select').jSelect({speed: 50});
    $('.calc .input-checkbox input').jCheckbox();
    $('.calc .col2 .add').calcAdd({elements: '.input-select-attr', visibleClass: 'input-select-visible'});
    $('.calc .col3 .add').calcAdd({elements: '.input-select-menu', visibleClass: 'input-select-visible'});
    $('.calc').calcCount();

// hoverFix
    $('.button').hoverFix('button-hover');
    $('.event-descr-headers span').hoverFix();

// IE6 PNG Fix
    if (typeof(DD_belatedPNG) == 'object') {
        var hasPNG = '.png';
        hasPNG += ', .corner';
        hasPNG += ', .circles';
        hasPNG += ', .pages li';
        hasPNG += ', .video-box i';
        hasPNG += ', .button, .button i';
        hasPNG += ', .button-share, .button-share i';
        hasPNG += ', .button-teaser, .button-teaser i';
        hasPNG += ', .button-download, .button-download i';
        DD_belatedPNG.fix(hasPNG);
    }
});



/* ------------- PLUGINS ------------- */

/* calcAdd
----------------------------------------------- */
(function($){
$.fn.calcAdd = function(o){
    o = $.extend({
        elements: null,
        visibleClass: null
    }, o || {});

    var $button = $(this),
        $elements = $(o.elements);

    $button.click(function(){
        $elements.each(function(i){
            var $element = $(this);
            if ($element.hasClass(o.visibleClass)) {
                return true;
            }
            $element.addClass(o.visibleClass);
            if (i + 1 == $elements.length) {
                $button.hide();
            }
            return false;
        });
    });

    return this;
};
})(jQuery);



/* calcCount
----------------------------------------------- */
(function($){
$.fn.calcCount = function(o){
    return this.each(function(){
        var $root = $(this),
            $inputPeople = $('input:text', $root),
            $checkboxes = $('input:checkbox', $root),
            $selects = $('select', $root),

            $inputs = $inputPeople.add($checkboxes).add($selects),
            $total = $('.calcTotal', $root),
            sum = 0;

        $inputPeople.keydown(function(e){
            if (!(
                    e.which == 8 ||
                    e.which == 9 ||
                    e.which == 37 ||
                    e.which == 39 ||
                    e.which == 46 ||
                    ( e.which >= 48 && e.which <= 57 ) ||
                    ( e.which >= 96 && e.which <= 105 )
                )
            ) {
                return false;
            }
        }).keyup(calculate);

        $inputs.change(calculate);
        
        function calculate() {
            sum = 0;
            $checkboxes.filter(':checked').each(function(){
                sum += parseInt($(this).val());
            });
            $selects.each(function(){
                sum += parseInt($(this).val());
            });
            sum = sum * parseInt($inputPeople.val());

            if (isNaN(sum)) {
                sum = 0;
            }

            $total.html(sum);
        }
    });
};
})(jQuery);



/* hint
----------------------------------------------- */
(function($){
$.fn.hint = function(o){
    o = $.extend({
        speed: 500
    }, o || {});

    var $win = $(window), $doc = $(document), $body = $('body'),
        $hint, $l, $r, $content;

    hintInit = function(){
        if ($('#hint').length) {
            $hint = $('#hint');
            $bgL = $('.l', $hint);
            $bgR = $('.r', $hint);
            $сontent = $('.content', $hint);
        } else {
            $hint = $('<div id="hint" />');
            $bgL = $('<div class="l" />').appendTo($hint);
            $bgR = $('<div class="r" />').appendTo($hint);
            $сontent = $('<div class="content" />').appendTo($hint);
        }

        $hint.css({opacity: 0.5});

        $body.append($hint);
    }

    hintInit();

    return this.each(function(){
        var $el = $(this),
            $title = $el.attr('title');
            
        $el.attr('title', '');
        
        $el.hover(
            function(){
                var elOffset = $el.offset(),
                    elWidth = $el.width(),
                    elHeight = $el.height();
                
                $сontent.html($title);

                var hintOffsetLeft = elOffset.left + ( elWidth / 2 ) - ( $сontent.outerWidth(true) / 2 ),
                    hintOffsetTop = elOffset.top + elHeight;

                $hint.css({left: hintOffsetLeft, top: hintOffsetTop}).fadeTo(o.speed, 1);
            },
            function(){
                $hint.css({opacity: 0, left: -9999});
            }
        );
    });
};
})(jQuery);



/* programExpand
----------------------------------------------- */
(function($){
$.fn.programExpand = function(o){
    o = $.extend({
        speed: 500
    }, o || {});

    return this.each(function(){
        var $list = $(this),
            $hArray = $('.h', $list);

        $hArray.click(function(){
            var $h = $(this),
                $descr = $h.next();

            $descr.mySlideToggle({speed: o.speed});
        }).hover(
            function(){
                $(this).addClass('h-hover');
            },
            function(){
                $(this).removeClass('h-hover');
            }
        );
    });
};
})(jQuery);



/* mySlideToggle
----------------------------------------------- */
(function($){
$.fn.mySlideToggle = function(o){
    o = $.extend({
        show: null,
        speed: 500
    }, o || {});

    return this.each(function(){
        var $el = $(this),
            elHeight = $el.height(),
            isVisible = $el.is(':visible');

        if (o.show == null) o.show = !isVisible;

        if (o.show == isVisible) return this;

        if (!isVisible) {
            elHeight = $el.show().height();
            $el.hide().height(0);
        }

        if (o.show) {
            $el.show().animate({'height': elHeight}, {
                'duration': o.speed
            });
        } else {
            $el.animate({'height': 0}, {
                'duration': o.speed,
                'complete': function(){
                    $el.hide().css('height', '');
                }
            });
        }
    });
};
})(jQuery);



/* programTotal
----------------------------------------------- */
(function($){
$.fn.programTotal = function(o){
    o = $.extend({
        speed: 500
    }, o || {});

    return this.each(function(){
        var $container = $(this),
            $inputArray = $('input:checkbox', $container),
            $price = $('.price-val', $container);

        $inputArray.change(function(){
            var $input = $(this),
                priceVal = parseInt($price.text()),
                inputVal = parseInt($input.val());

            if ($input.is(':checked')) {
                $price.text(priceVal + inputVal);
            } else {
                $price.text(priceVal - inputVal);
            }
        });
    });
};
})(jQuery);



/* mapSelect
----------------------------------------------- */
(function($){
$.fn.mapSelect = function(o){
    o = $.extend({
        speed:  500
    }, o || {});

    return this.each(function(){
        var $selectItems = $('span', this),

            $descrContent = $('.map-descr-content'),
            $descrItems = $('.map-descr-i'),

            $imgContent = $('.map-img-content'),
            $imgItems = $('.map-img-i'),

            busy = false;

        $selectItems.click(function(){
            var $selectItem = $(this);

            if (!busy && !$selectItem.hasClass('a')) {
                busy = true;

                var index = $selectItems.index($selectItem),
                    $descrItem = $descrItems.eq(index),
                    $imgItem = $imgItems.eq(index);

                var descrHeight = $descrItem.show().height();
                $descrItem.hide();

                var imgHeight = $imgItem.show().height();
                $imgItem.hide();

                $selectItems.removeClass('a');
                $selectItem.addClass('a');

                $descrContent.height($descrContent.height());
                $descrItems.filter(':visible').fadeOut(o.speed, function(){
                    $descrContent.animate({'height': descrHeight}, {
                        queue: false,
                        duration: o.speed,
                        complete: function(){
                            $descrItem.fadeIn(o.speed);
                        }
                    });
                });

                $imgContent.height($imgContent.height());
                $imgItems.filter(':visible').fadeOut(o.speed, function(){
                    $imgContent.animate({'height': imgHeight}, {
                        queue: false,
                        duration: o.speed,
                        complete: function(){
                            $imgItem.fadeIn(o.speed, function(){
                                busy = false;
                            });
                        }
                    });
                });
            }
        }).hover(
            function(){
                $(this).addClass('hover');
            },
            function(){
                $(this).removeClass('hover');
            }
        );
    });
};
})(jQuery);



/* scheduleSelect
----------------------------------------------- */
(function($){
$.fn.scheduleSelect = function(o){
    o = $.extend({
        speed:  500
    }, o || {});

    return this.each(function(){
        var $selectItems = $('span', this),
            $content = $('.schedule-content'),
            $items = $('.schedule-i'),
            busy = false;

        $selectItems.click(function(){
            var $selectItem = $(this);

            if (!busy && !$selectItem.hasClass('a')) {
                busy = true;

                var index = $selectItems.index($selectItem),
                    $item = $items.eq(index),
                    itemHeight = $item.show().height();

                $item.hide();

                $selectItems.removeClass('a');
                $selectItem.addClass('a');

                $content.height($content.height());
                $items.filter(':visible').fadeOut(o.speed, function(){
                    $content.animate({'height': itemHeight}, {
                        queue: false,
                        duration: o.speed,
                        complete: function(){
                            $item.fadeIn(o.speed, function(){
                                busy = false;
                            });
                        }
                    });
                });
            }
        }).hover(
            function(){
                $(this).addClass('hover');
            },
            function(){
                $(this).removeClass('hover');
            }
        );
    });
};
})(jQuery);



/* placeHolder
----------------------------------------------- */
(function($){
$.fn.placeHolder = function(o){
    o = $.extend({
        'classNames': 'placeholder'
    }, o || {});

    return this.each(function(){
        var $label = $(this),
            labelText = $label.text(),
            $input = $('#' + $label.attr('for')),
            isTextarea = ($input.get(0).nodeName.toLowerCase() == 'textarea');

        $input.data('placeholder', labelText);

        if ($input.val() == '' || $input.val() == labelText) {

            if (isTextarea) $input.text(labelText);
            $input.val(labelText).addClass(o.classNames).focus(function(){
                if ($input.val() == labelText) {
                    if (isTextarea) $input.text('');
                    $input.val('');
                }
                $input.removeClass(o.classNames);
            }).blur(function(){
                if ($input.val() == '') {
                    if (isTextarea) $input.text(labelText);
                    $input.val(labelText).addClass(o.classNames);
                }
            });
        }
    });
};
})(jQuery);



/* jCheckbox
----------------------------------------------- */
(function($){
$.fn.jCheckbox = function(o){
    o = $.extend({
        initClass:    'jcheckbox',
        checkedClass: 'jcheckbox-checked'
    }, o || {});

    return this.each(function(){
        var $input = $(this),
            $label = $('label[for="' + $input.attr('id') + '"]');

        $label.addClass(o.initClass);

        if ($input.is(':checked')) {
            $label.addClass(o.checkedClass);
        }

        $input.css({'position': 'absolute', 'left': '-9999px'}).click(function(){
            if ($input.is(':checked')) {
                $label.addClass(o.checkedClass);
            } else {
                $label.removeClass(o.checkedClass);
            }
        });
    });
};
})(jQuery);



/* jSelect
----------------------------------------------- */
(function($){
$.fn.jSelect = function(o){
    o = $.extend({
        speed: 300
    }, o || {});

    var $doc = $(document),
        isExpanded = false;

    return this.each(function(){
        var $select = $(this),
            selectWidth = this.offsetWidth,
            $optionArray = $('option', $select),
            $optionSelected = $optionArray.filter(':selected'),
            optionSelectedText = $optionSelected.text(),

            $jSelect = $('<div class="jselect" />'),
            $jSelectTitle = $('<div class="jselect-title png" />').appendTo($jSelect),
            $jSelectTitleBG = $('<div class="jselect-title-bg png" />').appendTo($jSelectTitle),
            $jSelectTitleSPAN = $('<span />').appendTo($jSelectTitleBG),
            $jSelectTitleR = $('<i class="jselect-title-r" />').appendTo($jSelectTitle),
            $jSelectList = $('<div class="jselect-list png" />').appendTo($jSelect),
            $jSelectListUL = $('<ul class="png" />').appendTo($jSelectList),
            $jSelectListArr = $('<div class="jselect-arr"><i class="png"></i></div>').appendTo($jSelectTitle);

        $select.hide();
        $jSelect.width(selectWidth);
        $jSelectTitleSPAN.text(optionSelectedText);

        $optionArray.each(function(i){
            var itemHTML = $(this).html();

            $('<li />', {
                html: itemHTML,
                click: function(){
                    set(i, itemHTML);
                }
            }).hover(
                function(){
                    $(this).addClass('hover');
                },
                function(){
                    $(this).removeClass('hover');
                }
            ).appendTo($jSelectListUL);
        });

        $jSelect.insertAfter($select);

        $jSelect.click(function(e){
            e.stopPropagation();

            if ($jSelect.hasClass('jselect-expanded')) {
                hide();
            } else {
                if (isExpanded) {
                    hide();
                    show();
                } else {
                    show();
                }
            }
        });

        $doc.click(function(){
            if (isExpanded) {
                hide();
            }
        });

        function show() {
            $jSelect.addClass('jselect-expanded');
            $jSelectList.show();
            isExpanded = true;
        }

        function hide() {
            $('.jselect').removeClass('jselect-expanded');
            $('.jselect-list').hide();
            isExpanded = false;
        }

        function set(i, itemHTML) {
            $jSelectTitleSPAN.text(itemHTML);
            $select.val($optionArray.eq(i).val()).change();
        }
    });
};
})(jQuery);



/* formPost
----------------------------------------------- */
(function($){
$.fn.formPost = function(o){
    o = $.extend({
        url: '',
        type: 'post',
				dataType: 'json',
        speed: 500
    }, o || {});

    return this.each(function(){
        var $form = $(this),
            $inputArray = $('input, select, textarea, button', $form),
            $submitButton = $('button:submit', $form),
            $loading = $('.loading', $form),
            $statusOk = $('.status-ok', $form),
            $statusError = $('.status-error', $form);

        $form.validate({
            errorPlacement: function(error, el) {
            },
            highlight: function(el, errorClass) {
                $(el).closest('.i').addClass('i-error');
            },
            unhighlight: function(el, errorClass) {
                $(el).closest('.i').removeClass('i-error');
            },
            submitHandler: function() {
                $inputArray.blur();
                $submitButton.attr('disabled', 'disabled').fadeOut(o.speed, function(){
                    $loading.fadeIn(o.speed, function(){
											  $statusOk.fadeOut(o.speed);
                        $statusError.fadeOut(o.speed);
                        $form.ajaxSubmit({
                            url: o.url,
                            type: o.type,
                            success: function(responseText, statusText, xhr, $form){
                                $loading.fadeOut(o.speed, function(){
                                    if(responseText.errors)
                                    {
                                      $.each(responseText.errors, function(i, el)
                                      {
                                        $(el).closest('div.i-text').addClass('i-error');
                                      });
                                      $submitButton.attr('disabled', '').fadeIn(o.speed);
                                    }
                                    if(responseText.mailSent == '1') 
                                    {
                                      $statusOk.fadeIn(o.speed);
                                    }
                                    else
                                    {
                                      $statusError.fadeIn(o.speed);
																			$submitButton.attr('disabled', '').fadeIn(o.speed);
                                    }
                                });
                            }
                        });
                    });
                });
            }
        });

        $.validator.addClassRules('requiredph', {
            requiredph: true
        });
    });
};
})(jQuery);



/* equalHeight
----------------------------------------------- */
(function($){
$.fn.equalHeight = function(val){
    var colsTotal = val || 3;

    var row = [], rowHeight = 0, itemsTotal = this.length;

    return this.each(function(i){
        var $item = $(this),
            itemHeight = $item.height();

        row.push(this);

        rowHeight = itemHeight > rowHeight ? itemHeight : rowHeight;

        if ( (i+1) % colsTotal == 0 || (i+1) == itemsTotal ) {
            $(row).height(rowHeight);
            row = [], rowHeight = 0;
        }
    });
};
})(jQuery);



/* hoverFix
----------------------------------------------- */
(function($){
$.fn.hoverFix = function(value){
    var classNames = value || 'hover';

    return this.each(function(){
        var $el = $(this);

        $el.hover(
            function(){
                $el.addClass(classNames);
            },
            function(){
                $el.removeClass(classNames);
            }
        );
    });
};
})(jQuery);



/* fBox
----------------------------------------------- */
(function($){
$.fn.fBox = function(o){
    var o = $.extend({
        speed: 300
    }, o || {});
    
    var $descrArray = $(this),
        $win = $(window), $doc = $(document), $body = $('body'),
        $fBox, $fBoxBg, $fBoxContent, $fBoxTop, $fBoxBot;

    fBoxInit = function(){
        $('#fBox').remove();

        $fBox = $('<div id="fBox" />').css({opacity: 0}).show();
        $fBoxTop = $('<div class="fbox-top" />').appendTo($fBox);
        $fBoxBg = $('<div class="fbox-bg" />').appendTo($fBox);
        $fBoxBot = $('<div class="fbox-bot" />').appendTo($fBox);
        $fBoxClose = $('<div class="fbox-close" />').appendTo($fBox);
        $fBoxContent = $('<div class="fbox-content" />').appendTo($fBoxBg);
        $body.append($fBox);
    }

    fBoxInit();

    $descrArray.data('current', false);

    return this.each(function(){
        var $descr = $(this),
            $parent = $descr.parent(),
            parentOffset = $parent.offset(),
            $imgArray = $('.img', $parent),
            $descrContent = $('.event-descr-content', $descr),
            $descrItemsArray = $('.event-descr-i', $descr),
            $headersArray = $('.event-descr-headers span', $descr);

        $win.resize(function(){
            parentOffset = $parent.offset();
        });

        $parent.click(function(){
            if (!$descr.data('current')) {
                $descrArray.data('current', false);
                $descr.data('current', true);

                $fBoxContent.html($descr);
    
                $headersArray.unbind('click');
                $headersArray.click(function(){
                    var $header = $(this);
    
                    if (!$header.hasClass('act')) {
                        var index = $headersArray.index($header),
                            $img = $imgArray.eq(index);
                            $descrItem = $descrItemsArray.eq(index);
    
                        $headersArray.removeClass('act');
                        $header.addClass('act');
    
                        $descrContent.height($descrContent.height());
    
                        $descrItem.show();
                        var descrItemHeight = $descrItem.height();
                        $descrItem.hide();
    
                        $imgArray.hide();
                        $img.show();
    
                        $descrItemsArray.hide();
    
                        $descrContent.animate({
                            height: descrItemHeight
                        }, {
                            queue: false,
                            duration: o.speed,
                            complete: function(){
                                $descrItem.show();
                            }
                        });
                    }
                });
    
                fBoxOffset = {
                    left: parentOffset.left + $parent.width(),
                    top: parentOffset.top
                };
    
                $fBox.css({left: fBoxOffset.left, top: fBoxOffset.top + 30}).animate({
                    top: fBoxOffset.top,
                    opacity: 1
                }, {
                    queue: false,
                    duration: o.speed
                });
            }
        });

        $fBoxClose.click(function(){
            $fBox.animate({
                top: fBoxOffset.top - 30,
                opacity: 0
            }, {
                queue: false,
                duration: o.speed,
                complete: function(){
                    $fBox.css({left: -9999});
                }
            });
        });
    });
};
})(jQuery);



/* starsDescr
----------------------------------------------- */
(function($){
$.fn.starsDescr = function(){
    return this.each(function(){
        var $items = $('.i', this);
        
        $items.click(function(){
            var $item = $(this);

            if ($item.hasClass('i-act')) {
                $item.removeClass('i-act');
            } else {
                $items.removeClass('i-act');
                $item.addClass('i-act');
            }
        });
    });
};
})(jQuery);
