var Ymap = YUI( {
	base:'/scripts/yui/',
	timeout :10000
});

Ymap.namespace("dior");
Ymap.use("base", "node", function(Y) {

	function MapController() {

		MapController.superclass.constructor.apply(this, arguments);
	}

	MapController.NAME = "mapcontroller";

	MapController.ATTRS = {
		width : {
			value :'1024'
		},
		height : {
			value :'768'
		},
		xbox : {
			value :'12'
		},
		ybox : {
			value :'12'
		},
		type : {
			value :"0.75"
		},
		typeName : {
			value :"S"
		},
		xboxnum : {
			value :"77"
		},
		yboxnum : {
			value :"45"
		},
		left:{
			value:"0"
		},
		top:{
			value:"75"
		},
		footer:{
			value:"145"
		}
	}

	Y.extend(MapController, Y.Base, {
		config : function() {
			var body = Y.get(document.body);
			this.set("width", body.get("winWidth"));
			this.set("height", body.get("winHeight")-116);
			this.mapping();
		},
		mapping : function() {
			if (this.get("width") >= (this.get("xboxnum")*this.get("xbox")) && (this.get("height")-130 ) >= (this.get("yboxnum")*this.get("ybox"))) {
				this.set("type", "1");
				this.set("typeName", "L");
				this.set("footer", "155");
				this.set("xbox", "16");
				this.set("ybox", "16");
			}
			Y.get(document.body).addClass("size_"+this.get("typeName"));
			this.getSize();
			this.fire("mapping:done");
		},
		getSize:function(){

			var body = Y.get(document.body);
			this.set("width", body.get("winWidth"));
			this.set("height", body.get("winHeight")-146);
			if(Y.get("#dior_mosaique") != null){
				Y.get("#dior_mosaique").setStyle("width", parseInt(this.get("xboxnum"))*parseInt(this.get("xbox"))+"px");
				var region = Y.get("#dior_mosaique").get("region");
			 	this.set("left", region.left);
				this.fire("mapping:changeSize");
			}
			
			var centeredEls = Y.get(document.body).queryAll(".centered");
			
			if(centeredEls){
				
				
				for(i=0; i<centeredEls.size(); i++){
					var tmpItem = centeredEls.item(i);
					
					tmpItem.get("parentNode").removeChild(tmpItem);
					Y.get(document.body).appendChild(tmpItem);
					tmpItem.setStyle("position", "absolute");
					
					
					var width = tmpItem.get("offsetWidth");
					var height = tmpItem.get("offsetHeight");
					Y.log(mapInstance.get("height") + " => "+height)
					Y.log(mapInstance.get("width") + " => "+width)
					var posH = (mapInstance.get("height") - height) / 2
					var posW = (mapInstance.get("width") - width) / 2
					
					tmpItem.setStyle("top", (posH < 115 ? 120 : posH)+"px");
					tmpItem.setStyle("left", (posW < 16 ? 16 : posW)+"px");

					
				}
				
			}
			
		},
		getPosition : function(x, y){
			return [parseInt(x)*parseInt(this.get("xbox"))+parseInt(this.get("left")), parseInt(y)*parseInt(this.get("ybox"))+parseInt(this.get("top"))];
		}

	});

	Ymap.dior = {
		load :MapController
	};
});
var mapInstance;