﻿//	google.load("gdata", "1.x");
//	google.load("feeds", "1");
	google.load("jquery", "1.4.2");
//    google.load("visualization", "1");

function selectTab(tabid)
{
	$('#tab-menu * span').addClass("tab-navi1")
	$('#tab-menu span').removeClass("tab-navi")
	$('#' + tabid).addClass("tab-navi")
	$('#tab-text').children().hide();
	$('#'+tabid+'_text').show();
//	document.location = "#" + tabid;
};

function parsewritetothem(pcd,div)
{ var url = "proxy.php?url=http%3A//www.writetothem.com/who%3Fpc%3D"+$('#'+pcd)[0].value;
     $("." + div).html("Working...");
     $.get(url,
        function(data,status){
            var heads=$("#repstable th h3",data);
            var bodys=$("#repstable td",data);
            var str="";
            for (var i=0;i<heads.length;i++) {
                str += "<h3>" + heads[i].innerText + "</h3>" + $("p:first",bodys[i])[0].innerText.split(".")[0];
            };
			if (str=="") str = "<h3 style='color:red'>Sorry Post Code Invalid or Not found</h3>";
            $("." + div).html(str);

        }
    )
};

	google.setOnLoadCallback(initOnLoad);

	function initOnLoad() {

	    $("div.context_link").mouseover(function() {
	        $(this).find("div.context_menu").css({ "left": ($(this).offset().left) + "px", "top": $(this).offset().top + "px" });
	        $(this).find("div.context_menu").show();
	    })

	    $("div.context_menu").mouseout(function() {
	        $(this).hide();
	    })

	    var page = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
	    if (page == "") {page = "index.html"}
	    $("a[href$='" + page + "']").click(function() { return false; });
	    $("a[href$='" + page + "']").css("cursor", "default");
	    $("a[href$='" + page + "']").css("background-color", "#369");
	    $("a[href$='" + page + "']").css("color", "#fff");

	};
	function dummy()
	{
	// news
	var feed = new google.feeds.Feed("http://www.conservatives.com/XMLGateway/RSS/News.xml");
	feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
    feed.load(function(result) {
	    if (!result.error) {
	    			var rss=$(result.xmlDocument);
		            strRSS = "";
		            $("rss>channel>item>title:lt(5)",rss).each(function(i) {
						strRSS += "<p><strong><a href='";
		                strRSS += $("rss>channel>item>link:eq(" + i + ")",rss).text();
		                strRSS += "'>";
						strRSS += $(this).text();
						strRSS += "</a></strong><br />";
						strRSS += ($("rss>channel>item>description:eq(" + i + ")",rss).text()).substring(0,200) + "...</p>";
	            		});
			            $("#nationalnews").html(strRSS);
	           		}
           		});
	
	// blogger - news
		var bloggerService = new google.gdata.blogger.BloggerService('GoogleInc-jsguide-1.0');
		var feedUri="http://www.blogger.com/feeds/4285820701456825788/posts/default/-/news?orderby=updated"
		bloggerService.getBlogEntry(feedUri,
			function(entry) {$('#localnews').html("<h3>" + entry.feed.entry[0].title.$t + "</h3>" + entry.feed.entry[0].content.$t);},
			function(error) {alert("error" . error); } )
	// blogger - campaign
		var bloggerService = new google.gdata.blogger.BloggerService('GoogleInc-jsguide-1.0');
		var feedUri="http://www.blogger.com/feeds/4285820701456825788/posts/default/-/campaign?orderby=updated"
		bloggerService.getBlogEntry(feedUri,
			function(entry) {$('#campaignblog').html("<h3>" + entry.feed.entry[0].title.$t + "</h3>" + entry.feed.entry[0].content.$t);},
			function(error) {alert("error" . error); } )
	// twitter
	  var url = "http://twitter.com/statuses/user_timeline/kirby4kt.json?count=3&callback=?"; 
       $.getJSON(url, 
        function(data){
        	$(".twitter").append("<ul/>");
            $.each(data, function(i, item) { 
                $(".twitter ul").append("<li>"
                      + item.text
                      + " <span class='created_at'>"  
                      + item.created_at
                      + " via "  
                      + item.source  
                      + "</span></li>"); 
            }); 
        }); 		
	// twitter2
	  var url = "http://twitter.com/statuses/user_timeline/KempTownCA.json?count=3&callback=?"; 
       $.getJSON(url, 
        function(data){
        	$(".twitter2").append("<ul/>");
            $.each(data, function(i, item) { 
                $(".twitter2 ul").append("<li>"
                      + item.text
                      + " <span class='created_at'>"  
                      + item.created_at
                      + " via "  
                      + item.source  
                      + "</span></li>"); 
            }); 
        }); 		
	// people list
     var feed = new google.feeds.Feed("http://spreadsheets.google.com/feeds/cells/pKHdRlg23traac9RsFYQ0OQ/1/public/basic?range=r1c1:r3c10&return-empty=true");
     // feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
     // feed.includeHistoricalEntries(); // tell the API we want to have old entries too
     feed.setNumEntries(250); // we want a maximum of 250 entries, if they exist
     feed.load( function (result){
         if (!result.error) {
            var str = "<table>";
            for (var i=10; i<30; i+=10) {
                str += "<tr>";
				str += "<td>" + result.feed.entries[i+0].content + " " + result.feed.entries[i+1].content + " " + result.feed.entries[i+2].content + "</td>";
				str += "<td>" + result.feed.entries[i+3].content + "</td>";
				str += "<tr><td colspan=2><hr /><td></tr>"
                str += "</tr>";
            }
            str += "</table>";
            $(".peoplelist").html(str);
        }
        else
            $(".peoplelist").text(result.error.message);
        }
     )



	};

