/* Author: KOJI sibata
	関数型コンストラクタの参照
	「JavaScript: The Good Parts ―「良いパーツ」によるベストプラクティス」
*/

(function(window) {
	$( function() {
		// 初期化処理...
		// HTMLロード後に実行
	});	
	function doSomething() {
    	//alert("I'm done resizing for the moment");
	};

	var changeSize = function(){
		////ローカル変数
		var that = {};
		//849 807
		var defW = 849;
		var defH = 807;

		var _test = "init local";
		var _testB = "_testB";
		
		that.__defineGetter__("testB", 	function() { return _testB; 		});
		that.__defineGetter__("test", 	function() { 
												console.log("this.testB ++ "+this.testB);
												console.log("get _test ++ "+_test);
												return _test; 
											});
		
		that.__defineSetter__("test", 	function(value) { 
												_test = value;
												console.log("set _test ++ "+_test);
											})
		////ローカルメソッド
 		var makeRatio = function(w,h){
	 		if( w < defW && h < defH ){
				return 1;
 			}else{
 				if(h/defH < w/defW){
 					return w/defW;
 				}else{
 					return h/defH;
				}
 			}
 		}
		////パブリックメソッド
 		that.changeSize = function(){
    		var w = $(window).width();
	    	var h = $(window).height();
	    			
 			$("#navcontainer").css("left", w-22);
 			$("#globalnavi").css("top", h-211);
 		
 			var ratio = makeRatio(w,h);
			var newW  = defW*ratio;
			var newH = defH*ratio;
				
			$("#bkImage").css("width", newW);
			$("#bkImage").css("height", newH);
			$("#bkImage").css("left", w-newW);
			$("#bkImage").css("top", h-newH);
		}
 		that.init = function(){
			that.changeSize();
			return that;
		}
 		that.testGetterSetter = function(){
 			console.log("testGetterSetter _test ++ "+_test);
 			console.log("testGetterSetter this.test ++ "+ this.test);
 			this.test = "a";
 			console.log("testGetterSetter this.test = a ++ "+ this.test);
 		}
		return that;
	};
	
	var mySize = changeSize().init();
	console.log("mySize.test ++ "+mySize.test);
	mySize.test = "b";
	mySize.testGetterSetter();
	console.log("mySize.test2 ++ "+mySize.test);
	
	
	$(window).bind('resize', function() { 
		mySize.changeSize();
 	});
	$("#main").css("visibility", "visible");
	$("#bkImage").css("visibility", "visible");
	
})(window);
















