	
$(document).ready(function(){
	
	$.get("xml/main.xml", function(xml) {
		
		gamesXML = $(xml).find('games');
		
		$(gamesXML).find('item').each(function(i) {
				
			var object = new Object;
			object.type = 'games';
			
			$(this).children().each(function(i) {		
				if((this).nodeName != 'params') {
					$(object).attr((this).nodeName, $(this).text());
				} else {
					$(this).children().each(function(i){
						if((this).nodeName == 'js'){
							$(object).attr((this).nodeName + i, $(this).text());
						} else {
							$(object).attr((this).nodeName, $(this).text());
						}
					});
				}
			});
			
			gamesArray[i] = object;	
			
		});
		
		videosXML = $(xml).find('videos');
		
		$(videosXML).find('item').each(function(i) {
			
			var object = new Object;
			object.type = 'videos';
			
			$(this).children().each(function(i) {		
				if((this).nodeName != 'params') {
					$(object).attr((this).nodeName, $(this).text());
				} else {
					$(this).children().each(function(i){
						if((this).nodeName == 'js'){
							$(object).attr((this).nodeName + i, $(this).text());
						} else {
							$(object).attr((this).nodeName, $(this).text());
						}
					});
				}
			});
			
			videosArray[i] = object;	
			
		});
		
		aboutXML = $(xml).find('about');
		
		$(aboutXML).children().each(function(i) {
			$(siteconfig).attr('abouttxt', $(this).text());
		});
		
		buildGalleryNav(section);
	});	
});


function Narnia() {
	//buildGalleryNav(section);
}


function buildGalleryNav(type) {
	
	var divwidth = 0;
	
	$('.items').empty();
	
	switch (type) {
		
		case 'games':
			
			$(gamesArray).each(function(i) {
				
				divwidth += 160;
				
				$('.items').append('<div id="'+ i +'"><img src="'+ gamesArray[i].imgoff +'" data-hover="'+ gamesArray[i].imgon +'" border="0" /></div>');
					
				$('#' + i).hover(function(){
					if (i != seti) {
						$(this).find('img').attr('tmp', $(this).find('img').attr('src'));
						$(this).find('img').attr('src', $(this).find('img').attr('data-hover'));
					}
					
				}, function(){
					
					if (i != seti) {
						$(this).find('img').attr('src', $(this).find('img').attr('tmp'));
						$(this).find('img').removeAttr('tmp');
					}
				});
				
				$('#' + i)
					.css('cursor','pointer')
					.click(function() {
						seti = i;
						openIframe(i);
					});
					
				if(i == gamesArray.length - 1) {
					$('.scrollable .items').css('width', divwidth);
					
					setTimeout(function(){
						seti = 0;
						openIframe(0);
					}, 1000);
					
				}
			});
			
		break;
		
		case 'videos':
			
			$(videosArray).each(function(i){
				
				divwidth += 160;
				
				$('.items').append('<div id="'+ i +'"><img src="'+ videosArray[i].imgoff +'" data-hover="'+ videosArray[i].imgon +'" border="0" /></div>');
				
				$('#' + i).hover(function(){
					if (i != seti) {
						$(this).find('img').attr('tmp', $(this).find('img').attr('src'));
						$(this).find('img').attr('src', $(this).find('img').attr('data-hover'));
					}
					
				}, function(){
					
					if (i != seti) {
						$(this).find('img').attr('src', $(this).find('img').attr('tmp'));
						$(this).find('img').removeAttr('tmp');
					}
				});
				
				$('#' + i)
					.css('cursor','pointer')
					.click(function() {
						seti = i
						openIframe(i);
					});
					
				if(i == videosArray.length - 1) {
					$('.scrollable .items').css('width', divwidth);
					
					setTimeout(function(){
						seti = 0;
						openIframe(0);
					}, 1000);
				}
			});
			
		break;
	}	
}
