function youtubeCollector(){
	this.width = 315;
	this.height = 215;
	this.domObj;
	
	this.currentMovie = 0;

	this.__construct = ytc_construct;
	this.addControls = ytc_addControls;
	this.changeVideo = ytc_changeVideo;
	
	this.insertInto = $(".column");
	this.insertPosition = ':last';
}

function ytc_construct(){
	var obj = this;
	
	obj.currentMovie = Math.floor(Math.random()*youTubeFeed.length);
	
	var link = 'http://www.youtube.com/embed/'+youTubeFeed[obj.currentMovie].url+'/?hl=en&fs=1&showinfo=0&rel=0&controls=0';
	
	var objStr = '<div class="package ytc">'+
				 '<div class="headline"><div class="title"><span>'+youTubeFeed[obj.currentMovie].title+'</span></div></div>'+
				 '<div class="content video player">'+
				 '<iframe width="'+obj.width+'" height="'+obj.height+'" src="'+link+'" frameborder="0" allowfullscreen></iframe>'+
				 '</div></div>';
	
	this.insertInto.children(this.insertPosition).after(objStr);
	
	this.addControls();
}

function ytc_addControls(){
	var obj = this;
	obj.domObj = $(".ytc:last");
	
	
	obj.domObj.find('.headline').after('<div class="controls"><div class="next"></div><div class="previous"></div></div>');
	obj.domObj.find('.controls div').click(function(){
		obj.changeVideo($(this));
		if(typeof(siteTracker) != 'undefined'){
			siteTracker._trackEvent('YouTubeToggle', $(this).attr("class"));
		}
	});
}

function ytc_changeVideo(){	
	var obj = this;
	
	var domEl = obj.domObj.find('.player');

	var prevMovie = obj.currentMovie;
	
	if($(this).is(".next")){
		obj.currentMovie++;	
	}	
	else{
		obj.currentMovie--;
	}
	
	if(obj.currentMovie < 0){
		obj.currentMovie = youTubeFeed.length - 1;
	}	
	if(obj.currentMovie >= youTubeFeed.length){
		obj.currentMovie = 0;
	}				
	
	var html = domEl.html();
	obj.currentMovieUrlRE = new Array(new RegExp(youTubeFeed[prevMovie].url,"g"), youTubeFeed[obj.currentMovie].url);
	html = html.replace(obj.currentMovieUrlRE[0],obj.currentMovieUrlRE[1]);
	domEl.html(html);
	
	obj.currentMovieTitle = youTubeFeed[obj.currentMovie].title;
	obj.domObj.find(".headline .title span").html(obj.currentMovieTitle);
	
}

