
		var currSlide;
		var soapListsNs = "http://schemas.microsoft.com/sharepoint/soap/";	
		var soapUserGroupNs = "http://schemas.microsoft.com/sharepoint/soap/directory/";
		var webServiceUrl_Lists = "../_vti_bin/lists.asmx";
		
		var numOfProj = 1;
		var page = "";	
		var counter = 0;
		
		var ascending = false;
		var projPerPage = 9;  
		var startingNum = 0;
		var searchOrder = 'alpha';
		
		var numPerPage;
		var queryString;
		var searchOrder;
		var currentQuery;
		var numOfProj;
		
		var slideNum = 0;
		var numOfPhotos;
		
$(function(){


		var adrnd = Math.floor(Math.random()*3);
			
		if($('.adrotator').length > 0){
			$('.adrotator li').eq(adrnd).show();		
		}

		
	if($('a.lightbox').length > 0){
		$('a.lightbox').lightBox();
	}

	$('.gallery li img').css({'opacity':0});  
	
	numOfPhotos = $('.gallery li').length;
	
	for (var i=0; i<numOfPhotos; i++){
		var theLI = document.createElement('li');
		var theLink = document.createElement('a');
		var theSpan = document.createElement('span');
		$(theLI).addClass('thumb').attr('id', 't_'+i);
		$(theLink).append(theSpan);
		$(theLI).append(theLink);
		$('.thumbs').append(theLI);
		
	}
		
		
	/*faq effect*/

	$('.answer').slideUp(1);
	$('.question p.para').click(function(){
		if($(this).next('.answer').css('display') != 'block'){
			$('.answer').slideUp();
			$(this).next('.answer').slideDown();
		}else{
				$('.answer').slideUp();
		}
	});
	$('.answer').click();
	
	
	/*community people*/	

	if($('#teamList').length >0){
		var rndTeam = Math.ceil(Math.random()*21);
		$('#teamList').children('li').hide();
		for (var p=0; p<3; p++){
			if(rndTeam+p <21){
				$('#teamList li').eq(Number(rndTeam+p)).show();
			}else{
				$('#teamList li').eq(Number(p)).show();
			}
		}
		$('#teamList').css({'visibility':'visible'});
	}
	
	/*Social Links*/
	if($('#socialLinks').length >0){
		var URL = window.location.href;
        var theLinks = '<li><a target="_blank" href="http://digg.com/submit"><img src="images/icons/digg.gif" width="14" height="14" alt="Digg" /> Digg This</a></li>';
        theLinks +=    '<li><a target="_blank" href="http://www.newsvine.com/_tools/seed?popoff=0&amp;u='+URL+'"><img src="images/icons/newsvine.gif" alt="Newsvine"  width="16" height="16" />Seed Newsvine</a></li>';
		theLinks +=    '<li><a target="_blank" href="http://slashdot.org/slashdot-it.pl?op=basic&amp;url='+URL+'"><img src="http://images.slashdot.org/favicon.ico" alt="Slashdot" border="0" height="16" width="16" />Submit at Slashdot </a></li>';
		$('#socialLinks').append(theLinks);
	}
	
	if($('#storyTitle').length > 0){ getStory('detail'); }
	if($('#storyOverview').length > 0){ getStory('overview'); }


});
	
	function advance(){
		if(slideNum < numOfPhotos-1){
			slideNum++;
		}else{
			slideNum = 0;
		}
		$('.thumb').removeClass('thumbOn');                                               //Remove the "on" state from all thumbs
		$('.thumb').eq(slideNum).addClass('thumbOn');                                                      //Add the "on" state to the selected thumb      
		$('.gallery li img').css({'visibility':'visible'}); 
		$('.gallery li img').stop().animate({'opacity':0}, 900);                          //Hide all slides
		$('.gallery li').eq(slideNum).find('img').stop().animate({'opacity':1}, 500);     //Show selected slide
	}
	
