	
$(document).ready(function(){
	
	$.get("index.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) {
			//alert($('.items').append(gamesArray[i].visible))
			
			var xml_videos=$(videosXML).find('item');
			//alert($(xml_videos[i]).find('visible').text())
			if($(xml_videos[i]).find('visible').text() == "on")
			{
				//alert("in if");
					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;	
			}
			else
			{
				//alert("in else");
			}
			
		});
		
		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 + ' img[data-hover]')
				.hover(function() {
					$(this)
						.attr('tmp', $(this).attr('src'))
						.attr('src', $(this).attr('data-hover'))
						.attr('data-hover', $(this)
						.attr('tmp')).removeAttr('tmp');
				}).each(function() {
					$('<img />')
						.attr('src', $(this).attr('data-hover'));
				});;
				
				$('#' + i)
					.css('cursor','pointer')
					.click(function() {
						openIframe(i);
					});
					
				if(i == gamesArray.length - 1) {
					$('.scrollable .items').css('width', divwidth);
					
					setTimeout(function(){
						openIframe(0);
					}, 1000);
					
				}
			});
			
		break;
		
		case 'videos':
			
			$(videosArray).each(function(i){
				//alert(i)
				divwidth += 160;
				
				$('.items').append('<div id="'+ i +'"><img src="'+ videosArray[i].imgoff +'" data-hover="'+ videosArray[i].imgon +'" border="0" /></div>');
				
				$('#' + i + ' img[data-hover]')
				.hover(function() {
					$(this)
						.attr('tmp', $(this).attr('src'))
						.attr('src', $(this).attr('data-hover'))
						.attr('data-hover', $(this)
						.attr('tmp')).removeAttr('tmp');
				}).each(function() {
					$('<img />')
						.attr('src', $(this).attr('data-hover'));
				});;
				
				$('#' + i)
					.css('cursor','pointer')
					.click(function() {
						openIframe(i);
					});
					
				if(i == videosArray.length - 1) {
					$('.scrollable .items').css('width', divwidth);
					
					setTimeout(function(){
						openIframe(0);
					}, 1000);
				}
			});
			
		break;
	}	
}
