//-------------------------------------------------------------------
// START: SETTINGS
//-------------------------------------------------------------------
	
	sects=new Array("content","services","applications","platforms","infrastructure","seeds");
	stats=new Array("active","past");
	
//-------------------------------------------------------------------
// START: VARIABLES
//-------------------------------------------------------------------
	var iMax = 0;
	var aCompanyID 			= new Array();
	var aCompanyName 		= new Array();
	var aCompanyImage 		= new Array();
	var aCompanyLink 		= new Array();
	var xmlSource = "/portfolio/portfolio.xml";
	
//-------------------------------------------------------------------
// START: NAV FUNCTIONS
//-------------------------------------------------------------------

// JQUERY - START READY FUNCTIONS
$(document).ready(function(){
		
	//-------------------------------------------------------------------
	// JQUERY - Data/Library Functions
	
	$.get(xmlSource,{},function(xml){
      	numOfItems=$('company',xml).length;
    	i = 1;
		
		var set = new Array();
	
		$('company',xml).each(function(i) {
			cName = $(this).find("basic").find("name").text().toLowerCase();
			cNameUcase = cName.toUpperCase();
			cId = $(this).find("basic").find("id").text();
			cUrl= $(this).find("link").text();
			cImage= $(this).find('size1').text();
			
			set.push(new Array(cNameUcase, cName, cImage, cUrl, cId));	
		});

		set.sort();
		
		for(i=0;i<set.length;i++)	{
			aCompanyID[i] 		= parseInt(set[i][4]);;
			aCompanyName[i] 	= set[i][1];
			aCompanyImage[i] 	= set[i][2];
			aCompanyLink[i] 	= set[i][3]
		} // for

		iMax = i-1; // sets max number of items shown	
		
		jQuery.fn.fncPageSetUp();
	});
	
	// placeholder fncPageSetUp - used for secondary pages
	jQuery.fn.fncPageSetUp = function() {}
	//-------------------------------------------------------------------
	// JQUERY - Set up and load the lists/sort
	
	if($.browser.msie)	{
		$("#exp_options li").css({width: '160px'});
	}

	$(".lowernav li").click(function()	{
		
		$(this).addClass('current');
		curr=$(this).text();
		
		$('.lowernav li').each(function()	{
			if($(this).text() != curr)	{
				$(this).removeClass('current');
			}
		});

		if($.browser.msie)	{
			by_sector($(this).attr('id'));
		} else	{
			by_sector($(this).html());
		}
		
	}); // end lowernav li click

	by_sector_all();
	$("#all").addClass('current');
	
	
}); // end jQuery load

function fncChangeHeader(sText) {
	//$("h2").html(sText);
	// turned off
}; // fncChangeHeader

function by_name()	{
	var contents="";
	var set = new Array();
	$.get(xmlSource,{},function(xml){
		$('company',xml).each(function(i) {

			cName = $(this).find("basic").find("name").text().toLowerCase();
			cId = $(this).find("basic").find("id").text();
			cUrl= $(this).find("link").text();
			cDescription= $(this).find("descriptions").find("short").text();
			
			set.push(new Array(cName, cDescription, cUrl, cId));	
		});

		// Update the DIV called contents Area with the HTML string
		set.sort();

		for(c=0;c<set.length;c++)	{
			contents += "<li class='portfolio_name' id='p_"+set[c][3]+"'><span class='p_"+set[c][3]+"colorchange'>"+set[c][0]+"</span></li>";
			contents+="<ul class='portfolio_data' id='p_"+set[c][3]+"_data'>";
			contents += "<li>"+set[c][1]+"</li>";
			contents += "<li class='more'><a href='"+set[c][2]+"'>more</a></li>";
			contents+="</ul>";
		}

		$("#portfolio").html(contents);
		add_click();
	});
} // end by_name()

function by_sector(limit)	{
	var contents="";
	limit = limit.toLowerCase();
	
	set=new Array();

	if(limit=="all")	{
		by_sector_all();
	} else	{
		// is this for past investments or current?
		if ( limit == "past investments" || limit == "past" ) {
			fncChangeHeader("Past Investments");
			by_sector_past_all();
		} else {
			fncChangeHeader("Current Investments");
			
			bWriteSection = false;
			
			//get sectors
			contents="<h5 style='font-weight: normal'>"+limit+"</h5>";
			$.get(xmlSource,{},function(xml){
				$('company',xml).each(function(i) {
					if ( $(this).find("status").text() == "Current Investment" ) {
					  cName = $(this).find("basic").find("name").text().toLowerCase();
					  cId = $(this).find("basic").find("id").text();
					  cUrl= $(this).find("link").text();
					  cDescription= $(this).find("descriptions").find("short").text();
					  
					  cSector = $(this).find("sector").map(function()	{
						  if($(this).text().toLowerCase()==limit)	{
							  set.push(new Array(cName, cDescription, cUrl, cId));	
							  bWriteSection = true;
						  }
					  })
					}
				});
	
				set.sort();
		
				if (bWriteSection) {
					for(c=0;c<set.length;c++)	{
						contents += "<li class='portfolio_name' id='p_"+set[c][3]+"'><span class='p_"+set[c][3]+"colorchange'>"+set[c][0]+"</span></li>";
						contents+="<ul class='portfolio_data' id='p_"+set[c][3]+"_data'>";
						contents += "<li>"+set[c][1]+"</li>";
						contents += "<li class='more'><a href='"+set[c][2]+"'>more</a></li>";
						contents+="</ul>";
					}
				} else {
					contents += "<p>To be announced!</p>";
				} // bWriteSection
			
				$("#portfolio").html(contents);
				add_click();
			});
		} // if current investment
	}
} // end by_sector();

