var __mainDiv; var __mainDiv2; var __opts;

function __ReceiveData2(data,divx,preloader,items,hideAuthor) {
     var cnt = 0;
     $.each(data.items, function(i, e) {
         if (cnt < items) {
			 var out = '<p class="wdgt">';
			 out = out + '<a style="font-weight:900;" href="' + e.alternate.href + '" target="_blank" title="' +  e.title + '">&raquo; ' + e.title + '</a>';
	         if (!hideAuthor) {	out = out + '<span style="font-size:70%;"><br /><a style="color:#333333;" href="' + e.origin.htmlUrl + '">' + e.origin.title + '</a><br /></span>';}
			 //if (e.summary != null) { out = out + '<br />' + e.summary + ''; }
			 out = out + '</p>';
             divx.append(out);
             cnt = cnt + 1;
         }
     });
    preloader.remove();
    divx.show();
}


(function($) {
    $.fn.googleReaderShared2 = function(options) {
        var readerDiv = $(this); var __mainDivx; var __preLoaderHTML; var hideAuthor;

        $.fn.googleReaderShared2.defaults = {
            readerName: null,
            readerTag: null,
            readerFeed: null,
            hideAuthor: true,
            loadingText: "",
            numberToDisplay: 8
        }

        __opts = $.extend({}, $.fn.googleReaderShared2.defaults, options);
        var items = __opts.numberToDisplay;
		var hideAuthor = __opts.hideAuthor;

        if (__opts.readerName != null) {	
            readerDiv.append("<p id=\"reader_div" +  __opts.readerDIV + "\"></p>");
            __mainDivx = $("#reader_div" +  __opts.readerDIV);
            __mainDivx.hide();
            __preLoaderHTML = $("<p class=\"loader" +  __opts.readerDIV + "\">" + __opts.loadingText + "</p>");
            readerDiv.append(__preLoaderHTML);


            if (__opts.readerTag != null) {
				var urle = "http://www.google.com/reader/public/javascript/user/" +  __opts.readerName + "/label/" + __opts.readerTag + "?callback=?";
		    } else if (__opts.readerFeed != null) {
            	var urle = "http://www.google.com/reader/public/javascript/feed/" +  __opts.readerFeed + "?callback=?";			
			} else { 
            	var urle = "http://www.google.com/reader/public/javascript/user/" +  __opts.readerName + "/state/com.google/broadcast?callback=?";
            }

          	$.getJSON(urle, function(data) { __ReceiveData2(data, __mainDivx, __preLoaderHTML, items, hideAuthor); });
        }
    };
})(jQuery);


function __ReceiveData3(data,divx,preloader,items,hideAuthor,displayItem) {
     var cnt = 0;
     $.each(data.items, function(i, e) {
         if (cnt < items) {
         if (cnt == displayItem) {
			 var out = '<p class="wdgt">';
	         if (!hideAuthor) {	out = out + '<span style="font-size:106%;"><a style="color:#000000; font-weight:900;" href="' + e.origin.htmlUrl + '">' + e.origin.title + '</a><br /></span>';}
             out = out + '<a style="font-weight:600; font-size:24px; line-height:24px; font-weight:900; color:#970f19;" href="' + e.alternate.href + '" target="_blank" title="' +  e.title + '">' + e.title + '</a>';
			 if (e.content != null) { out = out + '<br />' + e.content + ''; }
			 out = out + '</p>';
             divx.append(out);
		     }
             cnt = cnt + 1; 
         }
     });
    preloader.remove();
    divx.show();
}
(function($) {
    $.fn.googleReaderShared3 = function(options) {
        var readerDiv = $(this); var __mainDivx; var __preLoaderHTML; var hideAuthor; var displayItem;

        $.fn.googleReaderShared3.defaults = {
            readerName: null,
            readerTag: null,
            readerFeed: null,
            hideAuthor: true,
            loadingText: "",
			displayItem: 0,
            numberToDisplay: 8
        }

        __opts = $.extend({}, $.fn.googleReaderShared3.defaults, options);
        var items = __opts.numberToDisplay;
		var hideAuthor = __opts.hideAuthor;
		var displayItem = __opts.displayItem;
		
        if (__opts.readerName != null) {	
            readerDiv.append("<p id=\"reader_div" +  __opts.readerDIV + "\"></p>");
            __mainDivx = $("#reader_div" +  __opts.readerDIV);
            __mainDivx.hide();
            __preLoaderHTML = $("<p class=\"loader" +  __opts.readerDIV + "\">" + __opts.loadingText + "</p>");
            readerDiv.append(__preLoaderHTML);

            if (__opts.readerTag != null) {
				var urle = "http://www.google.com/reader/public/javascript/user/" +  __opts.readerName + "/label/" + __opts.readerTag + "?callback=?";
		    } else if (__opts.readerFeed != null) {
            	var urle = "http://www.google.com/reader/public/javascript/feed/" +  __opts.readerFeed + "?callback=?";			
			} else { 
            	var urle = "http://www.google.com/reader/public/javascript/user/" +  __opts.readerName + "/state/com.google/broadcast?callback=?";
            }

          	$.getJSON(urle, function(data) { __ReceiveData3(data, __mainDivx, __preLoaderHTML, items, hideAuthor, displayItem); });
        }
    };
})(jQuery);