$(function(){
	//SLIDESHOW PROGRAM FOLLOWS
	//ON INITIAL PAGE LOAD

		$('.gallery li img').css({'opacity':0}).css({'visibility':'visible'});                                              //Hide all slides
		$('.gallery li').css({'backgroundColor':'#000000'});
		$('.gallery li:first-child img').css({'opacity':1}).css({'visibility':'visible'});                                  //Show first slide
		$('.thumbs li:first-child').addClass('thumbOn');                                      //Assign first thumb "on" state
		var theTime = setInterval("advance()", 11000);
		
		
	//ON THUMBNAIL CLICK	
		$('.thumb').click(function(){
			$('.thumb').removeClass('thumbOn');                                               //Remove the "on" state from all thumbs
			$(this).addClass('thumbOn');                                                      //Add the "on" state to the selected thumb      
			slideNum = $(this).attr('id').split('_');                                     //Find slideNum
			slideNum = slideNum[1];                                                           //Isolate slidenum
			$('.gallery li img').stop().animate({'opacity':0}, 900);                          //Hide all slides
			$('.gallery li').eq(slideNum).find('img').stop().animate({'opacity':1}, 500);     //Show selected slide
			clearInterval(theTime);     
			theTime = setInterval("advance()", 11000);			
		});
		


//END SLIDESHOW PROGRAM


	
	/*banner link hover effect*/
	$('ul#bannerThumbs li img').fadeTo(200,0.4).hover(function(){$(this).fadeTo(200,1)},function(){$(this).fadeTo(200,0.4)});
	
	/*Bing Box Clearer*/
	$('#bingMain input').focus(function() {
	if( this.value == this.defaultValue ) {
		this.value = "";
	}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});

	if($('#feed').length > 0){
	
	var monthArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	$.get('RSSProxy.aspx', function(d) {
		$('#feed').empty();
		//find each 'item' in the file and parse it
		$(d).find('item').each(function(index) {
			
			if(index<3){

			var title = $(this).find('title').text();
			//var creator = $(this).find('dc'	+ '\x3A' + 'creator').text();
			
			
			var link = $(this).find('link').text();
			var description = $(this).find('description').text();
			var pubDate = $(this).find('pubDate').text();
			pubDate = pubDate.split(' ');
			
			var pubMonth;
			var pubDay;
			
			switch(pubDate[2]){
				case 'Jan':
					pubMonth = 'January';
				break;
				case 'Feb':
					pubMonth = 'February';		
				break;
				case 'Mar':
					pubMonth = 'March';
				break;
				case 'Apr':
					pubMonth = 'April';
				break;
				case 'May':
					pubMonth = 'May';
				break;
				case 'Jun':
					pubMonth = 'June';
				break;
				case 'Jul':
					pubMonth = 'July';
				break;
				case 'Aug':
					pubMonth = 'August';
				break;
				case 'Sep':
					pubMonth = 'September';
				break;
				case 'Oct':
					pubMonth = 'October';
				break;
				case 'Nov':
					pubMonth = 'November';
				break;
				case 'Dec':
					pubMonth = 'December';
				break;
			}
			
			switch(pubDate[0]){
				case 'Mon,':
					pubDay = 'Monday';
				break;
				case 'Tue,':
					pubDay = 'Tuesday';		
				break;
				case 'Wed,':
					pubDay = 'Wednesday';
				break;
				case 'Thu,':
					pubDay = 'Thursday';
				break;
				case 'Fri,':
					pubDay = 'Friday';
				break;
				case 'Sat,':
					pubDay = 'Saturday';
				break;
				case 'Sun,':
					pubDay = 'Sunday';
				break;
			}
			

			pubDate = pubDay + ', ' + pubMonth + ' ' + pubDate[1] + ', ' + pubDate[3] /*+ ' | By ' +  creator */;
			
			
			
			
			var html = '';
			
			var div = document.createElement('div');
			var heading = document.createElement('h5');
			var headingLink = document.createElement('a')
			var byline = document.createElement('p')
			var desc = document.createElement('p')
			var more = document.createElement('a')
			
			$(div).addClass('entry');
			$(byline).addClass('byline');
			$(desc).addClass('description');
			$(more).addClass('more');
			$(headingLink).attr('href', link);
			
			$(more).attr('href', link);
			$(more).text('More >>');
			$(headingLink).append(title);
			$(heading).append(headingLink);
			$(byline).append(pubDate);
			
			var concatLength = 650;

			$(description).find('a').each(function(index){
				var thestr = $(this).text();
				if($(this).attr('href')){
					var alength = $(this).attr('href').length * 2;
					alength = alength+22;
					var pre = alength  ;
					var word = $(this).text().length;
					var index = description.indexOf('>'+thestr);
					var tagStart = index - pre;
					var tagEnd = index + word + 5;
				}
				
											
				if(tagStart < 650 && tagEnd > 650){
					
					concatLength = tagEnd;

					
				}
				
			});

			description = description.substring(0, concatLength) + '...';
			$(desc).append(description);
			
			$(div).append(heading).append(byline).append(desc).append(more);
			
			$('#feed').append(div); 
			
						
			}//End If Statement
		});
	});
	}
	
	/*Twitter Getter*/
	$("#tweet").tweet({
            username: 'openatmicrosoft',
            count: 1
        });
	
	function tweetOut(){
		
	}
	
	/*partners hover effect*/
	$('ul#partnersList li').hover(
		function(){
			var thisImg = $('img',this);
			var colorSrc = $(thisImg).attr("src").replace("bw", "color");
			$(thisImg).attr("src", colorSrc);
			$('div', this).fadeIn(150);
			
		},function(){
			var thisImg = $('img',this);
			var bwSrc = $(thisImg).attr("src").replace("color", "bw");
			$(thisImg).attr("src", bwSrc);
			$('div', this).fadeOut(150);
		});
		
		/*loads the projects XML for the different pages*/
		if(document.getElementById('project_details')){
			page = 'detail';
			num = 0;
			getProjects(0,'detail');
		}else if(document.getElementById("projectResults")){
			page = 'projects';
			num = 5;
			getProjects(5, 'projects');
			runSearchCheck();
		}else if(document.getElementById("directory")){
			populateDirectory();
		}else if(document.getElementById("newsModule")){
			getStory('module');
		}

		if($('#highlight').length > 0){	makeHighlight(6);}
		if($('#home .highlight').length > 0){	makeHighlight(3);}

		if(document.getElementById('slideShow')){
			initSlides('#slidesMain', '#slideThumbs', '#slideShow');	
		}
		
		/*Show the captions on the slideshow*/
		$('div#slideShow li').hover(function(){
			if($(this).css('opacity') >.5){							 
				$(this).children('p').stop().animate({top:'-100px'}).animate({paddingTop:'10px', paddingBottom:'10px', top:'-110px'});	
			}	
		},function(){
			$(this).children('p').stop().animate({top:'0px', paddingTop:'0px', paddingBottom:'0px'});	 			 
		});
		
		
		/*Submit from the hightlights page*/
		$('#highlightSearchSubmit').click(function(){
			if( $('#searchForm').val() !== ""){
			window.location.href = 'projects.aspx?q=' + $('#searchForm').val() + '&num=' + projPerPage + '&order=alpha';
			}
			return false;
		});
		
		/*Submit from the projects page*/
		$('#searchSubmit').click(function(){
			if( $('#searchForm').val() !== ""){
				window.location.href = 'projects.aspx?q=' + $('#searchForm').val() + '&num=' + projPerPage + '&order=alpha';
			}
			return false;
		});
		
		$('#searchForm').keyup(function(e) {
		
			if(e.keyCode == 13 && $('#searchForm').val() !== "") {

				window.location.href = 'projects.aspx?q=' + $('#searchForm').val() + '&num=' + projPerPage + '&order=alpha';

				return false;
			}
		});		
		/*SORT BY ALPHABETICAL*/
		$('#sortByAlpha').click(function(){
			//window.location.href = 'projects.aspx?q=' + currentQuery + '&num=' + projPerPage + '&order=' + 'alpha';
			return false;
		});
		
		/*SORT BY DATE*/
		$('#sortByDate').click(function(){
			if(searchOrder == 'dec'){		
				window.location.href = 'projects.aspx?q=' + currentQuery + '&num=' + projPerPage + '&order=' + 'asc';
				ascending = true;
			}else{
				window.location.href = 'projects.aspx?q=' + currentQuery + '&num=' + projPerPage + '&order=' + 'dec';
				ascending = false;
			}
			return false;
		});
		
		/*Sort by new projects*/
		$('#newProj').click(function(){
				window.location.href = 'projects.aspx?q=' + currentQuery + '&num=' + projPerPage + '&order=' + 'dec';
				ascending = false;
		});

		/*Change the amount of projects per page*/
		$('#perPage a').click(function(){
		
		if($(this).text() !== 'all'){
			var newNum = $(this).text();
			window.location.href = 'projects.aspx?q=' + currentQuery + '&num=' + newNum + '&order=' + searchOrder;
		}else{
			window.location.href = 'projects.aspx?q=' + currentQuery + '&num=' + 'all' + '&order=' + searchOrder;
		}
			
			return false;
		});
		
		/*show all projects*/
		$('#showAll').click(function(){
			projPerPage = 9999999999;
			makePages();
			return false;
		});
		
		/*Goto the next results page*/
		$('#nextPage').click(function(){
			nextPage();
			return false;
		});
		
		/*Goto the previous results page*/
		$('#prevPage').click(function(){
			prevPage();
			return false;
		});
		

		
		
});/*end document ready*/





