Video = function(){
//private vars
var defaults={path:'videoWorx/',
			  pathJson:'json/',
			  pathImages:'images/',
			  pathTemplate:'template/',
			  pageIndex:true,
			  imageInSet:10,
			  currentPage:0,
			  pageSize:9,
			  videoThumbContainer:'#videoThumbContainer',
			  videoBigContainer:'#videoBigContainer'
			}
			
this.videoIndex=new Array();
//things to do when creating an object	
var _this = this;
 
_init = function(){
		   //reads json file
	       readJson = function(data){
						for(i in data.video){
							o=data.video[i];
							o.img="videoWorx/images/"+o.img;
							_this.videoIndex.push(o);
					 	}
			};
	
			jQuery.ajax({
				url: '/videoWorx/json/videos.json',
				dataType: 'json',
				success: readJson,
				async:false
			});
	   }
	   
_init();
	 	
//load current page of video thumbnail		
this.showCurrentPage=function(){
					//get the template
					var _templateVideos=new TemplateReader();
					_templateVideos.read(defaults.path+defaults.pathTemplate+"videoThumb.html","#videoThumbContainer");
					
					chainParams={container:'#VideoThumb',".filenameLink":{href:"/videoWorx/videos/{filename}",title:'{title}'}};
					_data=_this.videoIndex.slice(defaults.currentPage*defaults.pageSize,(defaults.currentPage*defaults.pageSize)+defaults.pageSize);
					_templateVideos.update(_data,defaults.videoThumbContainer,chainParams);
					//check if prev/next page exists
					//alert(defaults.currentPage)
					if(defaults.currentPage < (_data.length-1)){ hasNextPage=false; jQuery(defaults.videoThumbContainer+' .nextThumbs').addClass('disabled'); }else{ hasNextPage=true;  jQuery(defaults.videoThumbContainer+' .nextThumbs').removeClass('disabled');}
					if(defaults.currentPage!=0){ hasPrevPage=true; jQuery(defaults.videoThumbContainer+' .prevThumbs').removeClass('disabled'); }else{ hasPrevPage=false; jQuery(defaults.videoThumbContainer+' .prevThumbs').addClass('disabled'); }
                   }
this.showCurrentPage();


//load next page of the video thumbnail
this.showNextPage=function(){
						if(hasNextPage){
							defaults.currentPage++;
							this.showCurrentPage();
						}
				}

//load previous page of video thumbnail
this.showPrevPage=function(){
						if(hasPrevPage){
							defaults.currentPage--;
							this.showCurrentPage();
						}
               }

//load video player 
this.displayBigVideo=function(videourl){
	if(videourl=="")videourl="/videoWorx/videos/"+_this.videoIndex[0].filename;

		jQuery(defaults.videoBigContainer).html('<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="374">'+
                     '<param name="movie" value="/videoplayer.swf?moviepath='+videourl+'" />'+
					 '<param name="autoplay" value="1" />'+
                      '<param name="quality" value="high" />'+
					  '<param name="wmode" value="opaque" />'+
                      '<param name="swfversion" value="8.0.35.0" />'+
                      <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                      '<param name="expressinstall" value="Scripts/expressInstall.swf" />'+
                      <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                      <!--[if !IE]>-->
                      '<object type="application/x-shockwave-flash" data="/videoplayer.swf?moviepath='+videourl+'" width="480" height="374">'+
                        <!--<![endif]-->
						'<param name="autoplay" value="1" />'+
                        '<param name="quality" value="high" />'+
						 '<param name="wmode" value="opaque" />'+
                        '<param name="swfversion" value="8.0.35.0" />'+
                        '<param name="expressinstall" value="Scripts/expressInstall.swf" />'+
                        <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                        '<div>'+
                          '<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>'+
                          '<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>'+
                        '</div>'+
                        <!--[if !IE]>-->
                      '</object>'+
                      <!--<![endif]-->
                    '</object>')
	}
// convert first letter to uppercase	
function UCFirst(str){
   // split string
   firstChar = str.substring(0,1);
   remainChar = str.substring(1);

   // convert case
   firstChar = firstChar.toUpperCase(); 
   remainChar = remainChar.toLowerCase();

   return firstChar + remainChar

}
	
//display video title
this.displayVideoTitle=function(url){

		for(i=0;i<this.videoIndex.length;i++){
			if(url.indexOf(this.videoIndex[i].filename)>0){
				jQuery('#titleForVideo').html(UCFirst(this.videoIndex[i].title))
			}
		}
	}
	
	

jQuery(defaults.videoThumbContainer+ " a.filenameLink").live('click', function() {
  			jQuery(defaults.videoThumbContainer+ " a.filenameLink img").removeClass('selected')
			jQuery(defaults.videoThumbContainer+ " a.filenameLink").parent().removeClass('selected')
			_this.displayBigVideo(this.href)
			//_this.displayVideoTitle(this.href)
			jQuery('#titleForVideo').html(this.title)
			jQuery(this).addClass('selected')
			jQuery(this).parent().addClass('selected')
			return false;
		});

//add events to next and previous link
jQuery(defaults.videoThumbContainer+' .prevThumbs').live('click', function(event) {
																				
  			_this.showPrevPage();
		});
		
jQuery(defaults.videoThumbContainer+' .nextThumbs').live('click', function(event) {
																					
  			_this.showNextPage();
		});
}