/*
Kris Merckx - www.ardeco.be
2011
Creative Commons Licence
*/	
	$Icaros = function(n){
		this.name=n;
		this.webos="IcarOS";
		this.kernel="kernel 2.9";
		this.desktop= "Desktopversion 3.0";
		this.releasedate="10-2011";
		this.author= "Kris Merckx";
		this.website= "http://www.ardeco.be";
	};
	$Icaros.Apps={};
	
	$Icaros.Apps.ListApps= function(x,p,el,id){
		if(p=="desktop"){
			var ul= document.createElement("ul");
			ul.setAttribute("id", id);
			var elem= document.getElementById(el);	
			elem.appendChild(ul);
		}
		
		$(x).find("app").each(function(){
			var $appName=$(this).attr("name");
			var $appIcon=$(this).attr("icon");
			var $appWin=$(this).attr("window");
			var $appWidth=$(this).attr("width");
			var $appHeight=$(this).attr("height");
			var $appPath=$(this).find("path").text();
			
			
			var li= document.createElement("li");
			var applink= document.createElement("a");
			applink.setAttribute("href", $appPath);
			applink.setAttribute("title", $appName);
			
			applink.setAttribute("icarosWinW", $appWidth);
			applink.setAttribute("icarosWinH", $appHeight);
			
			if($appWin=="#"){
				applink.setAttribute("target", "_parent");
			}else{
				applink.setAttribute("target", "_blank");
			}
			applink.setAttribute("class", "appa");
			li.appendChild(applink);
			var appIcon= document.createElement("img");
			appIcon.setAttribute("src", $appIcon);
			applink.appendChild(appIcon);
			var appP=document.createElement("p");
			applink.appendChild(appP);
			
			var appText=document.createTextNode($appName);
			appP.appendChild(appText);
			
			document.getElementById(id).appendChild(li);
			/*Rendered result:
			<ul id="links">
			<li><a href="" target="" class="appa"><img src=""/><p></p></a></li>
			</ul>
			*/
			
		});	
		//$(document).pngFix(); 
		if(p=="desktop"){
			$("#" + id + " li").draggable();
			$("#" + id).sortable();
			
			$("#" + id + " li a").hover(function(){
				$(this).children("p").css("color", "black");
			},
			function(){
				$(this).children("p").css("color", "white");
			});
			$.window.prepare({
				dock: 'bottom',       
				animationSpeed: 200,  
				minWinLong: 180       
			});
			if($.browser.msie){
				$(".appa img").css("width", "60px");
				$(".appa img").css("height", "60px");
				$(".appa p").css("font-size", "x-small");	
				$(".appa img").removeAttr("width");
				$(".appa img").removeAttr("height");
			}
			$(".appa").click(function(ec){
				if($(this).attr("target")=="_parent"){
					ec.preventDefault();
				}	
			});
			$(".appa").dblclick(function(e){
				if($(this).attr("target")=="_parent"){
					var icWinW=$(this).attr("icarosWinW");
					var icWinH=$(this).attr("icarosWinH");
					
					if(isNaN(icWinW)){icWinW=850;}else{icWinW=parseInt(icWinW);}
					if(isNaN(icWinH)){icWinH=400;}else{icWinH=parseInt(icWinH);}
				
			        var icWin= $.window({
					   title: $(this).attr("title"),
					   url: $(this).attr("href"),
					   icon: $(this).children("img").attr("src"),
					   width: icWinW,
					   height: icWinH,
					   showRoundCorner: true,
					   maxWidth: -1,
					   maxHeight: -1
					});
					e.preventDefault();
				}
			});
		}
	}
	
	$Icaros.prototype.GetApps= function(curl,present,el,id){
		$.ajax({
		    type: "GET",
			url: curl,
			dataType: "xml",
			success: function(xml){
				$Icaros.Apps.ListApps(xml,present,el,id);
			}
		});		
	}



		
		function display(){
			alert("Deze functie is nog niet beschikbaar.");	
		}
		function iconsReverse(){
			$(".appa").parent("li").css("float","right");	
		}
		function iconsLeft(){
			$(".appa").parent("li").css("float","none");	
		}
		function iconsDefault(){
			$(".appa").parent("li").css("float","left");	
		}