/************************************/
/**********Story Reader**************/
/************************************/
var storyArray = new Array();
var sdArray = new Array();
function getStory(type){
	$.ajax({
		type:"GET",
		url:"xml/stories.xml",
		datatype: "xml",
		async: false,
		success: function(XML){
			var xml = XML;
			var querystring = String(window.location.querystring);
			querystring = querystring.substring(1);
			var found = false;

			$(xml).find('story').each(function(index){
				var title = $('title', this).text();
				var author = $('author', this).text();
				var date = $('date', this).text();
				var content = $('content', this).text();	
				sdArray.push(author);
				storyArray.push(title);
				
				if(type == 'detail'){
					if(querystring == index){
						buildStoryDetail(title, author, date, content, index);
						found = true;
					}
				}else if(type == 'overview'){
					buildStoryOverview(title, author, date, content, index);
				}else if(type == 'module'){
					makeNewsModule(title, author, date, content, index);
				}
				
			});//end each
			
			if(found == false && type == 'detail'){
				buildStoryIndex(true);	
			}
		}//end success
	});
}
function makeNewsModule(title, author, date, content, index){
	var listItem = document.createElement('li');
	var modLink = document.createElement('a');
	$(modLink).attr('href', 'story.aspx?'+index).text(title);
	$(listItem).append(modLink);
	$('#newsModule ul').append(listItem);

}

function buildStoryOverview(title, author, date, content, index){

	var storyDiv = document.createElement('div');
	var storyTitle = document.createElement('h3')
	var titleLink = document.createElement('a');
	var byline = document.createElement('p');
	var authorTag = document.createElement('strong');
	var contentDiv = document.createElement('div');
	$(storyDiv).addClass('story');	
	$(titleLink).text(title).attr('href', 'story.aspx?' + index );
	$(storyTitle).append(titleLink);
	$(authorTag).append(author);
	$(byline).addClass('byline');
	$(byline).append(authorTag).append('<br />' + date);
	content = content.substring(0, 220) + '...';
	$(contentDiv).append(content);
	$(contentDiv).append('<a href="story.aspx?' + index + '">Read More &#187;</a>');
	$(storyDiv).append(storyTitle).append(byline).append(contentDiv);
	$('#storyOverview').append(storyDiv);
}

