//define

var arpe;

if (typeof console != "object") {
	var console = {
		'log':function(){}
	};
}

//enhance mootols element
Element.implement({

	"setXOffset":function(v)
	{
		this.setProperty("xOffset", v);
	},
	
	"setYOffset":function(v)
	{
		this.setProperty("yOffset", v);
	},
	
	"getXOffset":function()
	{
		return this.getProperty("xOffset");
	},
	
	"getYOffset":function()
	{
		return this.getProperty("yOffset");
	},
	
	"computeStyle":function() //deprecated, renamed to compute
	{
		arpe._executeComputed(this);
	},
	
	"compute":function()
	{
		arpe._executeComputed(this);
	}

});

var isIE = (navigator.appName=='Microsoft Internet Explorer');


var Arpe = new Class({

	Implements: Options,
	options: {
	},
	
	initialize: function()
	{
		this._init();
		this._state = "";
		$(document.body).setStyle("visibility", "visible");
	},
	
	getChunk: function(name, params)
	{
		var chunk = this.chunks[name];
		
		if (chunk != null)
		{
			params = params || chunk.getBindings();
			
			return this._processContent(chunk.getContent(), params);
		}
		
		return "";
	},
	
	batchGetChunk: function(name, collection)
	{	
		var content = "";
		
		for (var i = 0; i < collection.length; i++)
			content += this.getChunk(name, collection[i]);
			
		return content;
	},
	
	setState: function(value)
	{
		this._state = value;
		this._executeComputed();
	},
	
	getState: function()
	{
		return this._state;
	},
	
	isOnState: function(value) //renvoie vrai si on est dans l'état ou dans un état supérieur
	{
		return (this._state.search(new RegExp("^"+value+"$")) != -1
			|| this._state.search(new RegExp("^"+value+":")) != -1);
	},
	
	run: function(regions)
	{
		this._display(regions);
	},
	
	/* private */
	_init: function()
	{
	
		this.chunks = {};
		this.elements = [];
		
		/* -- elmts loading -- */
		elmts = $$("table")
			.concat($$("div"))
			.concat($$("span"))
			.concat($$("p"))
			.concat($$("input"))
			.concat($$("ul"));
		
		var attributes;
		
		for (var i = 0; i < elmts.length; i++)
		{
		
			if (Arpe.getElementAttributes(elmts[i], "chunk").length > 0)
			{
				this.chunks[elmts[i].getAttribute("arpe:chunk")] = new Arpe_Chunk(
					{
						element: $(elmts[i]),
						content: $(elmts[i]).get("html"),
						binding: elmts[i].getAttribute("arpe:bindto"),
						states: elmts[i].getAttribute("arpe:states")
					});
				
				//on masque l'élément jusqu'à l'affichage
				$(elmts[i]).set("html", "");
			
			}
			else if (Arpe.getElementAttributes(elmts[i], "bindto").length > 0)
			{
				this.elements.push(new Arpe_DynamicElement(
					{
						element: $(elmts[i]),
						content: $(elmts[i]).get("html"),
						binding: elmts[i].getAttribute("arpe:bindto"),
						states: elmts[i].getAttribute("arpe:states")
					})
					);
					
				//on masque l'élément jusqu'à l'affichage
				$(elmts[i]).set("html", "");
			}
			else if ((attributes = Arpe.getElementAttributes(elmts[i], "twitter")).length > 0)
			{
				var args = attributes[0].name.replace(/arpe:twitter\?/g, "").split("?");
				
				this.chunks["_arpe_internal_twitter"] = new Arpe_Chunk(
					{
						element: $(elmts[i]),
						content: $(elmts[i]).get("html"),
						binding: elmts[i].getAttribute("arpe:bindto"),
						states: elmts[i].getAttribute("arpe:states")
					});
						
				//on masque l'élément jusqu'à l'affichage
				$(elmts[i]).set("html", "");
				
				new Arpe_Twitter({user:args[0],count:args[1],container:$(elmts[i])});
				
			}
			
		}
		
	},
	
	_executeComputed: function(elmt)
	{
	
		elmt = elmt || null;
		
		var elmts;
		
		if (elmt == null)
		{
			/* -- elmts loading -- */
			elmts = $$("table")
				.concat($$("div"))
				.concat($$("span"))
				.concat($$("p"))
				.concat($$("input"))
				.concat($$("ul"))
				.concat($$("a"))
				.concat($$("img"));
		}
		else
			elmts = [elmt];
		
		var computed;
		
		var attributes;
		
		for (var i = 0; i < elmts.length; i++)
		{
			if ((attributes = Arpe.getElementAttributes(elmts[i], "hide")).length > 0)
			{
				computed = new Arpe_Evaluable(
					{
						element: $(elmts[i]),
						type: "visibility",
						condition: attributes[0].value
					});
					
				computed._display();
				
			}
			
			if ((attributes = Arpe.getElementAttributes(elmts[i], "nodisplay")).length > 0)
			{
				computed = new Arpe_Evaluable(
					{
						element: $(elmts[i]),
						type: "display",
						condition: attributes[0].value
					});
					
				computed._display();
				
			}
			
			if ((attributes = Arpe.getElementAttributes(elmts[i], "class")).length > 0)
			{
			
				for (var j = 0; j < attributes.length; j++)
				{
					computed = new Arpe_Evaluable(
						{
							element: $(elmts[i]),
							type: "class",
							subtype: attributes[j].name.replace(/arpe:class\?/g, ""),
							condition: attributes[j].value
						});
						
					computed._display();
				}
				
			}
			
			if ((attributes = Arpe.getElementAttributes(elmts[i], "position")).length > 0)
			{
			
				for (var j = 0; j < attributes.length; j++)
				{

					computed = new Arpe_ComputedStyle(
						{
							element: $(elmts[i]),
							type: "position",
							subtype: attributes[j].name.replace(/arpe:position\?/g, ""),
							condition: attributes[j].value
						});
					
					computed._display();
				}
			}
			
			if ((attributes = Arpe.getElementAttributes(elmts[i], "max-size")).length > 0)
			{
			
				computed = new Arpe_ComputedStyle(
					{
						element: $(elmts[i]),
						type: "max-size",
						subtype: attributes[0].name.replace(/arpe:max\-size\?/g, ""),
						condition: attributes[0].value
					});
					
				computed._display();
			}
		}
	},
	
	_processContent: function(content, params, options, namespace)
	{
		options = options || {};
		
		namespace = (namespace != null && namespace != "") ? namespace+":":"";

		if (content != null)
		{
			if (params instanceof Element || params instanceof Document)
				params = Arpe.processXML(params);
			
			if (params instanceof Array)
			{
				var newContent = "";
				
				for (var i = 0; i < params.length; i++)
				{
					newContent += this._processContent(content, params[i], {_index_: i, _length_: params.length}, namespace);
				}
				
				content = newContent;
			}
			else
			{
			
				if (typeof params == "string" || typeof params == "int")
				{
				
					
					if (content.search(new RegExp(namespace+"value")) != -1)
						content = Arpe.replace(content, namespace+"value", params);
				
				}
				else
				{
					for (var key in params)
					{
						if (content.search(new RegExp(namespace+key)) != -1)
							content = Arpe.replace(content, namespace+key, params[key]);
					}
				}
				
				for (var key in options)
				{
					if (content.search(new RegExp(key)) != -1)
						content = Arpe.replace(content, key, options[key]);
				}
				
				content = Arpe.clean(content);
				content = Arpe.execute(content, params, options);
			}
			
			return content;
		}
		
		return "";
	},
	
	_display: function(regions)
	{
	
		regions = regions || [];
		
		var displayList = [].concat(this.elements);
	
		for (var i = 0; i < displayList.length; i++)
		{
			if (displayList[i] instanceof Arpe_DynamicElement)
			{
				if (displayList[i] != null 
					&& (regions.length == 0 || displayList[i].hasBinding(regions))
					&& (displayList[i].states == null 
						|| displayList[i].states.search(new RegExp(this.state+"[,$]", "g")) != -1)
					)
				{
					var content = displayList[i].getContent();
				
					for (var j = 0; j < displayList[i].getBindings().length; j++)
					{
						var binding = displayList[i].getBindings().length > 1 ? displayList[i].getBindings()[j].split(":")[1]:displayList[i].getBindings()[j];
						
						var namespace = null;
						var data = displayList[i].getBindings()[j];
												
						if (displayList[i].getBindings()[j].split(":").length > 1)
						{
							namespace = displayList[i].getBindings()[j].split(":")[0];
							data = displayList[i].getBindings()[j].split(":")[1];
						}
						
						try
						{
							content = this._processContent(content, eval("(function () { return "+data+"})()"), {}, namespace);
						}
						catch (e) { console.log(e) }
					}
					
					displayList[i]._display(content);
				}
			}
							
		}
		
		this._executeComputed();
		
	}

});

