/**
 * our functions, using jQuery
 */
$(function() {
	
	// left-nav
	// -> peak100: fancy scroller
	var _duration = 5;
	$('.nv-content3').each(function(){
		var _hold = $(this);
		var btn_up = _hold.find('a.btn-prev');
		var btn_down = _hold.find('a.btn-next');
		var list_h = _hold.find('div.scroller > ul:eq(0)');
		var _step = list_h.parent().height();
		var _h = list_h.height();
		var _m = 0;
		var _d;
		
		// gapz hack
		list_h.parent().css('overflow', 'hidden')
					   .css('height', '285px');
		btn_up.css('display', 'block');
		btn_down.css('display', 'block');
		
		_hold.mouseover(function(){
			_h = list_h.height();
			_m = -list_h.position().top;
			if(_h < _step) list_h.css('top', 0);
			else if(_h - _m < _step) list_h.css('top', -(_h - _step));
			
		});
		btn_up.mouseout(function(){
			list_h.stop();
		}).mousedown(function(){
			_h = list_h.height();
			_m = -list_h.position().top;
			
			if(_m > 0){
				_d = _m*_duration;
				list_h.animate({top: 0}, _d, 'linear');
			}
		}).mouseup(function(){
			list_h.stop();
		}).click(function(){
			return false;
		});
		
		btn_down.mouseout(function(){
			list_h.stop();
		}).mousedown(function(){
			_h = list_h.height();
			_m = -list_h.position().top;
			if(_h - _m - _step > 0){
				_d = (_h - _m - _step)*_duration;
				list_h.animate({top: -(_h - _step)}, _d, 'linear');
			}
		}).mouseup(function(){
			list_h.stop();
		}).click(function(){
			return false;
		});
		
		list_h.parent().mousewheel(function(event, delta){
			_h = list_h.height();
			_m = -list_h.position().top;
			if(delta > 0){
				if(_m > 0){
					if(_m > 20) list_h.css('top', -_m+20);
					else list_h.css('top', 0);
					return false;
				}
			}
			else{
				if(_h - _m - _step > 0){
					if(_h - _m - _step > 20) list_h.css('top', -_m-20);
					else list_h.css('top', -(_h - _step));
					return false;
				}
			}
		});
	});
	//! -- end of scroller -->
	

//	$('.current-event-with-js').show();
//	$('.current-event-no-js').hide();
	/*
	var slides = $('#slideshow-nav').children().size();
	if(slides <= 0) {
		$('#slideshow-nav').remove();
	}
	var slide_timer = 0;
	$('#slideshow-nav, #slideshow img').mouseover(function() {
		if(slide_timer) {
			clearTimeout(slide_timer);
		}
		$('#slideshow-nav').fadeIn();
		$('#slideshow').cycle('pause');
	});
	$('#slideshow-nav, #slideshow img').mouseout(function() {
		$('#slideshow').cycle('resume');
		slide_timer = setTimeout(function() {
		$('#slideshow-nav').fadeOut('slow');
		}, 900);
	});
	*/
	
	$('.footer1 img').mouseover(function() {
		$(this).css('opacity', 0.6);
	});
	$('.footer1 img').mouseout(function() {
		$(this).css('opacity', 1.0);
	});

});

var types = ['DOMMouseScroll', 'mousewheel'];
jQuery.event.special.mousewheel = {
	setup: function() {
		if ( this.addEventListener ) for ( var i=types.length; i; ) this.addEventListener( types[--i], handler, false );
		else this.onmousewheel = handler;
	},
	teardown: function() {
		if ( this.removeEventListener ) for ( var i=types.length; i; ) this.removeEventListener( types[--i], handler, false );
		else this.onmousewheel = null;
	}
};
jQuery.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});
function handler(event) {
	var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
	event = jQuery.event.fix(event || window.event);
	event.type = "mousewheel";
	if ( event.wheelDelta ) delta = event.wheelDelta/120;
	if ( event.detail     ) delta = -event.detail/3;
	args.unshift(event, delta);
	return jQuery.event.handle.apply(this, args);
}

/*
$.fn.cycle.defaults.timeout = 6000;
$.fn.cycle.defaults.speed   = 900;
*/
