 
	$(document).ready(function() {
		var userID= 'user1873115';
		var subHeadTitle = 'Vimeo Videos';
		var footerLinkText = 'View All Videos';
		var viewAllVideosURL = 'http://vimeo.com/lhmint/videos'; // absolute url of the vimeo file
		var maxVideos = 12;
		var numPerRow = 3;
		var thumbWidth = 105; //px
		var thumbSpacing = 3; //px
		var vimeoHeaderBsckColor = '#005173';
		var vimeoHeaderForeColor = '#ffffff';
		var vimeoThumbsBsckColor = 'transparent';
		var vimeoFooterBsckColor = '#005173';
		var vimeoFooterForeColor = '#ffffff';
		
		
		/* ============================================= */
		/*                 CODE                          */
		 /* ============================================ */
/*		
		var path = top.location.pathname;
		if (document.all) {
		path = path.replace(/\\/g,"/");
		}
		path = path.substr(0,path.lastIndexOf("/")+1);
		//viewAllVideosURL = top.location.protocol + "//" + path + '/vimeo/' +viewAllVideosURL;
		viewAllVideosURL =  path + 'vimeo/' +viewAllVideosURL;
		
		*/
		
		
		var thumbHeight = thumbWidth*2/3;
		var thumbBoxWidth = thumbWidth*numPerRow + thumbSpacing*(numPerRow-1);

		var userInfoURL = 'http://vimeo.com/api/'+userID+'/user_info.json?callback=?';
		var clipsURL = 'http://vimeo.com/api/'+userID+'/clips.json?callback=?';	
			
		// Load Thumbnails
 		$.getJSON(clipsURL,loadClipsData);
		
		// Load User Information
		$.getJSON(userInfoURL,loadUserData);
		
		// Clear html from #vimeo-box
		$('#vimeo-box').html('');
		
		// Add to elements page
		$('#vimeo-box').append('<div id="vimeoHeader"></div>');
		$('#vimeo-box').append('<div id="vimeoThumbs"></div>');
		$('#vimeo-box').append('<div id="vimeoFooter"></div>');		


		// Fix box size and thumbnail spacing
		//$('#vimeo-box').attr('style','width:'+(thumbBoxWidth+4*thumbSpacing)+'px;'); 
		$('#vimeo-box').attr('style','width: 100%;');
		
		//$('#vimeo-box #vimeoHeader', '#vimeo-box #vimeoFooter').width(thumbBox);
		$('#vimeo-box #vimeoHeader').attr('style','background-color: '+vimeoHeaderBsckColor+';'+'color: '+vimeoHeaderForeColor+';');
			$('#vimeo-box #vimeoHeader h3').attr('style','color: '+vimeoHeaderForeColor+';');
			$('#vimeo-box #vimeoHeader vimeoSubhead').attr('style','color: '+vimeoHeaderForeColor+';');
		
		$('#vimeo-box #vimeoFooter').attr('style','background-color: '+vimeoFooterBsckColor+';'+'color: '+vimeoFooterForeColor+';');
		
		
		$('#vimeo-box #vimeoThumbs').attr('style','padding: '+thumbSpacing+'px '+thumbSpacing+'px 0px; margin-top: 0px; margin-bottom: 0px; width: '+thumbBoxWidth +'px; background-color: '+vimeoThumbsBsckColor+';');
		
			

		function loadClipsData(data) {	
			//var feedData = new Array();
			var stringHtml = '';
			var count = 0;
			$(data).each(function(index, itemObj){
				//stringHtml +='<p>hello</p>';
				
				if(count == maxVideos) {
						return;
				}
				stringHtml +=buildGallery(index, itemObj);
					count++;		
				//alert('works: '+itemObj.clip_id );
				
			}); //end each
			$('#vimeo-box #vimeoThumbs').append(stringHtml);
			
			// Build Thumbnail Gaillery
			function buildGallery(i, galleryObj) {
				var strHTML = '';
				var colType = 'col-mid';
				if ((i%numPerRow)==0) {
					colType = 'col-first';
					//alert('works: '+galleryObj.clip_id );
				} else if((i%numPerRow)==(numPerRow-1)) {
				
					colType = 'col-last';
				} else {
					colType = 'col-mid';
				}	
				
				strHTML +='<!-- begin vimeoCell -->';
				strHTML +='<div  style="margin: 0px '+thumbSpacing+'px '+thumbSpacing+'px 0px;" class="vimeoCell '+colType+'">';
					//strHTML +='<a href="'+ galleryObj.thumbnail_small+'" target="_blank">';
						strHTML +='<div class="vimeo_t">';
						strHTML +='<a href="'+galleryObj.url+'?width=500&height=375" title="'+galleryObj.caption +'" alt="'+galleryObj.title +'" rel="prettyPhoto">';
						strHTML +='<img src="'+galleryObj.thumbnail_small+'" title="'+ galleryObj.title+'" alt="'+galleryObj.title +'" width="'+thumbWidth+'" height="'+thumbHeight+'" />'
						strHTML +='</a></div>';
				strHTML +='</div>';
				strHTML +='<!-- end vimeoCell -->';

				return strHTML;
						
			} // end buildGallery
			
			
		// Rollover Effect	
		$('.vimeo_t a img').css('opacity', .66);
		$('#vimeo-box #vimeoThumbs .vimeoCell .vimeo_t').attr('style','background-color: #888;');
		
		   $('.vimeo_t').hover(
			 function () {
     		 	// $(this).find('.f_image a img').css('opacity', 1);
				$(this).find('img').fadeTo('show', 1);
				$(this).stop();
   		     },
			 
			 function () {
     		 	// $(this).find('.f_image a img').css('opacity', .66);
				$(this).find('img').fadeTo('show', 0.66);
				$(this).stop();
   		     }
			);			
	
			// Popup Window to disply Videos
	
			var popupConfig  = {theme:'dark_rounded', autoplay: false};
			popupWin(popupConfig); // Show popup window

			function popupWin(){ $("div.vimeo_t a[rel^='prettyPhoto']").prettyPhoto(popupConfig); }
		

		}//end loadClipsData
		
		function loadUserData(data) {
			//alert('user:'+data.display_name);
			$('#vimeo-box #vimeoHeader').append('<h3>'+data.display_name+'</h3><div id="vimeoSubhead">'+subHeadTitle+'</div>');
			//$('#vimeo-box').append(stringHtml);
			$('#vimeo-box #vimeoFooter').append('<div style="border: 0px solid #fff;width: 125px;height: 15px;padding: 4px 0;margin: 0 auto;"><a href="'+viewAllVideosURL+'" target="_new">'+footerLinkText+'</a></div>');
		}	
		
		
		//$('#vimeo-box').width(vimeoBoxWidth);	
	});// end jquery