var __mainDiv;
var __preLoaderHTML;
var __opts;

function __jQueryYouTubeChannelReceiveData(data) {

     var cnt = 0;

     $.each(data.feed.entry, function(i, e) {
         if (cnt < 8) {
            var parts = e.id.$t.split('/');
            var videoId = parts[parts.length-1];
 			if(cnt > 0) {
				var out = '';
				out = out + '<div style="float:left;"><a style="margin-bottom:4px; margin-top:9px; margin-right:4px;" title="" href="' +  e.link[0].href + '"><img width="81" src="http://i.ytimg.com/vi/' +  videoId + '/1.jpg" /></a></div>';
				if(cnt == 7) {out = out + '<div style="width:100%; margin-top:8px;"><a href="http://www.youtube.com/user/AUGEIUG" title="YouTube Channel">Mehr Videos auf dem AUGE/UG YouTube Channel</a></div>';}
			} else {
			 	var out = '<div style="margin-bottom:12px;"><object width="596" height="477"><param name="movie" value="http://www.youtube.com/v/' + videoId + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + videoId + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="596" height="477"></embed></object></div>';				
			}
         }
          __mainDiv.append(out);
          cnt = cnt + 1;
     });
            
    // Open in new tab?
    if (__opts.linksInNewWindow) {
        $(__mainDiv).find("li > a").attr("target", "_blank");
    }
    
    // Remove the preloader and show the content
    $(__preLoaderHTML).remove();
    __mainDiv.show();
}
                
(function($) {
    $.fn.youTubeChannel = function(options) {
        var videoDiv = $(this);

        $.fn.youTubeChannel.defaults = {
            userName: null,
            channel: "favorites", //options are favorites or uploads
            loadingText: "",
            numberToDisplay: 1,
            linksInNewWindow: true,
			embeddClip: false,
			sizeWidth: 380,
            hideAuthor: false
        }

        __opts = $.extend({}, $.fn.youTubeChannel.defaults, options);

        return this.each(function() {
            if (__opts.userName != null) {
                videoDiv.append("<div id=\"channel_div\"></div>");
                __mainDiv = $("#channel_div");
                __mainDiv.hide();

                __preLoaderHTML = $("<p class=\"loader\">" + 
                    __opts.loadingText + "</p>");
                videoDiv.append(__preLoaderHTML);

                $.ajax({
                    url: "http://gdata.youtube.com/feeds/base/users/" + 
                        __opts.userName + "/" + __opts.channel + "?alt=json",
                    cache: true,
                    dataType: 'jsonp',                    
                    success: __jQueryYouTubeChannelReceiveData
                });
            }
        });
    };
})(jQuery);

