$(document).ready(function(){
	
	// shake affect ************************************************************
	var _shakeEl = $('#nav > li > a, ul.nav-bottom a');
	var _shakeDuration = 200;
	var _shakeDif = 1;
	
	_shakeEl.each(function(){
		$(this).parent().css('width',$(this).parent().width());
		$(this).mouseenter(function(){
			$(this).animate({'marginLeft':_shakeDif,'marginRight':-_shakeDif},{duration:_shakeDuration/4});
			$(this).animate({'marginLeft':0,'marginRight':0},{duration:_shakeDuration/4});
			$(this).animate({'marginRight':_shakeDif,'marginLeft':-_shakeDif},{duration:_shakeDuration/4});
			$(this).animate({'marginRight':0,'marginLeft':0},{duration:_shakeDuration/4});
			$(this).animate({'marginLeft':_shakeDif,'marginRight':-_shakeDif},{duration:_shakeDuration/4});
			$(this).animate({'marginLeft':0,'marginRight':0},{duration:_shakeDuration/4});
			$(this).animate({'marginRight':_shakeDif,'marginLeft':-_shakeDif},{duration:_shakeDuration/4});
			$(this).animate({'marginRight':0,'marginLeft':0},{duration:_shakeDuration/4});
		});		
	});
	
	//  horizontal accordion ***************************************************
	var _activeHA = false;
	var _widthHA = 739;
	var _widthHAmin = 48;
	var _slides = $('#main ul.slider li');
	var _timer = false;
	
	_slides.each(function(i,_li){
		var _slide = $('div.content',_li);
		
		if (i == 0) 
			_activeHA = _slide;
			
		_slide.css({width:_widthHAmin, 'overflow':'hidden'});
		_activeHA.css({'width':_widthHA});
		
		$(_li).mouseenter(function(){
			if (_activeHA != _slide) {
				_timer = setTimeout(function(){
					_activeHA.animate({width:_widthHAmin},{duration:500, step:function(_dif){
						_slide.css({width:_widthHAmin+(_widthHA-_dif)});
					}});
					_activeHA = _slide;
				}, 100);
			}
			return false;
		}).mouseleave(function(){
			if (_timer) clearTimeout(_timer);
		});
	});
	
	// dropdown ****************************************************************
	var _navEl = $('#nav li');
	var _durationSlide = 300;
	
	_navEl.each(function(i, _el){
		_el = $(_el);
		var _ul = $('> div', _el);
		var _h = _ul.outerHeight();
		_ul.css({'height':0,'overflow':'hidden'});
		
		_el.hover(function(){
			this.hoverEl = true;
			$(this).addClass('hover');
			
			_ul.animate({height:_h},{queue:false,duration:_durationSlide,complete:function(){
				_ul.css('height',_h);
			}});
		}, function(){
			this.hoverEl = false;
			var _this = this;
			if (_ul.length)
				_ul.animate({height:0},{queue:false,duration:_durationSlide, complete:function(){
					if (!_this.hoverEl)
						$(_this).removeClass('hover');
				}});
			else $(_this).removeClass('hover');
		});
	});
	
	// cast box ****************************************************************
	var _castBox = $('div.cast-box-content');
	var _next = $('a.btn-next', _castBox);
	var _prev = $('a.btn-prev', _castBox);
	var _cur = 0;
	_castBox.hide();
	_castBox.eq(_cur).show();
	
	_prev.show().css('visibility','hidden');
	
	_next.click(function(){
		if (_castBox.is(':animated')) return false;
		_cur += 1;
		_prev.css('visibility','visible');
		if (_cur + 1 >= _castBox.length) _next.css('visibility','hidden');
		
		_castBox.filter(':visible').fadeOut(300, function(){
			_castBox.eq(_cur).fadeIn(300);
		});
		return false;
	});
	_prev.click(function(){
		if (_castBox.is(':animated')) return false;
		_cur -= 1;
		_next.css('visibility','visible');
		if (_cur - 1 < 0) _prev.css('visibility','hidden');
		_castBox.filter(':visible').fadeOut(250, function(){
			_castBox.eq(_cur).fadeIn(250);
		});
		return false;
	});

});
