﻿jQuery(window).load(function () {
    (function ($) {
        $.fn.fullBg = function () {
            var bgImg = $(this);

            bgImg.addClass('fullBg');

            function resizeImg() {
                var imgwidth = bgImg.width();
                var imgheight = bgImg.height();

                var winwidth = $(window).width();
                var winheight = $(window).height();

                var widthratio = winwidth / imgwidth;
                var heightratio = winheight / imgheight;

                var widthdiff = heightratio * imgwidth;
                var heightdiff = widthratio * imgheight;

                if (heightdiff > winheight) {
                    bgImg.css({
                        width: winwidth + 'px',
                        height: heightdiff + 'px'
                    });
                } else {
                    bgImg.css({
                        width: widthdiff + 'px',
                        height: winheight + 'px'
                    });
                }
            }
            resizeImg();
            $(window).resize(function () {
                resizeImg();
            });
        };
    })(jQuery)
	
    jQuery(function ($) {
		$("#Background").fadeIn(2000);
		$("#HitArea").css({ width: ($(window).width() / 2) * 1.48 });
		
		$("#BrokersHover").fullBg();
		$("#BrokersHover").css({ left: ($(window).width() / 2) - ($("#BrokersHover").width() / 2) });
		$("#BrokersHover").css({ top: ($(window).height() / 2) - ($("#BrokersHover").height() / 2) });
		
		$("#EmployersHover").fullBg();
		$("#EmployersHover").css({ left: ($(window).width() / 2) - ($("#EmployersHover").width() / 2) });
		$("#EmployersHover").css({ top: ($(window).height() / 2) - ($("#EmployersHover").height() / 2) });
		
		$("#ProductsHover").fullBg();
		$("#ProductsHover").css({ left: ($(window).width() / 2) - ($("#ProductsHover").width() / 2) });
		$("#ProductsHover").css({ top: ($(window).height() / 2) - ($("#ProductsHover").height() / 2) });
		
		$("#Background").fullBg();		
        $("#Background").css({ left: ($(window).width() / 2) - ($("#Background").width() / 2) });
		$("#Background").css({ top: ($(window).height() / 2) - ($("#Background").height() / 2) });
		
		$("#HitArea").css({ left: ($(window).width() / 2) - ($("#HitArea").width() / 2) });
		$("#HitArea").css({ top: ($(window).height() / 2) - ($("#HitArea").height() / 1.8) });
		
		$("#BrokersHitArea").hover(
			function() {
				$("#BrokersHover").fadeIn();
			},
			function() {
				$("#BrokersHover").fadeOut();
			}
		);
		
		$("#BrokersHitArea").click(function () {
			window.location = "http://brokers.chimienti.com";
		});
		
		$("#EmployersHitArea").hover(
			function() {
				$("#EmployersHover").fadeIn();
			},
			function() {
				$("#EmployersHover").fadeOut();
			}
		);
		
		$("#EmployersHitArea").click(function () {
			window.location = "http://employers.chimienti.com";
		});
		
		$("#ProductsHitArea").hover(
			function() {
				$("#ProductsHover").fadeIn();
			},
			function() {
				$("#ProductsHover").fadeOut();
			}
		);
		
		$("#ProductsHitArea").click(function () {
			window.location = "http://insurance.chimienti.com";
		});
        
		$(window).resize(function () {
			$("#HitArea").css({ width: ($(window).width() / 2) * 1.48 });
			
			$("#BrokersHover").css({ left: ($(window).width() / 2) - ($("#BrokersHover").width() / 2) });
			$("#BrokersHover").css({ top: ($(window).height() / 2) - ($("#BrokersHover").height() / 2) });
		
			$("#EmployersHover").css({ left: ($(window).width() / 2) - ($("#EmployersHover").width() / 2) });
			$("#EmployersHover").css({ top: ($(window).height() / 2) - ($("#EmployersHover").height() / 2) });
		
			$("#ProductsHover").css({ left: ($(window).width() / 2) - ($("#ProductsHover").width() / 2) });
			$("#ProductsHover").css({ top: ($(window).height() / 2) - ($("#ProductsHover").height() / 2) });
			
			$("#Background").css({ left: ($(window).width() / 2) - ($("#Background").width() / 2) });
			$("#Background").css({ top: ($(window).height() / 2) - ($("#Background").height() / 2) });	
			
			$("#HitArea").css({ left: ($(window).width() / 2) - ($("#HitArea").width() / 2) });
			$("#HitArea").css({ top: ($(window).height() / 2) - ($("#HitArea").height() / 1.8) });
			
        });
		
    });
});