function buildStoryDetail(title, author, date, content){
		var byline = document.createElement('p');
		var authorTag = document.createElement('strong');
		var contentDiv = document.createElement('div');
		$('#storyTitle').append(title);
		$(authorTag).append(author);
		$(byline).addClass('byline');
		$(byline).append(authorTag).append('<br />' + date);
		$(contentDiv).append(byline).append(content);
		$('#col1').append(contentDiv);
}

function buildStoryIndex(error){
	if(error){
		$('#storyTitle').append('Oops');
		var error = document.createElement('p');
		$(error).append('Sorry, the article you are looking for does not exist or has moved.<br />Please select a story from the list below or visit the <a href="community.aspx">community page</a> to view all current stories');
		$('#col1').append(error);
	}
	for(var i=0; i<storyArray.length; i++){
		var theTitle = document.createElement('p');
		var theLink = document.createElement('a');
		var theDate = document.createElement('span');
		var strongTag = document.createElement('strong');
		
		$(theDate).addClass('byline');
		$(theDate).append(strongTag);
		$(strongTag).append(sdArray[i]);
		$(theLink).append(storyArray[i]).attr('href', 'story.aspx?' + i)
		$(theTitle).append(theDate).append('<br />').append(theLink);
		$('#col1').append(theTitle);
	}

}


/************************************/
/**********TAGCLOUD******************/
/************************************/

/*GET TAGS AND STORE THEM IN AN ARRAY FOR AUTOCOMPLETE*/
var tagList = new Array();
var tagListTotal = new Array();
function storeTags(respObj){
var totalLength = 0;
	$.ajax({
		type:"GET",
		url:"xml/projects.xml",
		datatype: "xml",
		async: false,
		success: function(XML){
			
			var xml = XML;
			var counter = 0;
			var numOfItems = 6;
			$('tag', xml).each(function(index){
				
				var dispIt = true;
				var query = String($(this).text());
				
				for(var p = 0; p<tagList.length; p++){
				    
					if( query == tagList[p]){
						dispIt = false;
					}
				}
				if(dispIt){
					totalLength++;
					tagList.push($(this).text());
				}
				tagListTotal.push($(this).text());
					
				});
			}
		});
	
	/*AutoComplete*/
	if($('#searchForm').length > 0){
		$("#searchForm").autocomplete(tagList, {
			matchContains: true,
			minChars: 0,
			width:190,
			max:5,
			selectFirst: true,
			multiple: false
		});
	}
	
	/*tagCloud Fire*/
	if($('#tagCloud').length>0){
		makeTagCloud(totalLength);
		//listMostCommonTags();
	}
}

function compareNum(a,b){
    return a-b
}

function listMostCommonTags(){
	var arr1 = tagListTotal;
	var count = [];
	var msg = '';

	for (var i = 0; i < arr1.length; i++) {
	if (count[arr1[i]]) {
	count[arr1[i]] += 1;
	
	} else {
	count[arr1[i]] = 1;
	}
	}
	//alert(count);
	arr1.sort();
	//alert(arr1);
	count.sort(compareNum);
	
	for (i in count){
		if(count[i] > 1){
		msg += i + ' occurres ' + count[i] + ' times\n <br />';
	}
	}
	
	$('#tagCloud').append('<p>').append(msg).append('</p>');
	$('#tagCloud').append(count);
	
}

function makeTagCloud(tl){
var holder = document.createElement('div');
$(holder).addClass('tagHolder');
var rndTag = Math.ceil(Math.random()*tl);
	for(var i=0; i<20; i++){
		var tagLink = document.createElement('a');
		if(rndTag+i < tl){
			var tagName = tagList[rndTag + i];
			$(tagLink).text(tagName);
			$(tagLink).attr('href', '#');
			$(tagLink).addClass('tag');
			$(holder).append(tagLink);
			
		}else{
			var tagName = tagList[i];
			$(tagLink).text(tagName);
			$(tagLink).attr('href', '#');
			$(tagLink).addClass('tag');
			$(holder).append(tagLink);
		}
	}
	$('#tagCloud').append(holder);
	
	$('#tagCloud a').click(function(){
	window.location.href = 'projects.aspx?q=' + $(this).text() + '&num=' + projPerPage + '&order=alpha';		
	});
	
	$('#highlights #tagCloud a').click(function(){
	window.location.href = 'projects.aspx?q=' + $(this).text() + '&num=9&order=alpha';		
	});
}

/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/

	
	
/*Get Projects*/
function getProjects(num, page){
	numOfProj = num;
	page = page;
	showProjects();
	storeTags();	
};

