
var cs;
var cp;
var fc = "";
function loadBlog (e) {
	dave();

	new Ajax.Request("blog/rss.xml", {method:"GET",onSuccess:showNews, onFailure:fail});
	
}

function showNews(data) {
	var list = data.responseXML.documentElement.firstChild.getElementsByTagName("item");
	
	//addNewsLoop
	for(var i=0; i<3; i++) {
		if(fc=="") {
			fc = (list[i].childNodes[3].textContent)?list[i].childNodes[3].textContent:list[i].childNodes[3].text;	
			
		}
		var newStory = "<div onclick='showNewsLarge(\""
		
		newStory+= (list[i].childNodes[3].textContent)?list[i].childNodes[3].textContent:list[i].childNodes[3].text;
																																				 newStory+="\")' class='content'>";
		newStory+=(list[i].childNodes[3].textContent)?list[i].childNodes[3].textContent:list[i].childNodes[3].text;
		newStory +="</div>"+"<div class='date'>posted on ";
		
		
		var datePre = (list[i].childNodes[1].textContent)?list[i].childNodes[1].textContent:list[i].childNodes[1].text;
					  dateMid = datePre.split(" ",4);
					  var date="";
					  for (var io= 0; io<dateMid.length;io++) {
						  date+=dateMid[io]+" ";
		}
					  
		
		newStory+=date;
		newStory+="</div>"; 
		
		newStory+="<div class='story'>\"";
		
		newStory+=(list[i].childNodes[4].textContent)?list[i].childNodes[4].textContent.substr(0,250).replace(/<br \/>/g, "&nbsp;")+"...\"</div>":list[i].childNodes[4].text.substr(0,250).replace(/<br \/>/g, "&nbsp;")+"...\"</div>";
		
		document.getElementById('miniFeedCont').innerHTML+=newStory;
	}
}

function getContent(title) {
	this.blur();
	cs = title;
	document.getElementById('mainContTitle').innerHTML = "Loading.... ";
	document.getElementById('mainContCont').innerHTML = "";
	new Ajax.Request("content.xml", {method:"GET",onSuccess:showContent, onFailure:fail});
	return false;
}
function fail() {
		alert("anything");
	
}

function showContent(data) {
	this.blur();
	var list = data.responseXML.documentElement.getElementsByTagName("content");
	
	for(var i=0; i<list.length; i++) {
		
		if(list[i].getAttribute('id') == cs) {
			document.getElementById('mainContTitle').innerHTML = list[i].getAttribute('title');
			document.getElementById('mainContCont').innerHTML = (list[i].textContent)?list[i].textContent:list[i].text;
			return;
		}
		
	}
		
}


function showNewsLarge (c) {
	this.blur();
	cp = c;
	
	new Ajax.Request("blog/rss.xml", {method:"GET",onSuccess:handleNewsLarge});	
	document.getElementById('largeNewsTitle').innerHTML = "Loading post...";
}

function handleNewsLarge(data) {
	
	var list = data.responseXML.documentElement.firstChild.getElementsByTagName("item");
	new Effect.Morph("news", {style:"height:400PX;"});
	//addNewsLoop
	//alert(list.length);
	for(var i=0; i<10; i++) {
		var comp = (list[i].childNodes[3].textContent)?list[i].childNodes[3].textContent:list[i].childNodes[3].text;
		if(comp==cp) {
			document.getElementById('largeNewsTitle').innerHTML = 
			(list[i].childNodes[3].textContent)?list[i].childNodes[3].textContent:list[i].childNodes[3].text;
			document.getElementById('largeNewsContent').innerHTML = 
			(list[i].childNodes[4].textContent)?list[i].childNodes[4].textContent:list[i].childNodes[4].text;
			
			var datePre = 
			(list[i].childNodes[1].textContent)?list[i].childNodes[1].textContent:list[i].childNodes[1].text;
			var dateMid = datePre.split(" ",4);
			var date="";
			for (var io= 0; io<dateMid.length;io++) {
				date+=dateMid[io]+" ";
			}
			document.getElementById('largeNewsDate').innerHTML = "posted on "+date;
		}
	}
		
}

function dave() {
	
	new Effect.Morph("news", {style:"height:0PX;"});
	document.getElementById('largeNewsDate').innerHTML = "";
	document.getElementById('largeNewsTitle').innerHTML = "";
	document.getElementById('largeNewsContent').innerHTML = "";
}

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}