/* 	Function: 	Enlarge an image when it is hovered over
	Author: 	Justin Farmer 
*/

$(document).ready(function () {

    var oWidth = $('img.resize').width();
    var oHeight = $('img.resize').height();
    var mpx = (oWidth / oHeight * 1.08);

    var large_size = {
        width: (oWidth * mpx),
        height: (oHeight * mpx)
    };

    get_pie_details = function(img) {
        var details = {
            offset: {
                top: 0,
                left: 0
            },
            show_el: '#home-switch'
        };

        if (img.hasClass("tl")) {
            details.offset = {
                top: oWidth - large_size.width,
                left: oHeight - large_size.height
            };
            details.show_el = '#solutions-switch';
        } else if (img.hasClass("tr")) {
            details.offset = {
                top: oWidth - large_size.width,
                left: 0
            };
            details.show_el = '#environment-switch';
        } else if (img.hasClass("bl")) {
            details.offset = {
                top: 0,
                left: oHeight - large_size.height
            };
            details.show_el = '#business-switch';
        } else if (img.hasClass("br")) {
            details.show_el = '#lifescience-switch';
        }

        return details;
    }
        
    $('img.resize').hover(function () {
		    var pie = get_pie_details($(this));
            
		    $(this).stop().animate({
				    width: large_size.width + 'px',
				    height: large_size.height + 'px',
				    marginLeft: pie.offset.left + 'px',
                    marginTop: pie.offset.top + 'px'
			}, 500);

            $(pie.show_el).stop().fadeIn();
            $(".pie-hover-content").not(pie.show_el).fadeOut();
		},
		function () {
            var pie = get_pie_details($(this));

		    $(this).stop().animate({
				    width: oWidth + 'px',
				    height: oHeight + 'px',
                    marginLeft: '0px',
                    marginTop: '0px'
			}, 500);
		});
});