﻿
$(document).ready(function () {
    setCorrectHeight();
    footer()
    rightColToggle();
    tooltipMe();
    toggleGroupBar();
    removeContent();
    bure3Cols();
    customFancy();
});

$(window).resize(function () {
    setCorrectHeight();
    footer()
    bure3Cols()
});


function bure3Cols() {
    var ww = $(window).width() - 450;
    if ($('#bure3Cols').length != '') {
        $('#bure3Cols').width(ww);
        $('#bureLeft, #bureCenter, #bureRight').width(ww / 3).show();

        $('.brDiv img').each(function () {
            var img = $(this);
            var zone = $(this).closest('.brDiv');
            var zw = $(zone).width();
            var zh = $(zone).height();
            var ratio = $(this).width() / $(this).height();
            var imgw = zh * ratio;
            var fh;
            var fw;
            if (imgw <= zw) {
                fh = zw / ratio;
                fw = zw;
            } else {
                fh = zh;
                fw = imgw;
            }
            $(img).width(fw).height(fh);
            $(img).css('left', -(fw - zw) / 2)
            $(img).css('top', -(fh - zh) / 2)
            $(img).show()
        })

    }
}


function removeContent() {
    if ($.trim($('#zone1 .fixedWidth').html()) == '') {
        $('#canvas #zone1').css('visibility', 'hidden')
        $('#slideshow').removeClass('stext').removeClass('sphoto').css('cursor', 'default');
        $('#slideshow img').unbind('click')
        $('#cycleNav').fadeIn()
    }
}

function toggleGroupBar() {
    $('#logoGroup a, #selection a').click(function () {
        $('#leftGroup').fadeToggle();
    })
}

function tooltipMe() {
    $('.tooltipMe').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        fade: 250,
        top: -50,
        left: -17
    });
}  

function setCorrectHeight() {
    $('#container').height('auto');
    var wh = $(window).height();
    
    var ch = $('#container').height();
    if ($('#canvas.withoutSlideshow').length > 0) {
        var wz = $('#zone1').height() + 36;
        if (wz > wh) {$('#container').height(wz); }
        if (wz < wh) { $('#container').height(wh);  }
        if ((ch > wh) && !((wz > wh))) { $('#container').height(ch);}
    } else {
        if (wh > ch) {$('#container').height(wh);}
    }

}


function footer() {
    var ch = $('#container').height();
    var th = $('#left .top').height();
    var bh = $('#left .bottom').height();

    var toth = ch - (th + bh) - 19; //18
    if (toth >= 0) {
        $('#left .bottom').css('top', toth);
    }
}

function rightColToggle() {
    $('#cycle img').live("click", function () {

        hideRight()

        if ($.trim($('#zone1 .fixedWidth').html()) != '') {
            if ($('#zone1').is(':visible')) {
                $('#slideshow').removeClass('sphoto').addClass('stext')
                $('#zone1').fadeOut(100)
                $('#cycleNav').not('.single').fadeIn('fast')

                $('#body1338 #badge, #body1454 #badge, #body1893 #badge, #body1833 #badge').fadeOut('fast')


            } else {
                $('#slideshow').removeClass('stext').addClass('sphoto')
                $('#zone1').fadeIn(100)
                $('#cycleNav').not('.single').fadeOut('fast')
                $('#cycle').cycle('resume');

                $('#body1338 #badge, #body1454 #badge, #body1893 #badge, #body1833 #badge').fadeIn('fast')

            }
        
        }
        

    })

    $('#rightBar').click(function () {
        $(this).animate({ width: 0 }, 'fast', function () {
            $('#right').animate({
                width: 260
            }, 'fast', function () {
                $('#right .spacer, #closeRight').fadeIn(100);
            })

        })
     })

     $('.cycleBtn, #closeRight').click(function () {hideRight()});

}

function hideRight() {
    if ($('#right .spacer').is(':visible')) {
        $('#right .spacer, #closeRight').fadeOut(100, function () {
            $('#right').animate({ width: 0 }, 'fast', function () {
                $('#rightBar').animate({ width: 60 }, 'fast')
            })
        })
    }
}

function rightColToggleHome() {
    $('#slideshow img, #rightBar:visible').click(function () {
        if ($('#right .spacer').is(':visible')) {
            $('#zone1').fadeOut(100)
            $('#right .spacer, #closeRight').fadeOut(100, function () {
                $('#right').animate({ width: 'toggle' }, 'fast', function () {

                    $('#cycleNav').not('.single').fadeIn('fast')

                    $('#rightBar').animate({ width: 'toggle' }, 'fast')
                })

                $('#body1338 #badge, #body1454 #badge, #body1893 #badge, #body1833 #badge').fadeOut('fast')

            })
        } else {
            $('#rightBar').animate({ width: 0 }, 'fast', function () {
                $('#right').animate({
                    width: 'toggle'
                }, 'fast', function () {
                    $('#zone1').fadeIn(100)
                    $('#right .spacer, #closeRight').fadeIn(100);

                    $('#cycleNav').not('.single').fadeOut('fast');
                   
                    $('#cycle').cycle('resume');

                })
                $('#body1338 #badge, #body1454 #badge, #body1893 #badge, #body1833 #badge').fadeIn('fast')


            })


        }
    })
}


function customFancy() {

    $("#fancyBrochure").fancybox({
        width: 960,
        height: 600,
        margin: 75,
        prevEffect: 'fade',
        nextEffect: 'fade',
        helpers: {
            title: {
                type: 'float'
            }
        }, padding: 0
    });



}


