$(function(){ //start jquery
  /*
      Display the most recent titles, dates and provide a link for the most recent items in the conspiracy blog.

      conspiracy blog - http://conspiracymediagroup.wordpress.com/feed/    
  */
  $.getJSON("http://pipes.yahoo.com/pipes/pipe.run?_id=c55bc3a65abf8c1065cf85b0795ffed5&_render=json&_callback=?", function(feed){
    //clear out default error
    $("#show-blog-latest").text("");
    $.each(feed.value.items, function(i,item){
      //set date format
      pubishedDate = new Date(item.pubDate).format('l F j, Y');    
      //add the text for each of the 
      $("#show-blog-latest").append("<div class=\"blog-entry\">\n\t<a target=\"_blank\" href=\""+item.link+"\">\n\t\t<div class=\"date\">"+pubishedDate+"</div>\n\t\t<div class=\"link\">"+item.title+"</div>\n\t</a>\n</div>\n\n");
      //show only for
      if(i == 3){return false;}
    });
  });

  /*
    Open all externals in new window
  */
  $("a").click(function(){
		var myUrl = $(this).attr("href");
		if(myUrl.indexOf("http://") >= 0){
			myPopup = window.open(myUrl, "", '');
			myPopup.focus();
			return false;
		}
	});
  
  
  /*
		Show-expand elements based on the click on a neighbor.
	*/
	//set background on the show link, and hide the text with javascript, this makes the page usable without javascript

	$(".show-link").css("overflow","hidden")
	$(".show-text").css("display","none");
	
	$(".show-text").css("margin",0);
	
	$(".show-link").click(function(){
		if($("body").attr("id") == "who"){
			if($(this).hasClass("expanded")){			
				$(this).parent().parent().children("li").children("h2").removeClass("expanded");
				$(this).parent().parent().children("li").children(".show-text").slideUp("medium");
			}else{
				$(this).parent().parent().children("li").children("h2").removeClass("expanded");
				$(this).parent().parent().children("li").children(".show-text").slideUp("medium");
				
				$(this).addClass("expanded"); //set the class on the clicked item			
				$(this).next().slideDown("medium"); //and turn it on/off based on current state.
			}
		}else{
			if($(this).hasClass("expanded")){			
				$(this).parent().children("h2").removeClass("expanded");
				$(this).parent().children(".show-text").slideUp("medium");
			}else{
				$(this).parent().children("h2").removeClass("expanded");
				$(this).parent().children(".show-text").slideUp("medium");
				
				$(this).addClass("expanded"); //set the class on the clicked item			
				$(this).next().slideDown("medium"); //and turn it on/off based on current state.
			}
		}
	});//close .show-link click event
});//close jquery