/*Master show projects function*/
function showProjects(){
	$.ajax({
		type:"GET",
		url:"xml/projects.xml",
		datatype: "xml",
		async: false,
		success: function(XML){
			var xml = XML;
			var counter = 0;
			var numOfItems = 3;
			$(xml).find('project').each(function(index){
			            	var projName = $(this).attr('title');
			            	var projDate = $(this).attr('initDate');
							var projLink = $(this).attr('mainLink');
			            	var projLogo = $(this).attr('logo');
							projLogo = 'images/project_logos/' + projLogo;
							var projLogo2 = $(this).attr('logo2');
							projLogo2 = 'images/project_logos/' + projLogo2;
			            	var projIndex = index;
							var projDesc = $('description', this).text();

							var tagArray = new Array();
							var projTags = $('tag', this).each(function(){
								var theTag = $(this).text()
								tagArray.push(theTag);
							});
							
			            	var linkArray = new Array()
							var projLinks = $('link', this).each(function(){
								var array = new Array();
								var theLink = $(this).attr('href');
								var theText = $(this).attr('text');
								array.push(theLink);
								array.push(theText)
								linkArray.push(array);
							});

			            	switch(page){
			            	/*case 'home':
					            	makeHomeProj(projName, projDesc, projDate, tagArray, projLogo, linkArray, projIndex);
			            	break;
			            	case 'projects':
					            	makeProj(projName, projDesc, projDate, tagArray, projLogo, linkArray, projIndex);
			            	break;*/
			            	case 'detail':
					            	makeDetailProj(projName, projDesc, projDate, tagArray, projLogo, projLogo2, linkArray, projIndex, projLink);
			            	break;
							}

							
			            });
						
					}
				});
}

/*Home Projects*/
function makeHomeProj (projName, projDesc, projDate, tagArray, projLogo, linkArray, projIndex){
if(projIndex<3){
			projLogo = projLogo.split(',');
	       	var thisDiv = document.createElement('div');
			var thisFooter = document.createElement('div');
			var clearDiv = document.createElement('div');
			var thisHeader = document.createElement('h4');
			var thisDescrip = document.createElement('p');
			var thisImage = document.createElement('img');
			$(thisImage).attr('src', projLogo[0]);
			$(thisImage).attr('alt', projName);
			var thisLink = document.createElement('a');
			$(thisLink).attr('href', 'project-detail.aspx?pid='+ projIndex).text('more').addClass('moreLink');
			$(thisHeader).text(projName);
			$(thisDescrip).text(projDesc.substring(0,130) + '...');
			$(thisFooter).addClass('projectModuleFooter');
			$(clearDiv).addClass('clear');
			$(thisDiv).addClass('projectModule').append(thisHeader).append(thisDescrip).append(thisImage).append(thisLink).append(clearDiv);
			$('#col1').append(thisDiv).append(thisFooter);
			}
}

/*highlighted projects*/
function makeHighlight(num){
	$.ajax({
		type:"GET",
		url:"xml/projects.xml",
		datatype: "xml",
		success: function(XML){
			processHighlights(XML, num);
		}});
		storeTags();
}
function processHighlights(XML, num){
	var xml = XML;
	$(xml).find('project').each(function(index){
		var projName = $(this).attr('title');
		var projDate = $(this).attr('initDate');
		var projLogo = $(this).attr('logo');
		projLogo = 'images/project_logos/' + projLogo;
		var projLogo2 = $(this).attr('logo2');
		projLogo2 = 'images/project_logos/' + projLogo2;
		var projIndex = $(this).attr('id');
		projIndex = Number(projIndex -1);
		var highlight = $(this).attr('highlight');

		var projDesc = $('description', this).text();

		var tagArray = new Array();
		var projTags = $('tag', this).each(function(){
			var theTag = $(this).text()
			tagArray.push(theTag);
		});
		
		var linkArray = new Array()
		var projLinks = $('link', this).each(function(){
			var array = new Array();
			var theLink = $(this).attr('href');
			var theText = $(this).attr('text');
			array.push(theLink);
			array.push(theText)
			linkArray.push(array);
		});
		makeHighlightProj(projName, projDesc, projDate, tagArray, projLogo, linkArray, projIndex, highlight,num);

	});
}
				
var count = 0;
function makeHighlightProj(projName, projDesc, projDate, tagArray, projLogo, linkArray, projIndex, highlight,num){
	//alert(count + ' ' + num + ' ' + count%3);
	
	if(highlight == 'yes' && count < num){
	

		var thisCont = document.createElement('div');							
		var thisDiv = document.createElement('div');
		var clearDiv = document.createElement('div');
		var thisFooter = document.createElement('div');
		var thisHeader = document.createElement('h4');
		var thisDescrip = document.createElement('p');
		var thisImage = document.createElement('img');
		$(thisImage).attr('src', projLogo);
		$(thisImage).attr('alt', projName);
		
		var thisLink = document.createElement('a');
		var titleLink = document.createElement('a');
		var bLink = document.createElement('a');
		$(titleLink).attr('href', 'project-detail.aspx?pid='+ projIndex).text(projName);
		$(thisHeader).append(titleLink);
		$(thisLink).attr('href', 'project-detail.aspx?pid='+ projIndex).text('more').addClass('moreLink');
		$(bLink).attr('href', 'project-detail.aspx?pid='+ projIndex).text(projDesc.substring(0,140) + '...');
		
		$(thisDescrip).append(bLink);
		$(thisFooter).addClass('projectModuleFooter');
		$(thisCont).addClass('projectModuleCont');				
		$(thisCont).append(thisDiv);
		$(clearDiv).addClass('clear');
		$(thisDiv).addClass('projectModule').append(thisHeader).append(thisDescrip).append(thisImage).append(thisLink).append(clearDiv);
		$(thisCont).append(thisFooter);
		$('.highlight').append(thisCont);
		//alert(count);
		if(count%2 >0){  // 2 columns
		//if(count%3 == 2){  // 3 columns
		
		$('.highlight').append('<div class="clear"></div>');
		}
		count++

	}
}

