/**
 * © DewPoint
 * @author Хрищанович Анастасия
 * @date 16.03.2011
 */

$(function () {
	// Установка ширины подменю в главном меню
	$('.header_menu>li>p').each (function() {
		var lev_2_width = $(this).width();
		$($($(this).parents('.header_menu>li')).children('div.level_2')).css({
			'width': lev_2_width + 33
		});
	});
	
	// Ховеры
	$('.hovered').hover(function () {
		$(this).addClass('hover');
		
		$('li.hover div.level_2').css('display', 'block');
		
		//$('.header_menu li .logo_gs_small').css('display', 'none');
	},
	function () {
		$(this).removeClass('hover'); 
		
		$('div.level_2').css('display', 'none');
		//$('.header_menu li .logo_gs_small').css('display', 'block');
	});
	
	// Показать/спрятать форму входа
	$('a.ref_input').toggle(function() {
			$('#centr_part .reference_input').addClass('active_ref');
		}, function() {
			$('#centr_part .reference_input').removeClass('active_ref');
	});
	
	
	
	// Подсветка баннеров
	$('.bb_img a').hover(function () {
		
		var ind = $('.bb_img a').index(this);
		
		if (!$(this).data('originalSizes')) {
			var _h = $(this).height(),
				_w = $(this).width(),
			
				_left = $(this).position().left,
			
				_h_img = $('img', this).height(),
				_w_img = $('img', this).width();
	
			$(this).data('originalSizes', {w: _w, h: _h, l: _left});
			$('img', this).data('originalSizes', {w: _w_img, h: _h_img});
		}

		$(this).animate({
			width: $(this).data('originalSizes').w + 30,
			height: $(this).data('originalSizes').h + 30,
			left: $(this).data('originalSizes').l - 15
		}, 200);
		
		$('img', this).animate({
			width: $(this).data('originalSizes').w + 30,
			height: $(this).data('originalSizes').h + 30
		}, 200);	
		
		$($('#bb_href a').get(ind)).show();
	},
	function () {

		$(this).animate({
			width: $(this).data('originalSizes').w,
			height: $(this).data('originalSizes').h,
			left: $(this).data('originalSizes').l
		}, 200);
		
		$('img', this).animate({
			width: $(this).data('originalSizes').w,
			height: $(this).data('originalSizes').h
		}, 200);
		
		$('#bb_href a').hide();

	});
	
	// Карусель
/*
	$('.date').click(function () {
		$('.date').removeClass('dark');
		$(this).addClass('dark');
	});
*/
		
		// Подсветка активного элемента
//		$('.mycarousel').jcarousel({
//			visible: 3,
//	        animation: 600,
////	        start: 5,
//			itemFirstInCallback:  mycarousel_itemFirstInCallback,
//	    });
	
		var _timer = null;
		//var curState = null;
	
		$('.jcarousel-prev').click( function () {
			clearTimeout(_timer);
			_timer = setTimeout(function () {
				var _parent = $('.dark').parents('li');
				if (!_parent.prev().is('.first')) {
					$('.dark').removeClass('dark');
					$('.date', _parent.prev()).addClass('dark');
				}
				
			}, 600);
			//return false;
		});
	
		$('.jcarousel-next').click( function () {
			clearTimeout(_timer);
			_timer = setTimeout(function () {
				var _parent = $('.dark').parents('li');
				if (!_parent.next().is('.last')) {
					$('.dark').removeClass('dark');
					$('.date', _parent.next()).addClass('dark');
				}
			}, 600);
		});
	
		/*function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
		    //display('Item #' + idx + ' is now the first item');
			reloadNews(idx, '<?php echo Zend_Registry::get('lang');?>');
		};*/

		// $('#for_dates .mycarousel li:first').before('<li class="first"></li>');
		// $('#for_dates .mycarousel li:last').after('<li class="last"></li>');
	/*
		$('.jcarousel-prev').click( function () {
			
			var i, stop = false;
            
            $('#for_dates .jcarousel-item').each(function( i ) {
                 if ( $('div', this).is('.dark') && !stop) {
                      $('.jcarousel-item .dark').removeClass('dark');
                      $($('.jcarousel-item div').get(i-1)).addClass('dark');
                      stop = true;
                 }
            });
		});
		
		$('.jcarousel-next').click( function () {
			var i, stop = false;
            
            $('#for_dates .jcarousel-item').each(function( i ) {
                 if ( $('div', this).is('.dark') && !stop) {
                      $('.jcarousel-item .dark').removeClass('dark');
                      $($('.jcarousel-item div').get(i+1)).addClass('dark');
                      stop = true;
                 }
            });
		});
	*/
		
		$('.sl').each(function () {

			if ($('.slider ul li', this).length >= 3) {
				
				$('.next, .prev', this).css('display','block');
				
				$('.slider', this).css('left', '-5000');
				
				$('.slider', this).jCarouselLite({
		    		btnNext: $('.next', this),
		    		btnPrev: $('.prev', this),
		    		circular: true,
		    		visible: 2
				});
				
				$('.slider a', this).lightBox();
			}
			
			else {
				/*$('.slider', this).addClass('slider_one');
				$('.slider', this).removeClass('slider');
				$(this).removeClass('sl');*/
				$('.slider_one a', this).lightBox();
				
				$('.slider a', this).lightBox();
			}
		});

});
