var logoRatio = 6.813;
var slideshowOriginalWidth = 1680;
var slideshowOriginalHeight = 232;


//  Size functions from http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function dentalsOnResize()
{
    var slideshowDiv            = document.getElementById('slideshow');
    var originalContainerHeight = 298;
    var maxContainerShare       = 0.3725;
//    var originalTemplateHeight  = 800;
    var clientHeight            = f_clientHeight();
    var clientWidth             = f_clientWidth();
    var containerHeight         = clientHeight * maxContainerShare;

    if (containerHeight > originalContainerHeight)
        containerHeight = originalContainerHeight;

    $('#slideshow').height(containerHeight - 2);
    $('#logo').css({bottom: clientHeight * 0.1 + containerHeight + 80});

    var rainbowBottom = clientHeight * 0.1075 + containerHeight;
    var headerHeight = clientHeight - rainbowBottom;
    var logoWidth = clientWidth - headerHeight * 1; //  Consider the rainbow square.
    var logoHeight = logoWidth / logoRatio;
    var contactInfoFontSize = logoWidth * 0.031;

    $('#rainbow-img')
            .css({bottom: rainbowBottom - 1})
            .height(headerHeight * 0.76);

//    $('#logo-img')
//            .width(logoWidth)
//            .height(logoHeight)
//            .css({top: (headerHeight - logoHeight) / 2});

//    $('#contact-info')
//            .css({top: (headerHeight + logoHeight) / 2 + 6})
//            .find('div').css({
//                    'font-size': contactInfoFontSize + 'px'});

    $('#menu')
            .css({bottom: clientHeight * 0.1075 + containerHeight * 0.181208});

    var slideshowScale = containerHeight / originalContainerHeight;
    var slideshowWidth = Math.floor(slideshowOriginalWidth * slideshowScale);
    var slideshowHeight = Math.floor(slideshowOriginalHeight * slideshowScale);

    $('#slideshow-images')
            .width(slideshowWidth)
            .height(slideshowHeight)
            .css({top: Math.floor((containerHeight - slideshowHeight - 2) / 2)})  //  -2 for border
            .show();
}

function dentalsOnLoad()
{
    dentalsOnResize();

    $('#rainbow-img,#logo-img,#slideshow,#menu')
        .show();
}


window.onresize = dentalsOnResize;
window.onload = dentalsOnLoad;
