<!--**START VIDEO GALLERY SCRIPTING**-->

 		$(document).ready(function (){
			
			defaultID = $("#default").attr("title");
			
			
				//check if the page has a hashed value for playing a video
			  	if(window.location.hash) {
			  		
			  	  pageHash = window.location.hash;
			  	  vidID =  pageHash.replace(/[^a-zA-Z 0-9 _ -]+/g,'');
			  	  getYouTubeInfo(vidID);

			  	} //end if
				else
				getYouTubeInfo(defaultID);
				
                $("#thumbnails_div img").click(function(){
					
					var youtubeID = $(this).attr("id");
					window.location.hash = youtubeID;
					
					getYouTubeInfo(youtubeID);
					
					window.scroll(0,150); // horizontal and vertical scroll targets
					
				});
				
				$('#thumbnails_div img').each(function(){
					
					 var ytID = $(this).attr("id");
					
					$.ajax({
						
	                        url: "http://gdata.youtube.com/feeds/api/videos/"+ytID+"?v=2&alt=json",
							context:$(this),
	                        dataType: "jsonp",
	                        success: function (result){ 
							
							var ytTitle = result.entry.title.$t;
							var output = "<div>"+ytTitle+"</div>";
							$(this).parents('td').append(output);
						
						}
						
                		});


				});
        });
	
		
		function getYouTubeInfo(vidID) {

			  	descHash = $("#"+vidID+"").attr("title");
			  	embed = "<object width=\"300\" height=\"255\"><param name=\"movie\" 		value=\"http://www.youtube.com/v/+vidID+&rel=0&autoplay=1\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/"+vidID+"&rel=0&autoplay=1\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"300\" height=\"255\"></embed></object>";
			  	
				$("#show_div").empty();//empty div
				$("#show_div").append(embed);//populate div
				

		
		
                $.ajax({
                        url: "http://gdata.youtube.com/feeds/api/videos/"+vidID+"?v=2&alt=json",
                        dataType: "jsonp",
                        success: function (data) { parseresults(data); }
						
                });

        }

        function parseresults(data) {
                var title = data.entry.title.$t;
                var description = data.entry.media$group.media$description.$t;
                var viewcount = data.entry.yt$statistics.viewCount;
                var author = data.entry.author[0].name.$t;
                $('#title').html(title);
                $('#description').html('<b>Description</b>: ' + description);
                $('#extrainfo').html('<b>Author</b>: ' + author + '<br/><b>Views</b>: ' + viewcount);
                getComments(data.entry.gd$comments.gd$feedLink.href + '&max-results=50&alt=json', 1);
        }

        function getComments(commentsURL, startIndex) {
                $.ajax({
                        url: commentsURL + '&start-index=' + startIndex,
                        dataType: "jsonp",
                        success: function (data) {
                        $.each(data.feed.entry, function(key, val) {
                                $('#comments').append('<br/>Author: ' + val.author[0].name.$t + ', Comment: ' + val.content.$t);
                        });
                        if ($(data.feed.entry).size() == 50) { getComments(commentsURL, startIndex + 50); }
                        }
                });
        } 
		function getImgTitle(ytID){	
				$.ajax({
                        url: "http://gdata.youtube.com/feeds/api/videos/"+ytID+"?v=2&alt=json",
                        dataType: "jsonp",
                        success: function (info) { assignTitle(info); }
						
                });
		}
		
		function assignTitle(info){
			
			var thumbTitle = data.entry.title.$t;
			
			$('#img-title').html(thumbTitle);
		}
		    
		
<!--**END VIDEO GALLERY SCRIPTING**-->

