function Pager(tableName, itemsPerPage) {
    this.tableName = tableName;
    this.itemsPerPage = itemsPerPage;
    this.currentPage = 1;
    this.pages = 0;
    this.inited = false;
    
    this.showRecords = function(from, to) {        
        var rows = document.getElementById(tableName).rows;
        // i starts from 1 to skip table header row
        for (var i = 1; i < rows.length; i++) {
            if (i < from || i > to)  
                rows[i].style.display = 'none';
            else
                rows[i].style.display = '';
        }
    }
    
    this.showPage = function(pageNumber) {
    	if (! this.inited) {
    		//alert("not inited");
    		return;
    	}

       
	   var oldPageAnchor = document.getElementById('pg'+this.currentPage);
        oldPageAnchor.className = 'pg-normal';
		        
        this.currentPage = pageNumber;
        var newPageAnchor = document.getElementById('pg'+this.currentPage);
        newPageAnchor.className = 'pg-selected';
        
        var from = (pageNumber - 1) * itemsPerPage + 1;
        var to = from + itemsPerPage - 1;
       // alert(this.currentPage);
	   getElements(this.currentPage);
		this.showRecords(from, to);
    }   
    
    
	//Projects flash files function.
	function getElements(varNum)
  	{
  	 var x=document.getElementsByName("myInput");
	 var flashName=x[varNum].value;
	  var strFlash;
  	 //alert(x[varNum].value);
	 
	 //If there is flash file then dispaly otherwise display image.
	  if((flashName!="") || (flashName!="/"))
	 {
	 
strFlash="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='368' height='183'>";
strFlash=strFlash + "<param name='movie' value='Flexible_Images/videos/"+ flashName +"' />";
strFlash=strFlash + "<param name='quality' value='high' />";
strFlash=strFlash + "<param name='wmode' value='transparent' />";
strFlash=strFlash + "<embed src='Flexible_Images/videos/"+ flashName +"' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' wmode='transparent' width='368' height='183'>";
strFlash=strFlash + "</object>";


	 }
	 
	 /*else  if(flashName=="")
	 {
	   strFlash= "<img src='Flexible_Images/videos/video_3.jpg' alt='' name='slice_03' width='368' height='183' id='slice_03' />"
	  }*/
	  
	 
	 document.getElementById('someid').innerHTML = strFlash;
	 
  	}
	
	
	this.prev = function() {
        if (this.currentPage > 1)
            this.showPage(this.currentPage - 1);
    }
    
    this.next = function() {
        if (this.currentPage < this.pages) {
            this.showPage(this.currentPage + 1);
        }
    }                        
    
    this.init = function() {
        var rows = document.getElementById(tableName).rows;
        var records = (rows.length - 1); 
        this.pages = Math.ceil(records / itemsPerPage);
        
		//If pages are not more than 1 then no need to display the 'Prev or Next' on the page
		if (this.pages > 1)
		{ this.inited = true; }
		
		else
		{ this.inited = false; }
		
		
    }

    this.showPageNav = function(pagerName, positionId) {
    	if (! this.inited) {
    		//alert("not inited");
    		return;
    	}
    	var element = document.getElementById(positionId);
    	
    	var pagerHtml = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" onclick="' + pagerName + '.prev();" class="textprevious">Previous Project</a>&nbsp;&nbsp;&nbsp;&nbsp;';
        for (var page = 1; page <= this.pages; page++) 
            pagerHtml += '<span id="pg' + page + '" class="pg-normal" style="background-color:red;"></span>';
        pagerHtml += '<a href="javascript:void(0)" onclick="'+pagerName+'.next();" class="textnext">Next Project</a>';            
        
        element.innerHTML = pagerHtml;
    }
}

