(function($)
    {
        $.fn.vAlign = function(){
            return this.each(function() {
                var ah = $(this).height();
                var ph = $(this).parent().height();
                var mh = (ph - ah) / 2;
                $(this).css("margin-top", mh);
            });
        }
    })(jQuery);


$().ready(function(){

    $('#nav li a').vAlign();
    $('a.blank').attr('target', '_blank');
    
    // accordion slider    
    $("#featured").not('.fadeslider, .newsslider').kricordion({
        slides: '.featured',		// wich element inside the container should serve as slide
        animationSpeed: 900,		// animation duration in milliseconds
        autorotation: true,			// autorotation true or false?
        autorotationSpeed:5,		// duration between autorotation switch in Seconds
        event: 'mouseover',			// event to focus a slide: mouseover or click
        imageShadow:true,			// should the image get a drop shadow to the left
        easing: 'easeOutQuart',		// easing method
        imageShadowStrength:0.5		// how dark should that shadow be, recommended values: between 0.3 and 0.8, allowed between 0 and 1
    });
    $('div.outer').each(function(){
        var w = $('<a />').attr('href',$(this).attr('title'));
        $(this).css('cursor','pointer').wrap(w);
    });

    $('a.fancybox[rel=gallery]').fancybox({
        overlayOpacity: 0.8,
        overlayColor : '#111',
        'transitionIn'		: 'none',
        'transitionOut'		: 'none',
        'titlePosition' 	: 'over'
    });

    //gallery
    var mright = 7, mleft = 0, thumbwidth = 280;
    $('.ad-caption').empty().prepend($('<p>').text($('.mthumb:eq(0)').attr('title')));
    $('.mthumb:gt(0)').hide();
    $('.ad-thumb-list a').hover(function(){
        //console.log(mright+','+i);
        var i = $('.ad-thumb-list a').index($(this));
        if(i == mright){
            //move right
            //r = $('.ad-thumb-list').attr('right') += 500;
            $('.ad-thumb-list').stop().animate({
                right:'+=450px'
            },1500);
            mright += 6;
            mleft += 6;
        }
        if(i == mleft && i > 0){
            //move right
            //r = $('.ad-thumb-list').attr('right') += 500;
            if($('.ad-thumb-list').attr('right') > 450)
                $('.ad-thumb-list').stop().animate({
                    right:'-=450px'
                },1500);
            else $('.ad-thumb-list').stop().animate({
                right:'0'
            },1500);
            mright -= 6;
            mleft -= 6;
        }
    }, function(){});
    $('.ad-thumb-list a').click(function(){
        var i = $('.ad-thumb-list a').index($(this));
        var caption = $('<p>').text($(this).attr('title'));
        $('.ad-caption').empty().prepend(caption);
        $('.mthumb').hide().eq(i).show();
        return false;
    });
    
});


