﻿


// ==========================================================================
/**
 * Class that represents the photoalbum.
 */
var Youtube = Class.create();
Youtube.prototype = {
	uri: null,
	lang: null,	
	initialize: function(u,lang){
		if(u){this.uri = u;}
		if(lang){this.lang = lang;}
	},	
	loadFeed: function(u,lang){	        	
		    window.activeYoutube = this;		    	        
	        $("wait").show();
	        if(u){this.uri = u;}
	        if(lang){this.lang = lang;}
            var headTag = document.getElementsByTagName('head')[0]; 
		    var script = document.createElement("script");
		    script.src = this.buildURL();
		    script.language = "JavaScript";
		    headTag.appendChild(script);	                               
	},	
    buildURL: function(){	        
            var url = "http://gdata.youtube.com/feeds/videos?author=";
            url += this.uri + "&alt=json-in-script&callback=window.activeYoutube.parseFeed&orderby=published";
            //if(this.lang){url += "&hl="+this.lang;}
            return url;         
	},
	parseFeed: function(json){
		this.entries = {};
		e = json.feed.entry;
		for(var i=0;i < e.length;i++){
			this.entries[i] = new Video(e[i]);
		}
		try {
			this.onsuccess(this);
      } catch (e) {}
	},
	onsuccess: function(c){   
	    $('content').innerHTML = "";
	    for(k in c.entries){
            try{
		        var entry = c.entries[k];		    
		        var eventDiv = $('content');
		        var div = document.createElement("div");		    
		        var str = "<div class='title2 pointer' onclick=javascript:$('youtube_content"+k+"').toggle();>" + rep(entry.title) + "</div>";
		        if(entry.content)
			        str += "<div class='youtubeContent' id='youtube_content"+k+"'>" + rep(entry.content) + "</div>";		   
		        div.innerHTML = str;
		        eventDiv.appendChild(div);
		        $("wait").hide();
	        }catch(e){
		        alert(e.description);
	        }
	    }
    }
};



// ==========================================================================
var Video = Class.create();
Video.prototype = {
	title: null,
	content: null,
	initialize: function(entry){
		this.title = entry.title.$t;
		var id = entry.id.$t.substring(38);
		this.content = '<br/><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/'+id+'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+id+'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';		
		this.content += '<br/><br/>'+entry.content.$t+'<br/><br/><br/>';						
	}
};