/*
    $URL: http://nvdweb1/svn/Lists/branches/stable/src/webroot/list/public/london/imageResizer.js $
    $Revision: 53284 $
*/

(function(){
		var imageResizer = {initialImgWidth:0,criticalWindowWidth:0,totalHorizPaddingAndMargins:510};

		//establishes intial size of img and from that critical width of window, below which img resizing is necessary
		imageResizer.init = function(){
				if (!document.getElementById("AdImage")){
					return;
				}
				var initialImg = document.getElementById("AdImage");
				
				imageResizer.initialImgWidth = initialImg.width;
				imageResizer.criticalWindowWidth = imageResizer.totalHorizPaddingAndMargins+imageResizer.initialImgWidth;            
				imageResizer.resize();
		}
		//finds current window width then resizes window if necessary
		imageResizer.resize = function(){
				if (!document.getElementById("AdImage")){
					return;
				}        

				var windowWidth;
				var currentImg = document.getElementById("AdImage");

				if( typeof( window.innerWidth ) == 'number' ) {
						//Non-IE
						windowWidth = window.innerWidth;
				}
				else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
						//IE 6+ in 'standards compliant mode'
						windowWidth = document.documentElement.clientWidth;
				}
				else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
						//IE 4 compatible
						windowWidth = document.body.clientWidth;
				}

				if (windowWidth < imageResizer.criticalWindowWidth) {    
						currentImg.width = windowWidth-imageResizer.totalHorizPaddingAndMargins;
				}
		}
        //Firefox
		if (window.addEventListener){
			    window.addEventListener("load",imageResizer.init,false);
    			window.addEventListener("resize",imageResizer.resize,false);
		}
        //IE
		else if (window.attachEvent){
	    		window.attachEvent("onload",imageResizer.init);
		    	window.attachEvent("onresize",imageResizer.resize);
		}
})();