function by_sector_all()	{
	fncChangeHeader("All Investments");
	
	var contents="";
	
	$.get(xmlSource,{},function(xml){
		set=new Array();
		
		$('company',xml).each(function(i) {
			cName = $(this).find("basic").find("name").text().toLowerCase();
			cId = $(this).find("basic").find("id").text();
			cUrl= $(this).find("link").text();
			cDescription= $(this).find("descriptions").find("short").text();
			
			set.push(new Array(cName, cDescription, cUrl, cId));	
		});
	
		set.sort();
		
		for(c=0;c<set.length;c++)	{
			contents += "<li class='portfolio_name' id='p_"+set[c][3]+"'><span class='p_"+set[c][3]+"colorchange'>"+set[c][0]+"</span></li>";
			contents+="<ul class='portfolio_data' id='p_"+set[c][3]+"_data'>";
			contents += "<li>"+set[c][1]+"</li>";
			contents += "<li class='more'><a href='"+set[c][2]+"'>more</a></li>";
			contents+="</ul>";
		} // for
		
		$("#portfolio").html(contents);
		add_click();
		$("#page_cover").css({height: $(document).height()});
	});
	
} // end by_sector_all()

function by_status()	{
	contents="";
	head=new Array();
	$.get(xmlSource,{},function(xml){
		for(s=0;s<stats.length;s++)	{
			limit=stats[s];
			set=new Array();
			
			bWriteSection = false;
			
			//get sectors
			contents+="<h5 style='font-weight: normal'>"+limit+"</h5>";
			
			$('company',xml).each(function(i) {
				cName = $(this).find("basic").find("name").text().toLowerCase();
				cId = $(this).find("basic").find("id").text();
				cUrl= $(this).find("link").text();
				cDescription= $(this).find("descriptions").find("short").text();
				cSector = $(this).find("status").text();
				if(cSector.toLowerCase()==limit)	{
					set.push(new Array(cName, cDescription, cUrl, cId));
					
				}	
			});
			
			
			set.sort();
			for(c=0;c<set.length;c++)	{
				contents += "<li class='portfolio_name' id='p_"+set[c][3]+"'><span class='p_"+set[c][3]+"colorchange'>"+set[c][0]+"</span></li>";
				contents+="<ul class='portfolio_data' id='p_"+set[c][3]+"_data'>";
				contents += "<li>"+set[c][1]+"</li>";
				contents += "<li class='more'><a href='"+set[c][2]+"'>more</a></li>";
				contents+="</ul>";
			} // for - inner
		} // for - outer

		$("#portfolio").html(contents);
		add_click();
	});
} // end by_status()

function add_click()	{
	$(".portfolio_name span").mouseover(function()	{
		//$(this).css({color: '#999999', fontWeight: 'normal'});
	});

	$(".portfolio_name span").mouseout(function()	{
		if($('#'+$(this).parent().attr('id')+ '_data').css('display')=='none')	{
			//$(this).css({color: '#FD3130'});
		}
	});
	
	close_others=true;
	
	$(".portfolio_name span").click(function()	{
		current=$(this).parent().attr('id');
		currclass=$(this).parent().attr('class');
		$(this).toggleClass('on');
		if($(this).parent().next().css('display')=='none')	{
			//$('#'+$(this).parent().attr('id')+ '_data').css({display: 'block'});
			//alert($(this).parent().next().get(0));
			$(this).parent().next().css({display: 'block'});
			if(close_others)	{
				$(".portfolio_name").each(function()	{
					if($(this).attr('id')!=current )	{
						$(this).next().css({display: 'none'});
						$(this).children().removeClass('on');
					}
				});
			}
		} else	{
			$(this).parent().next().css({display: 'none'});	
			$(this).parent().removeClass('on');
		}
	});
}


function by_sector_past_all()	{	
	var contents="";
				
	$.get(xmlSource,{},function(xml){
		
		for(s=0;s<sects.length;s++)	{
			set=new Array();
			limit=sects[s];
			
			bWriteSection = false;
					
			$('company',xml).each(function(i) {
				if ( $(this).find("status").text() == "Past Investment" ) {
					cName = $(this).find("basic").find("name").text().toLowerCase();
					cId = $(this).find("basic").find("id").text();
					cUrl= $(this).find("link").text();
					cDescription= $(this).find("descriptions").find("short").text();
					
					cSector = $(this).find("sector").map(function()	{
						if($(this).text().toLowerCase()==limit)	{
							set.push(new Array(cName, cDescription, cUrl, cId));
							bWriteSection = true;
						}
					})
				}
			});
		
			set.sort();
			
			if (bWriteSection) {
				contents+="<h5 style='font-weight: normal'>"+limit+"</h5>";
				for(c=0;c<set.length;c++)	{
					contents += "<li class='portfolio_name' id='p_"+set[c][3]+"_"+limit+"'><span class='p_"+set[c][3]+"colorchange'>"+set[c][0]+"</span></li>";
					contents+="<ul class='portfolio_data "+limit+"' id='p_"+set[c][3]+"_data'>";
					contents += "<li>"+set[c][1]+"</li>";
					contents += "<li class='more'><a href='"+set[c][2]+"'>more</a></li>";
					contents+="</ul>";
				} // for - inner
				contents+="<li><br /><li>";
			} // bWriteSection
		} // for - outer
		
		$("#portfolio").html(contents);
		add_click();
		$("#page_cover").css({height: $(document).height()});
	});
	
} // end by_sector_all()