function setMouseOverImages($parentClass) {

    $($parentClass + ' .item').bind('mouseover', function() {

        $(this).find('.galleryDarkLayer').hide();
    });

    $($parentClass + ' .item').bind('mouseout', function() {

        $(this).find('.galleryDarkLayer').show();
    });
}


function setMouseOverNews($parentClass) {

    $($parentClass + ' .item').bind('mouseover', function() {
    
        $(this).find('.galleryDarkLayer').hide();
        $(this).addClass('mouseOverPostText');
    });

    $($parentClass + ' .item').bind('mouseout', function() {
    
        $(this).find('.galleryDarkLayer').show();
        $(this).removeClass('mouseOverPostText');
    });
}


function menuTreeToggled() {
    
    $('.tours .slideMenu').bind('click', function() {
    
        if (($(this).parents(':first').children('ul').css('display') != 'none') && $(this).parents(':first').children('ul').get(0)) { return false; }

        $('.tours .slideMenu').each(function() {

            $(this).parents(':first').children('ul').slideUp('slow');
        });

        //$(this).parents(':first').children('ul').slideDown('slow');
        var $h = $(this).parents(':first').children('ul').show().height();
        $(this).parents(':first').children('ul').height(0);
        $(this).parents(':first').children('ul').animate({height:$h}, {duration:400, easing:'swing', queue:false});

        return false;
    });
}


// слайдер
function theRotator() {

    this.intervalId;
    this.interval = 5000;
    this.canSlide = true;
    this.next = '.sl-next';
    this.prev = '.sl-prev';

    $('div#rotator ul li').css({opacity: 0.0});
    $('div#rotator ul li:first').css({opacity: 1.0});

    var $this = this;
    this.intervalId = setInterval(function () { $this.rotate(1); }, this.interval);

    var $this = this;
    $(this.next).bind('click', function() { $this.changeImage(1); });
    $(this.prev).bind('click', function() { $this.changeImage(0); });
}

theRotator.prototype.changeImage = function($direction) {

    if (!this.canSlide) { return false; }

    clearInterval(this.intervalId);
    this.rotate($direction);
    
    var $this = this;
    this.intervalId = setInterval(function () { $this.rotate(1); }, this.interval);
}

theRotator.prototype.rotate = function($direction) {

    var current = ($('div#rotator ul li.show')?$('div#rotator ul li.show') : $('div#rotator ul li:first'));
    
    if ($direction) {
        
        var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));
    } else {

        var next = ((current.prev().length) ? ((current.prev().hasClass('show')) ? $('div#rotator ul li:last') :current.prev()) : $('div#rotator ul li:last'));
    }
 
    var $this = this;
    $this.canSlide = false;
    next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, {duration:700, easing:'linear'});
    current.animate({opacity: 0.0}, {duration:700, easing:'swing', queue:false, complete:function() { $this.canSlide = true; } }).removeClass('show');
}
// /слайдер


$(function() {

    // target="_blank"
    $("a.blank").live('click', function() {
        
        window.open($(this).attr('href'));
        return false;
    }); 
    
    
    var $rotator = new theRotator();
    

    $(".lightbox").lightbox();

    
    // search
    $('.searchInp').bind('blur', function() {
    
        var $searchValue = $.trim($(this).val());

        if ($searchValue == '') { $searchValue = $(this).attr('title'); }

        $(this).val($searchValue);
    })

    $('.searchInp').bind('focus', function() {

        if ($(this).val() == $(this).attr('title')) { $(this).val(''); }
    });

    $('#searchForm').bind('submit', function () {
    
        var $searchValue = $.trim($('.searchInp').val());
        if ($searchValue == '' || $searchValue == $('.searchInp').attr('title')) { return false; }
    });
    // /search

    
    // adds classes for colorTable
    $('.colorTable').each(function() {

        // set colors
        $(this).find('tr:even').attr('class', 'dark');

        var $firstTr = $(this).find('tr').first();
        if ($($firstTr).find('td').length <= 0) {

            $($firstTr).attr('class', 'tableHeader');
            
            var $headerCells = $($firstTr).find('th,td');
            $($headerCells).first().addClass('first');
            $($headerCells).last().addClass('last');
        }

        
        // set links
        $(this).find('tr').each(function() {

            var $tr = this;

            if ($(this).find('a').length == 1) { // if it's a single link - make it on a table row

                var $href = $(this).find('a').first().attr('href');
                $($tr).css('cursor', 'pointer').bind('click', function() {
                
                    self.location = $href;
                });
            }
        });

        var $lastRowCells = $(this).find('tr').last().find('td');
        $($lastRowCells).first().addClass('first');
        $($lastRowCells).last().addClass('last');
    });
});


