showList = function(){
	if(navigator.appVersion.indexOf("afari") > 0){
		$('lijstje').style.display = 'block';
		var myEffect = $('lijstje').effect('height', {duration: 350, transition: Fx.Transitions.expoOut});
		myEffect.start(20, 410);
	} else {
		$('list').style.overflow = 'hidden';
		$('lijstje').style.display = 'block';
		var myEffect = $('lijstje').effect('height', {duration: 350, transition: Fx.Transitions.expoOut, onComplete: function(){$('list').style.overflow = 'auto';$('list').style.overflowX = 'hidden';}});
		myEffect.start(20, 410);
	}
}

hideList = function(){
	if(navigator.appVersion.indexOf("afari") > 0){
		var myEffect = $('lijstje').effect('height', {duration: 350, transition: Fx.Transitions.expoIn, onComplete: function(){ $('lijstje').style.display = 'none'; }});
		myEffect.start(410, 1);
	} else {
		$('list').style.overflow = 'hidden';
		var myEffect = $('lijstje').effect('height', {duration: 350, transition: Fx.Transitions.expoIn, onComplete: function(){ $('lijstje').style.display = 'none'; }});
		myEffect.start(410, 1);
	}
}

function addItem(id, color){
	new Ajax("http://www.quax.eu/indoor/addItem/" + id + "/" + color + "/", {method: 'get', update: 'ajaxwrapper', evalScripts: true, onComplete: getItems }).request();
	pageTracker._trackPageview("item_added_to_list_"+id );
	//new Ajax("http://10.0.0.90/quax/indoor/addItem/" + id + "/" + color + "/", {method: 'get', update: 'ajaxwrapper', evalScripts: true, onComplete: getItems }).request();
}

function removeItem(id, color) {
	new Ajax("http://www.quax.eu/indoor/removeItem/" + id + "/" + color + "/", {method: 'get', update: 'ajaxwrapper', evalScripts: true, onComplete: getItems }).request();
	pageTracker._trackPageview("item_removed_from_list_"+id );
	//new Ajax("http://10.0.0.90/quax/indoor/removeItem/" + id + "/" + color + "/", {method: 'get', update: 'ajaxwrapper', evalScripts: true, onComplete: getItems }).request();
}

function getItems(){
	//new Ajax("http://10.0.0.90/quax/indoor/getItems/", {method: 'get', evalScripts: true, update:'list', onComplete: adaptLinks }).request();
	new Ajax("http://www.quax.eu/indoor/getItems/", {method: 'get', evalScripts: true, update:'list', onComplete: adaptLinks }).request();
}

function adaptLinks() {
	$$('a').each(function(a) {
		if(a.hasClass('add')) {
			a.addEvent('click',function (evt) {
				args = a.getAttribute('id').split("_");
				addItem(args[0], args[1]);
				new Event(evt).stop();
			});
		}
		
		if(a.hasClass('trash') || a.hasClass('delete')) {
			a.addEvent('click',function (evt) {
				args = a.getAttribute('id').split("_");
				removeItem(args[0], args[1]);
				new Event(evt).stop();
			});
		}
		
		if(a.hasClass('up')) {
			a.addEvent('click',function (evt) {
				showList();
				new Event(evt).stop();
			});
		}
		
		if(a.hasClass('down')) {
			a.addEvent('click',function (evt) {
				hideList();
				new Event(evt).stop();
			});
		}
		
	});
}

window.addEvent('load', adaptLinks);
