function video_overlay(){


var api = jQuery("div.overlay").overlay({oneInstance: false, api: true, effect:'apple', expose:'#FFFFFF', close:'#close'}); 
var next_video;
var previous_video; 

jQuery('div.overlay').click(function(){
	
	//console.log('this has been clicked');
	// var rel_a = jQuery(this).attr('rel');
	// var target_rel = jQuery('#videos').find('a[rel]=' + rel_a);
	// 
	// console.log(target_rel);
	//return false;
	//alert('test');
	
});


jQuery('.ugc_image.youtube a').click(function(){
	
	//*___________________________________
	// Grab the alt tag information and add it to the html
	// var alt_tag = jQuery(this).find('img').attr('alt');
	// var video_info = jQuery('div.overlay').find('#video-info');
	// jQuery(video_info).find('.video-overlay-title').empty();
	// jQuery(video_info).find('.video-overlay-title').text(alt_tag);
	// 
	// //*___________________________________
	// // Setup the URL
	// 
	// var url_1 = "http://www.youtube.com/v/"
	// var url_rel = jQuery(this).attr('rel');
	// var url_2 = "?autoplay=1&hl=en&fs=1&"
	// var url = url_1 + url_rel + url_2;
	// 
	// //*___________________________________
	// // Change the object and param/embed tag attributes to the URL
	// 
	// var object = jQuery('div.overlay').find('object');
	// var param = jQuery(object).find('param');
	// jQuery(param).each(function(i){
	// 	if( jQuery(this).attr('name') == 'movie' )
	// 	{
	// 		jQuery(this).attr('name', url);
	// 	}
	// 	
	// });
	// 
	// var embed = jQuery(object).find('embed');
	// jQuery(embed).attr('src', url);
	

        // var ytplayer = document.getElementById("mainvideo");
        // ytplayer.stopVideo();
	get_next_and_prev_videos(this);
	get_atag_info(this);
	
	//*___________________________________
	// Load the overlay and return false to prevent redirection
	
	if(jQuery(this).parent().next().find('a').attr('class') == 'supporter-a')
	{
		return true;
	}else
{
api.load();
}

	
	

		return false;

	
	
	
	
	
});


jQuery('#sidebar .videos a').click(function(){
	
	//*___________________________________
	// Grab the alt tag information and add it to the html
	// var alt_tag = jQuery(this).find('img').attr('alt');
	// var video_info = jQuery('div.overlay').find('#video-info');
	// jQuery(video_info).find('.video-overlay-title').empty();
	// jQuery(video_info).find('.video-overlay-title').text(alt_tag);
	// 
	// //*___________________________________
	// // Setup the URL
	// 
	// var url_1 = "http://www.youtube.com/v/"
	// var url_rel = jQuery(this).attr('rel');
	// var url_2 = "?autoplay=1&hl=en&fs=1&"
	// var url = url_1 + url_rel + url_2;
	// 
	// //*___________________________________
	// // Change the object and param/embed tag attributes to the URL
	// 
	// var object = jQuery('div.overlay').find('object');
	// var param = jQuery(object).find('param');
	// jQuery(param).each(function(i){
	// 	if( jQuery(this).attr('name') == 'movie' )
	// 	{
	// 		jQuery(this).attr('name', url);
	// 	}
	// 	
	// });
	// 
	// var embed = jQuery(object).find('embed');
	// jQuery(embed).attr('src', url);
	

        // var ytplayer = document.getElementById("mainvideo");
        // ytplayer.stopVideo();
	get_next_and_prev_videos(this);
	get_atag_info(this);
	
	//*___________________________________
	// Load the overlay and return false to prevent redirection
	
	if(jQuery(this).parent().next().find('a').attr('class') == 'supporter-a')
	{
		return true;
	}else
{
api.load();
}

	
	

		return false;

	
	
	
	
	
});


function get_next_and_prev_videos(a_tag)
{
	next_video = jQuery(a_tag).parent().next().find('a').attr('rel');
	previous_video = jQuery(a_tag).parent().prev().find('a').attr('rel');
	
	if(previous_video != undefined)
	{
		jQuery('#video-info').find('.left').css({display:'inline'});
		jQuery('#video-info').find('.left').attr('rel', previous_video);
	}else
	{
		jQuery('#video-info').find('.left').css({display:'none'});
	}
	
	if(next_video != undefined)
	{
		jQuery('#video-info').find('.right').css({display:'inline'});
		jQuery('#video-info').find('.right').attr('rel', next_video);
	}else
	{
		jQuery('#video-info').find('.right').css({display:'none'});
	}
	
}

function get_atag_info(a_tag)
{
	var alt_tag = jQuery(a_tag).parent().find('img').attr('alt');
	var video_info = jQuery('div.overlay').find('#video-info');
	jQuery(video_info).find('.video-overlay-title').empty();
	jQuery(video_info).find('.video-overlay-title').text(alt_tag);
	
	//*___________________________________
	// Setup the URL
	
	var url_1 = "http://www.youtube.com/v/"
	var url_rel = jQuery(a_tag).attr('rel');
	var url_2 = "?autoplay=1&hl=en&fs=1&"
	var url = url_1 + url_rel + url_2;
	
	//*___________________________________
	// Change the object and param/embed tag attributes to the URL
	//change_object(url);
	
	//*___________________________________
	// Load the overlay and return false to prevent redirection

     
          var object_html = '<object width="575" height="380"><param name="movie" value="' + url + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + url + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="575" height="380"></embed></object>';

        jQuery('#object-video').empty();
        jQuery('#object-video').html(object_html);
       

}

function change_object(url)
{
	var object = jQuery('div.overlay').find('object');
	var param = jQuery(object).find('param');
	jQuery(param).each(function(i){
		if( jQuery(this).attr('name') == 'movie' )
		{
			jQuery(this).attr('name', url);
		}
		
	});
	
	var embed = jQuery(object).find('embed');
	jQuery(embed).attr('src', url);
}

}
