//current slide index counter
function onBefore(curr, next, opts) {
    var index = $(this).parent().children().index(this);
    $('span.current_num').text(index + 1);
}

//equal heights function - matches heights of a group of elements to the largest 
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

function mycarousel_initCallback(carousel) {
    $('.slider-next').bind('click', function() {
        carousel.next();
        return false;
    });

    $('.slider-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
}

$(document).ready(function() {

	/*************************
    fancybox for photo gallery
    **************************/
    // general photo lightbox
    $('a.fancybox').fancybox({ 
        'zoomSpeedIn': 0,
        'zoomSpeedOut': 0,
        'frameHeight': 390,
        'frameWidth': 455,
        'overlayShow': true,
        'navigation': true,
        'overlayOpacity' : 0.75
    });

    // ie6 detection - adjust height/width for ie6
    if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
        $('a.videobox').fancybox({ 
            'imageScale': false,
            'zoomSpeedIn': 0,
            'zoomSpeedOut': 0,
            'frameHeight': 395,
            'frameWidth': 425,
            'overlayShow': true,
            'navigation': false,
            'overlayOpacity' : 0.75,
            'callbackOnClose' : function(){ $('#fancy_ajax').remove(); }
        }); 
    } else {
        $('a.videobox').fancybox({ 
            'imageScale': false,
            'zoomSpeedIn': 0,
            'zoomSpeedOut': 0,
            'frameHeight': 355,
            'frameWidth': 425,
            'overlayShow': true,
            'navigation': false,
            'overlayOpacity' : 0.75,
            'callbackOnClose' : function(){ $('#fancy_ajax').remove(); }
        });
    }

    

    /**********************
    sidenav content rotater
    ***********************/
    $('#content-rotator-inner').cycle({ 
        fx: 'scrollHorz', 
        speed: 1500,
        easing: 'easeOutQuad',
        timeout: 7000,
        delay: -2000, 
        next: '#next-slide', 
        prev: '#prev-slide',
        pause: 1,
        before: onBefore
    });
    
    /***********
    photo slider
    ************/
    $('.photo-slider ul').jcarousel({
        'animation': 1000,
        initCallback: mycarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
    
   
    
    /************************************************
    set equalHeights on content rotater, and it children
    *************************************************/  
    $('#content-rotator-inner .rotator_item:eq(0)').show();
    equalHeight($('#content-rotator-inner, #content-rotator-inner .rotator_item'));
    
    

});

