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">';
	         if (!hideAuthor) {	out = out + '<span style="font-size:70%;"><a style="color:#333333;" href="' + e.origin.htmlUrl + '">' + e.origin.title + '</a><br /></span>';}
             out = out + '<a style="font-weight:600;" href="' + e.alternate.href + '" target="_blank" title="' +  e.title + '">&raquo; ' + e.title + '</a>';
			//if (e.summary != null) { out = out + '<br />' + e.summary + ''; }
			 out = out + '</p>';
             divx.append(out);
             cnt = cnt + 1;
         }
     });
	//out = '<p class="feedline" ><img src="feed.gif" /> <a style="color:black;" href="http://feeds.feedburner.com/Gpa-djpBildungsabteilung">diesen Feed abbonnieren</a></p>';
	//divx.append(out);
    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);







var __mainDiv;
var __preLoaderHTML;
var __opts;

function __jQueryYouTubeChannelReceiveData(data) {

     var cnt = 0;

     $.each(data.feed.entry, function(i, e) {
         if (cnt < 7) {
            var parts = e.id.$t.split('/');
            var videoId = parts[parts.length-1];
			if(cnt > 0) {
				var out = '';
				if(cnt == 1) {out = out + '<div style="width:170px; margin-top:-2px; text-align:right; float:left;"><a href="http://www.youtube.com/user/gpadjp" title="YouTube Channel"><img src="yt.png" title="YouTube Logo" /></a>&nbsp;</div>';}
				out = out + '<div style="float:left;"><a style="margin-bottom:4px; margin-left:6px;" href="' +  e.link[0].href + '"><img width="76" src="http://i.ytimg.com/vi/' +  videoId + '/2.jpg" /></a></div>';
			} else {
			 	var out = '<div style="width:370px;float:left;"><object width="370" height="230"><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="370" height="230"></embed></object></div><div style="float:left;">';				
			}
         }
          __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: 220,
            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);

