// JavaScript Document

var selected = 0;
var holder;
var iMaxNum = 5;
var sFeedURL = 'http://www.paperdog.co.uk/?feed=atom';


$(document).ready(function(){

$(".tweet").tweet({
            username: "paper_dog",
            join_text: "auto",
            count: 1,
            auto_join_text_default: "Paper Dog said,",
            auto_join_text_ed: "Paper Dog",
            auto_join_text_ing: "Paper Dog is",
            auto_join_text_reply: "Paper Dog replied to",
            auto_join_text_url: "Paper Dog was checking out",
            loading_text: "loading tweets..."
        });
					
$('#contentHide').hide();

$(document).bind("contextmenu",function(e){
        return false;
    });
	
					
if (sFeedURL == undefined)
   return false;

            $.getFeed ({
                url: 'get_rss_feed.php?url=' + escape(sFeedURL),
                success: function(feed) {
                    if (feed != undefined && feed.items) {
                        
                        var iCount = 0;
                        for (var iItemId = 0; iItemId < feed.items.length; iItemId ++) {
                            var item = feed.items[iItemId];
							var RSSFeed;
							var holder;
                            iCount ++;
															
									RSSFeed = "<div class='storyItem'>" + 
													"<h1>" + item.title + "</h1>" + 
													"<div class='rssCont'>" + item.description  + "</div>" + 
													"<a href=" + item.link + ">" + item.category + "/" + item.tag + "</a>" + 
												"</div>";					
														
														
                          $("#rss").append(RSSFeed);
						  
						 

							if ($("#rss .storyItem:last-child .rssCont img").length != 0){
			
							holder = $("#rss .storyItem:last-child .rssCont img").detach();
							$("#rss .storyItem:last-child .rssCont p:first-child").remove();
							
							if ($("#rss .storyItem:last-child .rssCont p").length > 1){
								$("#rss .storyItem:last-child .rssCont p:not(:first-child)").remove();
								$("#rss .storyItem:last-child .rssCont p:first-child").append(".. <br><br><a href=" + item.link + ">read more</a>");
								};
							
							$("#rss .storyItem:last-child .rssCont").prepend(holder);
							
							if ($("#rss .storyItem:last-child .rssCont img").length > 1){
								$("#rss .storyItem:last-child .rssCont img:first-child").css('z-index', '99');
								$("#rss .storyItem:last-child .rssCont img").wrapAll('<div class="slideshow" />');							
								};
								
							};
							
							
								
							  switch(item.category)
							{
								case "comment": 
								$("#rss .storyItem:last-child").css('background-color', '#e50278');
								$("#rss .storyItem:last-child p").css('background-color', '#e50278');
								$("#rss .storyItem:last-child a").css('color', '#ee80b7');
								break;
								case "project":  
								$("#rss .storyItem:last-child").css('background-color', '#f78f1e');
								$("#rss .storyItem:last-child p").css('background-color', '#f78f1e');
								$("#rss .storyItem:last-child a").css('color', '#f7c78a');
								break;
								case "interest":  
								$("#rss .storyItem:last-child").css('background-color', '#ef4035');
								$("#rss .storyItem:last-child p").css('background-color', '#ef4035');
								$("#rss .storyItem:last-child a").css('color', '#f39f96');
								break;
								default:  
								$("#rss .storyItem:last-child").css('background-color', '#9a8c7e');
								$("#rss .storyItem:last-child p").css('background-color', '#9a8c7e');
							};
							
		if (iCount == iMaxNum) break;
                        };

                        
                    };
					$(".storyItem p").hide();
					/*$(".storyItem a").attr('target', '_blank');*/
					
					$("#rss .storyItem:last-child .rssCont img").load(function(){
						$("#rss .storyItem .rssCont .slideshow").cycle(function(){
								$(this).cycle({	fx: 'fade', timeout:300 });
					});
					
					$("#rss .storyItem .rssCont .slideshow").cycle('pause');
						
						
					
					$("#contentHide").fadeIn('slow'); });
					
					
				
                }
            });
			

 


 
   $(".storyItem").live('click', function(event){
		if ($(this).height() == 110){		
			
			if (selected != 0){	
				if (selected.height() == 330){
					selected.animate({'height': '110px'}, {duration: 300});
					selected.find("p").fadeOut({duration: 300});
					selected.find("a").animate({'top': '95px'}, {duration: 300});
					selected.find(".slideshow").cycle('pause');
				}
			}
			selected = $(this);
			$(this).animate({'height': '330px'}, {duration: 300});
			$(this).find("p").fadeIn({duration: 300});
			$(this).find("a").animate({'top': '315px'}, {duration: 300});
			
			$(this).find(".slideshow").cycle('resume');
		
		} else {
			$(this).animate({'height': '110px'}, {duration: 300});
			$(this).find("p").fadeOut({duration: 300});
			$(this).find("a").animate({'top': '95px'}, {duration: 300});
			$(this).find(".slideshow").cycle('pause');

		};
  });
   
 });
 

