$(document).ready(function(){

	$("#tabs").tabs();

	$('#slider').nivoSlider({
		effect:'fade',
		animSpeed:500,
        pauseTime:4000,
		directionNav:false,
		controlNav:true,
		keyboardNav:false,
		pauseOnHover:false
	});

	$("a[target=_top]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic'
	});

	// GALERIA
	$("a[rel=galeria]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? '&nbsp;-&nbsp; ' + title : '') + '</span>';
		}
	});

	// VIDEO
	$("a[rel=video]").click(function() {
		$.fancybox({
			'padding'             : 0,
			'autoScale'   		  : false,
			'transitionIn'	      : 'elastic',
			'transitionOut'		  : 'elastic',
			'title'               : this.title,
			'width'               : 680,
			'height'              : 495,
			'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'                : 'swf',    // <--add a comma here
			'swf'                 : {'allowfullscreen':'true'} // <-- flashvars here
		});
		return false;
	});

	/*************** MENU ****************/
	
	// retarder
    $.fn.retarder = function(delay, method){
        var node = this;
        if (node.length){
            if (node[0]._timer_) clearTimeout(node[0]._timer_);
            node[0]._timer_ = setTimeout(function(){ method(node); }, delay);
        }
        return this;
    };

    // base rules
    $('ul ul', '#menu').css({display: 'none', left: -2});
    $('li', '#menu').hover(
        function(){
            var ul = $('ul:first', this);
            $('span', ul).css('color', 'rgb(169,169,169)');
            if (ul.length){
                if (!ul[0].wid){
                    ul[0].wid = ul.width();
                    ul[0].hei = ul.height();
                }
                ul.css({width: 0, height: 0, overflow: 'hidden', display: 'block'}).retarder(100, function(i){
                    i.animate({width: ul[0].wid, height: ul[0].hei}, {duration: 300, complete : function(){ ul.css('overflow', 'visible'); }});
                });
            }
        },
        function(){
            var ul  = $('ul:first', this);
            if (ul.length){
                var css = {display: 'none', width: ul[0].wid, height: ul[0].hei};
                ul.stop().css('overflow', 'hidden').retarder(50, function(i){
                    i.animate({width: 0, height: 0}, {duration: 100, complete : function(){  $(this).css(css); }});
                });
            }
        }
    );
	/*
    // lava lamp
    $('#menu ul.menu').lavaLamp({
        fx: 'easeOutBack',
        speed: 800
    });
    // color animation
    if (!($.browser.msie && $.browser.version.substr(0, 1) == '6')){
        $('ul ul a span', '#menu').css('color', 'rgb(169,169,169)').hover(
            function(){ $(this).animate({color: 'rgb(255,255,255)'}, 500); },
            function(){ $(this).animate({color: 'rgb(169,169,169)'}, 200); }
        );
    }
	*/
	/************** MENU END ***************/

});
