Function.prototype.bind=function(scope){
	var _this=this;
	return function(){
		return _this.apply(scope);
	}
}

function Vatera(version){
	this.dependencies={
		'cart':['cookie','ajax'],
		'ajax':['viewport'],
		'tooltip':['CSS:tooltip'],
		'page/rating':['CSS:page/rating'],
		'page/rating_summary':['query'],
		'password/hu.password_strength_check':['password/password_strength_check'],
		'jquery/plugin/jquery.tooltip':['CSS:jquery/theme/jquery.tooltip'],
		'jquery/plugin/jquery.autocomplete':[
			'CSS:jquery/theme/jquery.autocomplete'
		],
		'jquery/plugin/jquery.agile-uploader.min':[
			'CSS:jquery/theme/jquery.agile-uploader',
			'lib/swfobject2.2'
		],
		'jquery/plugin/jquery.ui.core':['CSS:jquery/theme/ui-lightness/jquery.ui.all'],
		'jquery/plugin/jquery.ui.accordion':['jquery/plugin/jquery.ui.core','jquery/plugin/jquery.ui.widget'],
		'jquery/plugin/jquery.ui.button':[
			'jquery/plugin/jquery.ui.core',
			'jquery/plugin/jquery.ui.widget'
		],
		'jquery/plugin/jquery.ui.datepicker':['jquery/plugin/jquery.ui.core','jquery/plugin/jquery.ui.datepicker-hu'],
		'jquery/plugin/jquery.ui.dialog':[
			'jquery/plugin/jquery.ui.core',
			'jquery/plugin/jquery.ui.widget',
			'jquery/plugin/jquery.ui.button',
			'jquery/plugin/jquery.ui.draggable',
			'jquery/plugin/jquery.ui.mouse',
			'jquery/plugin/jquery.ui.position',
			'jquery/plugin/jquery.ui.resizable'
		],
		'jquery/plugin/jquery.ui.draggable':[
			'jquery/plugin/jquery.ui.core',
			'jquery/plugin/jquery.ui.mouse',
			'jquery/plugin/jquery.ui.widget'
		],
		'jquery/plugin/jquery.ui.droppable':[
			'jquery/plugin/jquery.ui.core',
			'jquery/plugin/jquery.ui.widget',
			'jquery/plugin/jquery.ui.mouse',
			'jquery/plugin/jquery.ui.draggable'
		],
		'jquery/plugin/jquery.ui.effects':['jquery/plugin/jquery.ui.core'],
		'jquery/plugin/jquery.ui.mouse':['jquery/plugin/jquery.ui.widget'],
		'jquery/plugin/jquery.ui.progressbar':[
			'jquery/plugin/jquery.ui.core',
			'jquery/plugin/jquery.ui.widget'
		],

		'jquery/plugin/jquery.ui.resizable':[
			'jquery/plugin/jquery.ui.core',
			'jquery/plugin/jquery.ui.mouse',
			'jquery/plugin/jquery.ui.widget'
		],
		'jquery/plugin/jquery.ui.selectable':[
			'jquery/plugin/jquery.ui.core',
			'jquery/plugin/jquery.ui.mouse',
			'jquery/plugin/jquery.ui.widget'
		],
		'jquery/plugin/jquery.ui.slider':[
			'jquery/plugin/jquery.ui.core',
			'jquery/plugin/jquery.ui.mouse',
			'jquery/plugin/jquery.ui.widget'
		],
		'jquery/plugin/jquery.ui.sortable':[
			'jquery/plugin/jquery.ui.core',
			'jquery/plugin/jquery.ui.mouse',
			'jquery/plugin/jquery.ui.widget'
		],
		'jquery/plugin/jquery.ui.tabs':[
			'jquery/plugin/jquery.ui.core',
			'jquery/plugin/jquery.ui.widget'
		],
		'autocomplete':[
			'jquery/plugin/jquery.autocomplete'
		],
		'autocomplete.settlement':[
			'autocomplete'
		],
		'autocomplete.termsearch':[
			'autocomplete'
		]
	};

	this.dependedModulCollection=[];

	this.searchDependedModuls=function(modul){
		if(modul in this.dependencies){
			for(i in this.dependencies[modul]){
				if(typeof this.dependencies[modul][i]=='string'){ // TODO: need to remove when v3.js will be deleted
					this.searchDependedModuls(this.dependencies[modul][i]);
				}
			}
			this.dependedModulCollection.push(modul);
		}
		else{
			this.dependedModulCollection.push(modul);
		}
	}

	this.loadModules=function(modulsToLoad){
		for(var i in modulsToLoad){
			if(
				modulsToLoad[i] in this.loadedModules||
				modulsToLoad[i]==undefined||
				typeof modulsToLoad[i]!='string' // TODO: need to remove when v3.js will be deleted
			){
				continue;
			}

			this.searchDependedModuls(modulsToLoad[i]);
			for(var k in this.dependedModulCollection){
				if(
					this.dependedModulCollection[k] in this.loadedModules||
					typeof this.dependedModulCollection[k]!='string' // TODO: need to remove when v3.js will be deleted
				){
					continue;
				}
				this.loadedModules[this.dependedModulCollection[k]]=true;
				if(this.dependedModulCollection[k].substring(0,4)=='CSS:'){
					document.write('<link type="text/css" href="'+ImageUrl+'v2/jsmoduls/'+this.dependedModulCollection[k].replace('CSS:','')+'.css?'+this.version+'" rel="stylesheet" />');
				}
				else{
					document.write('<script type="text/javascript" src="'+ImageUrl+'v2/jsmoduls/'+this.dependedModulCollection[k]+'.js?'+this.version+'"></script>');
				}
			}

		}
	}

	// init
	this.loadedModules={};
	this.version=version;
}

