﻿var rssTxt = "";
//alert(typeof rssURL);
if (!rssURL || typeof rssURL == "undefined" || typeof rssURL == null){
var rssURL="../press_and_publications/current_events.xml";
}



var eventsPage=false;
var eventsList="";
var feedList="";
$(document).ready(function() {
	
	
	if ( $("#fixedFloat").length!=0 ){
		
		//alert('');
		var msie6 = $.browser == 'msie' && $.browser.version < 7;
	  
		  if (!msie6) {
			
			var varoffSet = $('#fixedFloat').offset();
			
			var theTop = varoffSet.top - parseFloat($('#fixedFloat').css('margin-top').replace(/auto/, 20));
			
			$(window).scroll(function (event) {
			  // what the y position of the scroll is
			  var y = $(this).scrollTop();
			  
			  // whether that's below the form
			  if (y >= theTop) {
				// if so, ad the fixed class
				$('#fixedFloat').addClass('fixed');
			  } else {
				// otherwise remove it
				$('#fixedFloat').removeClass('fixed');
			  }
			});
		  }  
	
	}
	
	
	
	if ( getUrlVars()["tab"] ){
		
		$("#copyArea").css("display", "none");
		loadPage(getUrlVars()["tab"]);
		if ( getUrlVars()["tabIdx"] ){
			$("#secondaryNav .inlineNav li").removeClass("on");
			$("#secondaryNav .inlineNav li:eq("+getUrlVars()["tabIdx"]+")").addClass("on");
			updateTitle("Process Metrix-About Us-", $("#secondaryNav .inlineNav li:eq("+getUrlVars()["tabIdx"]+") a").attr("title") )
		}
	}
	
	
	
	
	$("a.disabled").click(function(e) {
		e.preventDefault();
	});
	
	$("a.ajaxLink").click(function(e) {
		e.preventDefault();
		loadPage($(this).attr("href"));
		window.location.hash="?tab="+$(this).attr("href");
	});
	
	$(".secondaryNavAbout .inlineNav li a").click(function(e) {
		e.preventDefault();
		$("#secondaryNav .inlineNav li").removeClass("on");
		$(this).parent().addClass("on");
		$(this).blur();
		loadPage($(this).attr("href"));
		var index=$(".secondaryNavAbout .inlineNav li").index($(this).parent());		
		window.location.hash="?tab="+$(this).attr("href")+"&tabIdx="+index;
		updateTitle("Process Metrix-About Us-", $(this).attr("title"));
	});


	$("a.rssLink").hover(
		function () {
			rssTxt  = $(this).text();
			$(this).text("RSS Subscribe");
		}, 
		function () {
			$(this).text(rssTxt);
		}
	);
	
	if($("#press_and_pub ul#eventsList").length!=0){eventsPage=true;}
	
	$.get(rssURL, function(xml){ 
		
		var theRSS = $.xml2json(xml);
		$(theRSS.channel.item, xml).each(function(i){
		
			if (eventsPage){
				updateEventsList(this.guid, this.category, this.title, this.description);				
			}
			
			if (i<=2){
				var feed=this.category + " / " + this.title + "..."
				updateFeedList(i+1, this.link, feed);
			}
			
		});
		
		$("#press_and_pub ul#eventsList").html(eventsList);
		$("#rssFeedContent ul").html(feedList);
	});	
});

$(window).load(function() {
	adjustHeight();	
});

function loadPage(url){
	//$("#copyArea").load(url+' #copyArea');
	//alert(url);
	$('#mainColumn').load(url+' #copyArea', function() {
	  adjustHeight();
	  $("#copyArea").css("display", "block");
		$("a.ajaxLink").click(function(e) {
			e.preventDefault();
			loadPage($(this).attr("href"));
			window.location.hash="?tab="+$(this).attr("href");
		});
		
	});
	
}

function adjustHeight(){
	var sideColHeight = $("#sideColumn").height();
	var mainColHeight = $("#mainColumn").height();
	$("#sideColumn").css("height", mainColHeight);
}	
function updateEventsList(theGuid, theCategory, theTitle, theDesc){
	eventsList += 	"<li style=\"background:url("+theGuid+") no-repeat;\">";
	eventsList += 	"	<span class=\"date\">"+theCategory+"</span>";
	eventsList += 	"	<span class=\"title\">"+theTitle+"</span>";
	eventsList += 	"	<span class=\"desc\">"+theDesc+"</span>";
	eventsList += 	"</li>";
}

function updateFeedList(idx, theLink, theFeed){
	feedList += "<li class=\"feed"+idx+"\"><a href=\""+theLink+"\">"+theFeed+"</a></li>";
}

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function updateTitle(prefix, titleAttr){
	document.title=prefix+titleAttr;
}
