	

	//-------------------------------------------
	//	XML
	//-------------------------------------------
	var xml;
	var itemWidth = 200;
	var itemPadding = 10;
	var itemIndex = 0;
	var contentDir = "";
	
	var fileSelected = "";
	var fileInView = "";
	var descrSelected = "";
	var isNew = false;
	
	var image;
	var itemContainerWidth = 0;
	
	
	//-------------------------------------------
	//	LOAD FILE
	//-------------------------------------------
	LoadXML = function( xmlFile , contentDirectory ) {
		xml = null;
		
		if( $.trim( contentDirectory ) == "" ) return;
		contentDir = contentDirectory;
		
		itemIndex = 0;
		itemContainerWidth = 0;
		$("#ItemContainer").html( "" );
		
		$.ajax( { type:"GET" , url: "xml/" + xmlFile , dataType: "xml" , success: XMLLoaded } );
	}//end function
	
	
	XMLLoaded = function( e ) {
		xml = $( e ).find("item");
		$.each( xml , HandleXML );
		$("#ItemContainer" ).css( "width" , itemContainerWidth + itemWidth );	
	}//end function
	
	
	HandleXML = function( index , element ) {
		var title = $(this).find("title").text();
		var file = $(this).find("link").text();
		var descr = $(this).find("description").text();
		var isNew = $(this).find("isNew");
		
		var x = itemIndex * ( itemWidth + itemPadding );
		
		$("#ItemContainer").append("<div id='Item"+ itemIndex +"' unselectable='on'>" + title + "</div>");
		
		var contentItem = $( "#Item" + itemIndex );
		contentItem.addClass( "Item" );
		contentItem.css( "left" , x );
		
		contentItem.data( "file" , file );
		contentItem.data( "descr" , descr );
		contentItem.data( "isNew" , isNew );
		
		contentItem.bind( "click" , HandleItemClick );
		
		itemIndex++;
		itemContainerWidth += ( itemWidth + itemPadding );
	}//end function
	
	
	
	
	//-------------------------------------------
	//	EVENTS
	//-------------------------------------------
	HandleItemClick = function( e ) {
		fileSelected = $(this).data("file");
		descrSelected = $(this).data("descr");
		isNew = $(this).data("isNew");
		
		ShowContentSelected();
	}//end function
	
	
	
	ShowContentSelected = function() {
		if( fileInView == fileSelected ) return;
		
		//IMAGES
		if( fileSelected.indexOf( ".png" ) != -1 || fileSelected.indexOf( ".jpg" ) != -1 ) {
			$("#Content" ).empty();
			ShowImage();

		//FLASH
		}else if( fileSelected.indexOf( ".swf" ) != -1 ) {
			$("#Content" ).empty();
			ShowFlash();
			
		//UNITY
		}else if( fileSelected.indexOf( ".unity3d" ) != -1 ) {
			$("#Content" ).empty();
			ShowUnity();

		}else if( fileSelected.indexOf( ".mp3" ) != -1 ) {
			PlayMusic();

		}//end if
		
		fileInView = fileSelected;
	}//end function
	
	
	
	ShowImage = function() {
		ShowLoader();
		image = new Image();
		image.src = contentDir +"/"+ fileSelected;
		$( image ).load( ImageLoaded );
	}//end function


	ImageLoaded = function( e ) {
		HideLoader();
		$("#Content" ).fadeOut(0);
		$(this).addClass("ImageContent");
		$("#Content" ).append( image );
		$("#Content" ).fadeIn( 1000 );
	}//end function
	
	
	
	ShowFlash = function() {
		var htmlString = '<embed src="' + contentDir +'/'+  fileSelected + '" width="800" height="500"/>';
		$("#Content" ).append( htmlString );
	}//end function
	
	
	
	ShowUnity = function() {
		$("#Content" ).append( "<div id='UnityContent'></div>" );
		
		unityObject.embedUnity( "UnityContent", contentDir + "/" + fileSelected, 800, 500 );
		
		if( !unityObject ) {
			var htmlString = "";		
			htmlString += '<div class="missing">';
			htmlString += '	<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">';
			htmlString += '		<img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />';
			htmlString += '	</a>';
			htmlString += '</div>';
			document.getElementById("Content").innerHTML = htmlString;
		}//end if
	}//end function
	
	
	PlayMusic = function() {
		var musicPlayer = $( "#FlashObject" ).get(0);
		musicPlayer.Load( contentDir + "/" + fileSelected );
	}//end function
	
	
	
	
	//-------------------------------------------
	//	SHOW/HIDE PRELOADER IMAGE
	//-------------------------------------------
	ShowLoader = function() {
		$("#Content" ).empty();
		$("#Content" ).append("<div id='Preloader'>Loading...</div>");
	}//end function

	
	HideLoader = function() {
		$("#Content" ).empty();
	}//end function
	
	
	
	//END-------------------------------------------