Arpe.replace = function(str, field, value)
{
	var ret;
	var reg = new RegExp("(@"+field+"@)", "g");
	ret = str.replace(reg, Arpe.htmlEncode(value));
	reg = new RegExp("(@html="+field+"@)", "g");
	ret = ret.replace(reg, value);
	reg = new RegExp("(@url="+field+"@)", "g");
	ret = ret.replace(reg, encodeURIComponent(value));
	if (typeof value == "string")
	{
		reg = new RegExp("(@string="+field+"@)", "g");
		ret = ret.replace(reg, (value != null ? ("'"+value.replace(/'/g, "\'")+"'"):value));
	}
	return ret;
}

Arpe.execute = function(str, data, repeater)
{
	//hack for firefox
	str = str.replace(/@%7B/g, "@{");
	str = str.replace(/%7D@/g, "}@");
	str = str.replace(/%28/g, "(");
	str = str.replace(/%29/g, ")");
	str = str.replace(/%20/g, " ");
	str = str.replace(/%27/g, "'");

	var reg = new RegExp("(@\\{([^\\}@]+)\\}@)", "g");
	var toEval = str.match(reg);
	
	for (var i = 0; toEval != null && i < toEval.length; i++)
	{
		toEval[i] = toEval[i].replace("@{", "");
		toEval[i] = toEval[i].replace("}@", "");
		
		try
		{
			var out = eval("(function (_data_, _repeater_) { return "+toEval[i]
				.replace(/&gt;/g, ">")
				.replace(/&lt;/g, "<")+";})(data, repeater)");
			str = str.replace("arpe:eval=\"@{"+toEval[i]+"}@\"", out);
			str = str.replace("@{"+toEval[i]+"}@", out);
		}
		catch (e) {console.log(e); return str;}
	}

	return str;
};

Arpe.detectDevice = function()
{

	if (navigator.userAgent.search(/iPad/g) != -1)
		return "iPad";
	
	if (navigator.userAgent.search(/iPhone/g) != -1)
		return "iPhone";
		
	if (navigator.userAgent.search(/iPod/g) != -1)
		return "iPod";
		
	if (navigator.userAgent.search(/Matsiya crawler/g) != -1)
		return "Matsiya crawler";

	return "";
};

Arpe.clean = function(str)
{
	//remove unused
	str = str.replace(new RegExp("(@[\\w\\d\\.]+@)", "g"), "");
	return str.replace(new RegExp("\\w+=\\s", "g"), ""); //hack for ie , remove value= 
};

Arpe.getElementAttributes = function(elmt, attr)
{
	var attributes = [];

	for (var i = 0; i < elmt.attributes.length; i++)
	{
		if (elmt.attributes[i].name == "arpe:"+attr
			|| elmt.attributes[i].name.search(new RegExp("(arpe:"+attr+"\\?[\\w\\-\\?\\d]+)")) != -1)
				attributes.push(elmt.attributes[i]);
	}
	
	return attributes;
};

Arpe.htmlEncode = function(str)
{
	str = str.toString();
	str = str.replace(/>/g, "&gt;");
	str = str.replace(/</g, "&lt;");
	str = str.replace(/'/g, "&#39;");
	str = str.replace(/"/g, "&quot;");
	str = str.replace(/\n/g, "<br/>");
	str = str.replace(/\r/g, "<br/>");
	str = str.replace(/\s/g, "&#32;");

	return str;
};

Arpe.htmlDecode = function(str)
{
	str = str.toString();
	str = str.replace(/&gt;/g, ">");
	str = str.replace(/&lt;/g, "<");
	str = str.replace(/&#39;/g, "'");
	str = str.replace(/&quot;/g, "\"");
	str = str.replace(/&#32;/g, " ");

	return str;
};

Arpe.processXML = function(doc)
{

	if (doc == null)
		return null;

	var result = Arpe.instanceofNodeList(doc) ? []:{};
	var nodes = Arpe.instanceofNodeList(doc) ? doc:doc.childNodes;

	for (var i = 0; nodes != null && i < nodes.length; i++)
	{
		if (Arpe.instanceofNodeList(doc))
		{
			result.push(Arpe.processXML(nodes[i]));
		}
		else if (nodes[i].hasChildNodes && nodes[i].childNodes.length > 1)
		{
			if (result[nodes[i].tagName] != null && !(result[nodes[i].tagName] instanceof Array))
			{
				result[nodes[i].tagName] = [result[nodes[i].tagName]];
				result[nodes[i].tagName].push(Arpe.processXML(nodes[i]));
			}
			else if (result[nodes[i].tagName] instanceof Array)
				result[nodes[i].tagName].push(Arpe.processXML(nodes[i]));
			else
				result[nodes[i].tagName] = Arpe.processXML(nodes[i]);
		}
		else
			result[nodes[i].tagName] = Arpe.getNodeText(nodes[i]).toString();
	}
		
	return result;

};

Arpe.getNodeText = function(node)
{
	if (isIE)
		return node.text;
	else
		return node.textContent;
};

Arpe.instanceofNodeList = function(o)
{
	if (navigator.appName=='Microsoft Internet Explorer')
		return ((typeof o.nextNode == "object" || typeof o.nextNode == "function")
			&& typeof o.length == "number");
	else if (Arpe.detectDevice() == "Matsiya crawler")
		return (typeof o.length == "number" && typeof o.namedItem == "function")
	else
		return (o instanceof NodeList || o instanceof HTMLCollection);
};

Arpe.getURLParameter = function(name)
{

  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&#;]"+name+"=([^&#;]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  
  if( results == null )
    return "";
  else
    return results[1];

};

Arpe.setURLParameter = function(name, value)
{
	var sname = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "([\\?#;])"+sname+"=([^&#;]*)";
	var regex = new RegExp( regexS );
	
	
	
	if (regex.exec( window.location.href ) != null)
		window.location.href = window.location.href.replace(regex, "$1"+name+"="+value);
	else if (window.location.href.search(/#/g) != -1)
	{
		window.location.href = window.location.href+";"+name+"="+value;
	}
	else
	{
		regex = new RegExp("[;]"+sname+"=([^&#;]*)");
		window.location.href = window.location.href+"#"+name+"="+value;
	}

};

var Arpe_Pagination = new Class({

	Implements: Options,
	options: {
	
		first_id: "",
		prev_id: "",
		numbers_id: "",
		next_id: "",
		last_id: "",
		page: 0,
		pageSize: 20,
		maxResults: 1000,
		maxPage: Math.ceil(1000/20),
		numbersCount: 5,
		callback: null
	},

	initialize: function(instance, options)
	{
		this.instance = instance;
		this.setOptions(options);
		this._init();
		this._display();
	},
	
	_init: function()
	{
		if ($(this.options.first_id) != null)
			$(this.options.first_id).addEvent('click', this.first.bindWithEvent(this));
		
		if ($(this.options.prev_id) != null)	
			$(this.options.prev_id).addEvent('click', this.previous.bindWithEvent(this));
		
		if ($(this.options.next_id) != null)
			$(this.options.next_id).addEvent('click', this.next.bindWithEvent(this));
		
		if ($(this.options.last_id) != null)
			$(this.options.last_id).addEvent('click', this.last.bindWithEvent(this));
	
	},
	
	_display: function()
	{
		if ($(this.options.first_id) != null)
			$(this.options.first_id).setStyle("visibility", (this.options.page <= 0) ? "hidden":"visible");
			
		if ($(this.options.prev_id) != null)
			$(this.options.prev_id).setStyle("visibility", (this.options.page <= 0) ? "hidden":"visible");
			
		if ($(this.options.next_id) != null)
			$(this.options.next_id).setStyle("visibility", (this.options.page >= this.options.maxPage-1) ? "hidden":"visible");
			
		if ($(this.options.last_id) != null)
			$(this.options.last_id).setStyle("visibility", (this.options.page >= this.options.maxPage-1) ? "hidden":"visible");
		
		//génération des numéros de page
		var firstIndex = this.options.page-this.options.numbersCount+2;
		firstIndex = (firstIndex < 0 ? 0:firstIndex)+1;
		
		//set numbers content
		var content = "";
		for (var i = 0; i < this.options.numbersCount; i++)
		{
				
			if (this.options.page == i+firstIndex-1)
				content += "<li class=\"selected\"><a href=\"#\">"+(i+firstIndex)+"</a></li>";
			else
				content += "<li><a href=\"javascript:"+this.instance+".goTo("+(i+firstIndex-1)+")\">"+(i+firstIndex)+"</a></li>";
				
			if (i+firstIndex >= this.options.maxPage)
				break;
				
		}
		
		$(this.options.numbers_id).set("html", content);
		
	},
	
	setMaxResults: function (maxResults)
	{
		this.options.maxPage = Math.ceil((this.options.maxResults = maxResults)/this.options.pageSize);
		this._display();
	},
	
	setPageSize: function (pageSize)
	{
		if (this.options.pageSize != pageSize)
			this.options.page = 0;
			
		this.options.pageSize = pageSize;
		this._display();
	},
	
	setPage: function (page)
	{
		this.options.page = page;
		this._display();
	},
	
	getLimit: function()
	{
		return "limit "+this.options.page*this.options.pageSize+", "+this.options.pageSize;
	},
	
	getPage: function()
	{
		return this.options.page;
	},
	
	getPageSize: function()
	{
		return this.options.pageSize;
	},
	
	first: function(event)
	{
		this.goTo(0);
	},
	
	previous: function(event)
	{
		this.goTo(this.options.page-1);
	},
	
	next: function(event)
	{
		this.goTo(this.options.page+1);
	},
	
	last: function(event)
	{
		this.goTo(this.options.maxPage-1);
	},
	
	goTo: function(page)
	{
		this.options.page = page;
		this._display();
		this.options.callback();
	}

});


var Arpe_DynamicElement = new Class({
	
	Implements: Options,
	options: {
		element:null,
		binding:null,
		bindings:null,
		states:null
	},
	
	initialize: function(options)
	{
		this.setOptions(options);
		
		if (this.options.binding != null)
			this.options.bindings = this.options.binding.replace(/\s/g, "").split(",");
	},
	
	getContent: function()
	{
		return this.options.content;
	},
	
	getBindings: function()
	{
		return this.options.bindings;
	},
	
	hasBinding: function(values)
	{	
		for (var i = 0; i < values.length; i++)
			if (this.options.bindings.indexOf(values[i].replace(/\w+:/g, "")) != -1)
				return true;
		
		return false;
	},
	
	_display: function(content)
	{
		if (this.options.binding != null)
		{
			this.options.element.set("html", content);
		}
	}

});

var Arpe_Chunk = new Class({

	Extends: Arpe_DynamicElement,
	Implements: Options,
	options: {
		element:null,
		content:null,
		binding:null,
		states:null
	},
	
	_init: function()
	{
		this.html = this.options.element.get("html");
	}

});


var Arpe_Evaluable = new Class({

	Implements: Options,
	options: {
		element:null,
		type:null,
		subtype:null,
		condition:null
	},
	
	initialize: function(options)
	{
		this.setOptions(options);
	},
	
	_display: function()
	{
	
		try
		{
			var res = eval("(function() {return "+this.options.condition+";})()");
			
			switch (this.options.type)
			{
				case "visibility":
					this.options.element.setStyle("visibility", (res ? "hidden":"visible"));
					break;
				case "display":
					this.options.element.setStyle("display", (res ? "none":"block"));
					break;
				case "class":
					if (res)
						this.options.element.addClass(this.options.subtype);
					else
						this.options.element.removeClass(this.options.subtype);
				default:
					break;
			
			}
		}
		catch (e) { console.log(e.stack) }
	}
	

});

var Arpe_ComputedStyle = new Class({

	Implements: Options,
	options: {
		element:null,
		type:null,
		subtype:null,
		condition:null
	},
	
	initialize: function(options)
	{
		this.setOptions(options);
	},
	
	_display: function()
	{
	
		try
		{
			
			switch (this.options.type)
			{
				case "position":
					
					var position = function(params)
					{
					
					
						var subtype = params.subtype;
						var element = params.element;
						
						var subtypes = subtype.split("?");
						var reference;
						
						if (subtypes.length == 1)
							reference = element.getParent();
						else if (subtypes[1] == "previous")
							reference = element.getPrevious();
						else if (subtypes[1] == "next")
							reference = element.getNext();
						else if (subtype.search(/inherit/g) != -1)
							reference = $(subtypes[1]);
					
						if (subtypes[0] == "inherit-left" && reference != null)
							element.setStyle("left", (reference.getPosition(element.getParent()).x-element.getSize().x));
						
						if (subtypes[0] == "inherit-top" && reference != null)
							element.setStyle("top", (reference.getPosition(element.getParent()).y-element.getSize().y));
					
						if (subtypes[0] == "inherit-bottom" && reference != null)
							element.setStyle("top", (reference.getPosition(element.getParent()).y+reference.getSize().y));
						
						if (subtypes[0] == "inherit-right" && reference != null)
							element.setStyle("left", (reference.getPosition(element.getParent()).x+reference.getSize().x));
					
						if (subtypes[0] == "inherit-horizontal-center" || subtypes[0] == "inherit-both-center")
						{	
							if (element.getParent() == reference)
								element.setStyle("left", (reference.getSize().x.toInt()-element.getSize().x.toInt())/2);
							else
								element.setStyle("left", reference.getPosition(element.getParent()).x+(reference.getSize().x.toInt()-element.getSize().x.toInt())/2);
						}
							
						if (subtypes[0] == "inherit-vertical-center" || subtypes[0] == "inherit-both-center")
						{
							if (element.getParent() == reference)
								element.setStyle("top", (reference.getSize().y.toInt()-element.getSize().y.toInt())/2);
							else
								element.setStyle("top", reference.getPosition(element.getParent()).y+(reference.getSize().y.toInt()-element.getSize().y.toInt())/2);
						}
						
						if (subtypes[0] == "horizontal-offset" || subtypes[0] == "both-offset")
						{
							element.setStyle("left", -element.getXOffset()+element.getStyle("left").toInt()+parseInt(subtypes[1]));
							element.setXOffset(parseInt(subtypes[1]));
						}
						
						if (subtypes[0] == "vertical-offset" || subtypes[0] == "both-offset")
						{
							element.setStyle("top", -element.getYOffset()+element.getStyle("top").toInt()+parseInt(subtypes[1]));
							element.setYOffset(parseInt(subtypes[1]));
						}
					}
					
					if (this.options.condition.search("onload") != -1)
					{
						var target = this.options.condition.match(/[\-\w\d]+\.onload/g)[0].replace(/\.onload/g, "");
						
						var element;
						
						if (target == "self")
							element = this.options.element;
						else if (target == "parent")
							element = this.options.element.getParent();
						else if (target == "target")
							element = $(this.options.subtype[1]);
						else
							element = $(target);
						
						if (this.options.subtype == null)
							console.log(target);
						
						element.addEvent("load", position.bind(this, {subtype:this.options.subtype, element:this.options.element}));
					}
					
					var subCond;
					
					if ((subCond = this.options.condition.replace(/[\w\d]+\.onload\,/g, "")) != "" && eval("(function() {return "+subCond+";})()"))
						position({subtype:this.options.subtype, element:this.options.element});
				
					
					break;
				case "max-size":
				
					var subtypes = this.options.subtype.split("?");
					
					var padding = 0;
					
					if (subtypes.length > 1 && subtypes[1] == "padding")
						padding = parseInt(subtypes[2]);
				
					if (subtypes[0] == "inherit-height" || subtypes[0]  == "inherit-both")
					{
					
						var n = this.options.element.getParent().getSize().y-padding
						
						if (this.options.element.getStyle("min-height").toInt() > n) //drop min height
							this.options.element.setStyle("min-height", 1);
							
						this.options.element.setStyle("max-height", n);
						
					}
					if (subtypes[0]  == "inherit-width" || subtypes[0]  == "inherit-both")
					{
					
						var n = this.options.element.getParent().getSize().x-padding;
					
						console.log(this.options.element.getStyle("min-width").toInt()+" > "+n);
						
						if (this.options.element.getStyle("min-width").toInt() > n)
							this.options.element.setStyle("min-width", 1);
						
						this.options.element.setStyle("max-width", n);
					}
					if (subtypes[0] == "inherit-height-constraint")
					{
					
						var h = this.options.element.getParent().getSize().y-padding;
						var w = h/this.options.element.getSize().y*this.options.element.getSize().x;
						
						if (this.options.element.getStyle("min-height").toInt() > h) //drop min height
						{
							this.options.element.setStyle("min-height", 1);
							this.options.element.setStyle("height", h);
						}
						
						if (this.options.element.getStyle("min-width").toInt() > w) //drop min width
						{
							this.options.element.setStyle("min-width", 1);
							this.options.element.setStyle("width", w);
						}
						
						this.options.element.setStyle("max-height", parseInt(h));
						this.options.element.setStyle("max-width", parseInt(w));
						
					}
					if (subtypes[0]  == "inherit-width-constraint")
					{
					
						var w = this.options.element.getParent().getSize().x-padding;
						var h = w/this.options.element.getSize().x*this.options.element.getSize().y;
						
						if (this.options.element.getStyle("min-height").toInt() > h) //drop min height
						{
							this.options.element.setStyle("min-height", 1);
							this.options.element.setStyle("height", h);
						}
						
						if (this.options.element.getStyle("min-width").toInt() > w) //drop min width
						{
							this.options.element.setStyle("min-width", 1);
							this.options.element.setStyle("width", w);
						}
													
						this.options.element.setStyle("max-height", h);
						this.options.element.setStyle("max-width", w);
						
					}
					break;
				default:
					break;
			}
		}
		catch (e) { console.log(e.stack) }
	}
	

});

