function YoutubeLoader(){
	this.height;
	this.width;
	this.src;
	this.mobilesrc;
	this.feed;
	this.domEl;
	
	this.currentMovie = 0,
	this.currentMovieTitle = false,
	this.currentMovieTitle = false,
	this.currentMovieUrlRE = new Array();
	
	this.title;
	
	this.setControls = yt_setControls;
	this.slideTitle = yt_slideTitle;
	
	this.__construct = function(){
		var obj = this;
		
		if(typeof(MobileUi) != 'undefined'){
			obj.title = $(".video:last .video-title");
			
			if(!(mobile)){
				$("#"+obj.domEl+" .video-player").html('<iframe scrolling="no" num="0" width="'+obj.width+'" height="'+obj.height+'" src="'+obj.src+'" frameborder="0" allowfullscreen></iframe>');
			}
			else{
				var imgurl = 'http://i.ytimg.com/vi/'+obj.feed[0].url+'/hqdefault.jpg';
				$("#"+obj.domEl+" .video-player").html('<a href="'+obj.mobilesrc+'" title="Play Video"><img src="'+imgurl+'" border="0"/><span></span></a>');
			}
			
			obj.setControls();
		}	
		else{
			var kp3_timeout;
			if(typeof(MobileUi) == 'undefined'){
				kp3_timeout = setTimeout(function(){
					obj.__construct();
				}, 50);
			}
			else{
				clearTimeout(kp3_timeout);
			}
		}
		
	};
}

function yt_setControls(){
	var obj = this;
	var title_timeout;
	
	if($("#"+obj.domEl+" .video-player").parents('#kit').length > 0){
		obj.slideTitle();
	}
	
	$("#"+obj.domEl+" .video-controls .button").live('click', function(){
		clearTimeout(title_timeout);
				
		var domEl = $("#"+obj.domEl+" .video-player");
	
		var prevMovie = obj.currentMovie;
		
		if($(this).is(".next")){
			obj.currentMovie++;	
		}	
		else{
			obj.currentMovie--;
		}
		
		if(obj.currentMovie < 0){
			obj.currentMovie = obj.feed.length - 1;
		}	
		if(obj.currentMovie >= obj.feed.length){
			obj.currentMovie = 0;
		}				
		
		var html = domEl.html();
		obj.currentMovieUrlRE = new Array(new RegExp(obj.feed[prevMovie].url,"g"), obj.feed[obj.currentMovie].url);
		html = html.replace(obj.currentMovieUrlRE[0],obj.currentMovieUrlRE[1]);
		domEl.html(html);
		
		obj.currentMovieTitle = obj.feed[obj.currentMovie].title;
		
		obj.title = $("#"+obj.domEl+" .video-title");;
		obj.title.children('span').html(obj.currentMovieTitle);
		
		if($(this).parents('#kit').length > 0){
			obj.slideTitle();
		}	
	});
	
	
	
}

function yt_slideTitle(){
	var obj = this;
	
	if((typeof(mobile) == 'undefined') || (mobile != true)){
		//open the title:
		obj.title.animate({
			'left': '0px'
		}, 350);
		
		title_timeout = setTimeout(function(){
			var m = obj.title.width();
			obj.title.animate({
				'left': '-'+m+'px'
			}, 350);
		}, 4000);
	}	
}
