(function () {
	var config,
	create,
	widget,
	
	config = {
		lang : "sv",
		containerId : "insertJannrNav",
		mainArticle : {
			tagName : "ul",
			appendChildren : [{
				tagName : "li",
				appendChildren : [{
					tagName : "h2",
					innerHTML : 'Mer grejer på <a href="http://jannr.com">jannr.com</a>:',
				},
				{
        			tagName : "ul",
		            appendChildren : [{
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://jannr.com/tagged/fotografi",
                            innerHTML : "fotograferat"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://jannr.com/tagged/film",
                            innerHTML : "filmat"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://jannr.com/archive",
                            innerHTML : "arkiv"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://jannr.com/random",
                            innerHTML : "slumpa"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://www.tumblr.com/liked/by/mjanner",
                            innerHTML : "jag gillar"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://tellusgrand.jannr.com/",
                            innerHTML : "tellusgränd"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://espresso.jannr.com/",
                            innerHTML : "espresso espresso"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://pixlar.jannr.com/",
                            innerHTML : "nya pixlar"
        				}]
                    }]
				}]
			},
			{
				tagName : "li",
				appendChildren : [{
					tagName : "h2",
					innerHTML : 'Annat Janner:',
				},
				{
        			tagName : "ul",
		            appendChildren : [{
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://anne-lina.jannr.com/",
                            innerHTML : "Anne-Lina"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://lillapi.com/",
                            innerHTML : "3,14"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://carolinnea.tumblr.com/",
                            innerHTML : "Carolina"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://janner.se/",
                            innerHTML : "Hela familjen"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://janner.blogg.se",
                            innerHTML : "Oskar och Pernilla"
        				}]
                    },
                    {
        				tagName : "li",
        				appendChildren : [{
        					tagName : "a",
        					href : "http://jannerferner.blogg.se",
                            innerHTML : "Monika och Rolf"
        				}]
                    }]
				}]
			}]
		}
	};









	create = function (obj) {
		var keys, 
		newElement = obj.tagName ? document.createElement(obj.tagName) : document.createElement("div"),
		i,
		newKid;
		for (keys in obj) {
			if (keys !== "tagName") {
				if ((/clas[s](Name)?/).test(keys)) {
					newElement.className = obj[keys];
				} else if (newElement.style[keys]) {
					newElement.style[keys] = obj[keys];
				} else if (keys === "appendChildren") {
					for (i = 0; i < obj[keys].length; i += 1) {
						newKid = create(obj[keys][i]);
						newElement.appendChild(newKid);
					}
				} else {
					newElement[keys] = obj[keys];
				}
			}
		}
		return newElement;
	};
	widget = {
		init : function () {
			var cf = config,
			cont = document.getElementById(cf.containerId),
			cn = "jannrWidget";
			cont.appendChild(create(cf.mainArticle));
		}
	};
	widget.init();
}());