/*Project Search Results*/
function makeProj(projName, projDesc, projDate, tagArray, projLogo, projLogo2, linkArray, projIndex, numOfProj){

			var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
			var dateArray = projDate.split('-');
			var monthNum = Number(dateArray[1]) - 1;
			var dateDisp = dateArray[0];
			var thisImage2;
			var thisDiv = document.createElement('div');
			var thisHeader = document.createElement('h3');
			var thisDescrip = document.createElement('p');
			var initDate = document.createElement('p');
			var tagsP = document.createElement('p');
			var thisImage = document.createElement('img');
			var imgDiv = document.createElement('div');
			var thisLink = document.createElement('a');
			if(projLogo){
				projLogo = projLogo.split(',');
			}
			$(thisLink).attr('href', 'project-detail.aspx?pid='+ projIndex).append(thisHeader).text(projName);
			$(thisHeader).append(thisLink);
			$(thisDescrip).text(projDesc.substring(0,200)+'...');
			if(projLogo){
				$(thisImage).attr('src', 'images/project_logos/'+projLogo[0]);
				$(thisImage).attr('alt', projName);
			}
			$(imgDiv).addClass('projectImages').append(thisImage);
			
				if(projLogo2){
					 thisImage2 = document.createElement('img');
					 $(thisImage2).attr('src', 'images/project_logos/'+projLogo2).attr('alt', projLogo2);
					 $(imgDiv).append(thisImage2);
				}

			$(tagsP).addClass('byline').text('tags: ');
			
			for(var num in tagArray){
				$(tagsP).append(tagArray[num] +', ');
			}
			
			$(tagsP).text($(tagsP).text().substring(0, $(tagsP).text().length -2));
			$(thisDiv).addClass('projectSummary').append(thisHeader).append(imgDiv).append(initDate).append(thisDescrip).append(tagsP);
			$('#searchResults').append(thisDiv);
}
				
				

/*Project Details*/
function makeDetailProj(projName, projDesc, projDate, tagArray, projLogo, projLogo2, linkArray, projIndex, projLink){
	var pId = window.location.toString().substring(window.location.toString().indexOf('?')+5 );
	if(projIndex == pId){
		var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
		var dateArray = projDate.split('-');
		var monthNum = Number(dateArray[1]);
		var dateDisp = dateArray[0];
		
		$('span.currentPage').text(projName);
		$('#projectOverview p').text(projDesc);

		for(var i=0; i<linkArray.length; i++){
			var thisLi = document.createElement('li');
			var thisLink = document.createElement('a');
			var link = linkArray[i];
			$(thisLink).attr('href', link[0]).attr('target','_blank');
			$(thisLink).text(link[1]);
			
			if(link[0] !== ''){
				$(thisLi).append(thisLink);
				$('#additionalInfo ul').append(thisLi);
			}
		}
		for (var i=0; i<tagArray.length; i++){
				
				var tagLink = tagArray[i]
				if(i != tagArray.length -1){
					tagLink += ', ';
				}
				$('#thetags').append(tagLink);
			}

		projLogo = projLogo.split(',');
		var thisDiv = document.createElement('div');
		var thisFooter = document.createElement('div');
		var clearDiv = document.createElement('div');
		var thisHeader = document.createElement('h4');
		var thisDescrip = document.createElement('p');
		if(projLink){
			$('#projectLink').attr('href', projLink).attr('target','_blank');
		}else{
			$('#projectLink').hide();
		}
		var thisImage = document.createElement('img');
			if($(projLogo2).length == 0){
				 thisImage2 = document.createElement('img');
				 $(thisImage2).attr('src', projLogo2).attr('alt', projLogo2);				 
			}

		$(thisImage).attr('src', projLogo[0]);
		$(thisImage).attr('alt', projName);
		var thisLink = document.createElement('a');
		$(thisLink).attr('href', 'project-detail.aspx?pid='+ projIndex).text('more').addClass('moreLink');
		$(thisHeader).text(projName);
		$(thisDescrip).text(projDesc.substring(0,130) + '...');
		$(thisFooter).addClass('projectModuleFooter');
		$(clearDiv).addClass('clear');
		if($(projLogo2).length == 0){$(thisDiv).append(thisImage2);}
	}
}



/********************************************/
/*******************SEARCH*******************/
/********************************************/
/*Find the query strings and set them to vars*/
function runSearchCheck(){
		var querystring = window.location.querystring;
 
		var myValue = querystring["&"];
 
		var qsKeyArray = new Array();
		var qsValueArray = new Array(); 

		for (var key in querystring) {
		    var value = querystring[key];
		    if(value){   
				qsValueArray.push(value);
	   		}
		}
		queryString = qsValueArray[0];
		numPerPage = qsValueArray[1];
		searchOrder = qsValueArray[2];
	
	if(numPerPage == 'all'){
		projPerPage = 9999999;
	}else if(numPerPage == 'undefined'){
		projPerPage = 9;
	}else{
		projPerPage = numPerPage;
	}
		currentQuery = queryString;
	
		updateSearchResults(queryString);
		$('#searchForm').val(queryString);
}

function updateSearchResults(query){
	if( searchOrder == 'alpha' || searchOrder == 'dec' || searchOrder == 'asc' ){	
	$('#searchResults').empty();

		showSearchResults(query);
		$('#pages').empty();
		$('#sortByAlpha').addClass('selected');

	}else if( searchOrder == 'dec'){
			$('#searchResults').empty();

		showSearchResults(query, 'projectsdec');
		$('#pages').empty();
		$('#arrow_img').attr('src', 'images/down_arrow.gif').attr('alt','Descending');
		$('#sortByDate').addClass('selected')
	}else if( searchOrder == 'asc'){
			$('#searchResults').empty();

		showSearchResults(query, 'projectsasc');
		$('#pages').empty();
		$('#arrow_img').attr('src', 'images/up_arrow.gif').attr('alt','Ascending');
		$('#sortByDate').addClass('selected')
	}
}

/*NEW PAGE FUNCTION*/
function newPage(limitLow, limitHigh){
	$('#searchResults').find('.projectSummary').each(function(index){
		if (index<limitHigh && index>=limitLow){
			$(this).show();
		}else{
			$(this).hide();
		}
	});	
	highlightPage();	
}

/*NEXT PAGE FUNCTION*/
function nextPage(){
	var limitLow = Number(startingNum) + Number(projPerPage);
	var limitHigh = Number(startingNum) + Number(projPerPage) + Number(projPerPage);
	
	$('#searchResults').find('.projectSummary').each(function(index){
		if(limitHigh < Number(numOfProj)+Number(projPerPage)){
		startingNum = limitLow;
		highlightPage();
			if (index<limitHigh && index>=limitLow){
				$(this).show();
			}else{
				$(this).hide();
			}
		}
	});
}

/*PREVIOUS PAGE FUNCTION*/
function prevPage(){
	var limitLow = Number(startingNum) - Number(projPerPage);
	var limitHigh = Number(startingNum);	
	
	$('#searchResults').find('.projectSummary').each(function(index){

		if(limitLow >= 0){
		startingNum = limitLow;
		highlightPage();
			if (index<limitHigh && index>=limitLow){
				$(this).show();
			}else{
				$(this).hide();
			}
		}
	});
}

/*SHOW SEARCH RESULTS*/
function showSearchResults(query){

		$.ajax({
		type:"GET",
		url:"xml/projects.xml",
		datatype: "xml",
		async: false,
			success: function(XML){
				numOfProj = 0;
				var xml = XML;
				$(xml).find('project').each(function(index){
							var displayMe = false;
							var projName = $(this).attr('title');
			            	var projDate = $(this).attr('initDate');
			            	var projLogo = $(this).attr('logo');
							
							var projLogo2 = $(this).attr('logo2');
			            	var projIndex = index;
							var projDesc = $('description', this).text();

							var tagArray = new Array();
							var projTags = $('tag', this).each(function(){
								var theTag = $(this).text()
								tagArray.push(theTag);
								if(theTag == query){ displayMe = true;}
								
							});
							
			            	var linkArray = new Array()
							var projLinks = $('link', this).each(function(){
								var array = new Array();
								var theLink = $(this).attr('href');
								var theText = $(this).attr('text');
								array.push(theLink);
								array.push(theText)
								linkArray.push(array);
							});
							if(displayMe){
								numOfProj++;
								makeProj(projName, projDesc, projDate, tagArray, projLogo, projLogo2, linkArray, projIndex, numOfProj);
							}
							});
					}
				});


		$('.pages').hide();
		if(numOfProj > projPerPage){
			makePages();
		};
		
		if(numOfProj == 1){
			$('#numResults').empty().append(numOfProj + ' Result');
		}else{
			$('#numResults').empty().append(numOfProj + ' Results');
		}

		$('#perPage').find('a').each(function(){

		if($(this).text() == projPerPage){
			$(this).addClass('selected');	
			$(this).removeAttr('href');						
		}
		if(projPerPage == 9999999 && $(this).text() == 'all'){
			$(this).addClass('selected');	
			$(this).removeAttr('href');						
		}
		if(numOfProj ==0){      // If no Results
			$('.pages').empty();
			$('.lost').empty();
			$('#blueBar').hide();
			$('#searchResults').append('<p class="lost"><strong>Can&#39;t find what you&#39;re looking for?</strong> Visit the <a href="directory.aspx">Project Directory</a> for a listing of all Open Source projects.</p>');
		//$('#numResults').append('0 results');
		}
		});



}/*END SHOW RESULTS*/


/*MAKE PAGATION ON THE BOTTOM OF THE PAGE IF TOTAL PROJECTS ARE HIGHER THAN PROJECTS/PAGE*/
function makePages(){

	$('#pages').empty()
		for (var p = 0; p<(Math.ceil(numOfProj/projPerPage)); p++){
			var link = document.createElement('a');
			$(link).attr('href', '#');
			if(p ==(Math.ceil(numOfProj/projPerPage)-1)){
				$(link).text(p+1);
			}else{
				$(link).text(p+1);
			}
			$('#searchPages').append(link);
		}
		
		$('#searchPages a').click(function(){
			var pageNum = Number($(this).text())-1;
			startingNum = projPerPage * Number(pageNum);
			newPage(startingNum, Number(startingNum) + Number(projPerPage));
			highlightPage();							
			return false;
			
		});
		newPage(0, projPerPage);
		$('.pages').show();
}


/*HIGHLIGHT (REMOVE CLASS) ON THE PAGE THAT IS CURRENTLY ACTIVE*/
function highlightPage(){
	$('#searchPages').find('a').each(function(){
		if(Number($(this).text())-1 == startingNum/projPerPage){
			$(this).addClass('selected');
		}else{
			$(this).removeClass();
		}
	});
}


/************************************/
/***********Directory****************/
/************************************/
function populateDirectory(){
	GetListItems("Projects", "<Query><OrderBy><FieldRef Name='Title' /></OrderBy></Query>", displayDirectory);
}
function displayDirectory(respObj){
	$.ajax({
		type:"GET",
		url:"xml/projects.xml",
		datatype: "xml",
		async: false,
		success: function(XML){
					var xml = XML;
		$('.directory p').empty();
				var totalProjects = $(xml).find('project').length;
				var colNum = 1;
				
				var numPerCol = Math.ceil((totalProjects)/4);

			$(xml).find('project').each(function(index){


							var projName = $(this).attr('title');
			            	var projIndex = $(this).attr('id');
									            	
		            		var projLi = document.createElement('li');
		            		var projLink = document.createElement('a');
		            		$(projLink).text(projName);
		            		$(projLink).attr('href', 'project-detail.aspx?pid='+ Number(projIndex-1));
		            		$(projLi).append(projLink);
		            		
 		            		if(counter <= numPerCol && counter > 0){$('ul.col1').append(projLi);}
							
							if(counter <= numPerCol*2 && counter > numPerCol){$('ul.col2').append(projLi);}
							
							if(counter <= numPerCol*3 && counter > numPerCol*2){$('ul.col3').append(projLi);}
							
							if(counter <= numPerCol*4 && counter > numPerCol*3){$('ul.col4').append(projLi);}
		            		
		            		counter++;
		            	});
					}
				});
}

/************************************/
/***********SLIDESHOW****************/
/************************************/
function initSlides(slideList, thumbList, container){
		var sl = $(slideList);
		var tl = $(thumbList);
		var cont = $(container);
		var contWidth = $(cont).width()/2;
		var tl_array = $('li', thumbList);
		var sl_array = $('li', slideList);
		
		/*Fade Thumbnails*/
		$('img', tl_array).fadeTo(400, 0.3);
		
		/*set slider width*/
		$(sl_array).each(function(index){
						
		/*set caption width*/
		var capWidth = $(this).children('img').width() - 40 + 'px';
		$(this).children('p').css({'top':'0px','padding':'0px 20px', 'width':capWidth});	 			 

		/*set width*/
		var thisWidth = $(this).outerWidth();
		$(sl).width($(sl).width() + thisWidth);

		/*fadeImgs*/
		$(this).fadeTo(400, 0.3);
});	
		
	/*initialize the thumbnaim click function*/
	moveSlides(1);
		
	/*Add Listener to Thumbnails*/
		$(tl_array).click(function(){moveSlides($(tl_array).index(this))}).hover(function(){$('img', this).stop().fadeTo(200,1);},function(){if($(tl_array).index(this) !== currSlide){$('img', this).stop().fadeTo(200,.3)}});
	/*Add Listener to Left Arrow*/
		$("#leftArrow").click(function(){if(currSlide !== 0){moveSlides(currSlide - 1)}; return false;});
	/*Add Listener to Right Arrrow*/
		$("#rightArrow").click(function(){if(currSlide !== sl_array.length - 1){moveSlides(currSlide + 1)}; return false;});
		
	function moveSlides(thumbIndex){
				for(j=0;j<sl_array.length;j++){
					if(j == thumbIndex){
						$(sl_array[j]).fadeTo(400, 1);
						$(tl_array[j]).find('img').fadeTo(400, 1)
						$(tl_array[j]).addClass('selected');
						var offset = $(sl_array[j]).position().left;
						var thisWidth = $(sl_array[j]).innerWidth()/2;
						var totalOffset = offset - (contWidth - thisWidth);
						$(sl).animate({left:-totalOffset+'px'}, 400);
						
					}else{
						$(sl_array[j]).fadeTo(400, .3);
						$(tl_array[j]).removeClass('selected');
						$('img', tl_array[j]).fadeTo(400, .3)
					}
					currSlide = thumbIndex;
				}
			}
		};



/************************************/
/********QueryStringUtility**********/
/************************************/
window.location.querystring = (function() {
    var collection = {};
    var querystring = window.location.search;
    if (!querystring) {
        return { toString: function() { return ""; } };
    }
    querystring = decodeURI(querystring.substring(1));
    var pairs = querystring.split("&");
    for (var i = 0; i < pairs.length; i++) {
        if (!pairs[i]) {
            continue;
        }
        var seperatorPosition = pairs[i].indexOf("=");
        if (seperatorPosition == -1) {
            collection[pairs[i]] = "";
        }
        else {
            collection[pairs[i].substring(0, seperatorPosition)] 
                = pairs[i].substr(seperatorPosition + 1);
        }
    }
    collection.toString = function() {
        return "?" + querystring;
    };
    return collection;
})();
