/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function loadPage()
{

	jQuery("#fotosTabContent").html("");
	jQuery.ajax({
      url: "php/shadowGallery/towndb.php",
      data: "ine="+this.ine + "&page=" + this.page + "&title=" + this.title + "&n_rows=" + this.n_rows + "&n_cols=" + this.n_cols,
      async:false,
      success: function(data) {
			jQuery("#fotosTabContent").html(data);
			Shadowbox.clearCache();			
			Shadowbox.setup();
			jQuery("#resize_wrapper td a img").each(function() {
				jQuery(this).cjObjectScaler({
					method: "fill",
					fade: 800
				});
			});
      }
   });

	jQuery('div.photos_mark').css('height',this.height -36 /*tab height*/ - 35 /*Fotos TabTopBand */ - 20 /*margin*/);
	var widthParent = jQuery('div.photos_mark').css('width');
	var widthParentInt = parseInt(widthParent.substr(0,widthParent.length - 2  ));
	jQuery('div.page_control').css('width',widthParentInt- 44);

}

function loadGallery()
{	
	this.loadPage();
}

function previousPage()
{
   if (this.page > 1)
   {
      this.page--;
   }
   this.loadPage();
}

function nextPage()
{
   this.page++;
	this.loadPage();
}

/*Object constructor*/
function TownGallery(ine,title,width,height)
{
   // declare properties
   this.ine = ine;
   this.title = title;
   this.page = 1;
	this.width = width;
	this.height = height;

	//calculate the number of rows and cols
	var PHOTO_WIDTH = 120;
	var PHOTO_HEIGHT = 120;
	var GAP_WIDTH = 28;
	var GAP_HEIGHT = 20;
	var MARGIN_HEIGHT = 36 /*tab height*/ + 35 /*Fotos TabTopBand */ + 20 /*margin*/ + 40 /*PhotoTitle*/ + 30 /*pageControl*/;
	var MARGIN_WIDTH = 10;


	this.n_cols =  Math.floor((width-MARGIN_WIDTH)/(PHOTO_WIDTH+GAP_WIDTH));
	//this.n_cols =  Math.floor((width- MARGIN_WIDTH) / (PHOTO_WIDTH + GAP_WIDTH ));
   this.n_rows = Math.floor((height - MARGIN_HEIGHT) / (PHOTO_HEIGHT + GAP_HEIGHT + 30 /*Photo description*/ ));


   // declare methods
   this.loadGallery = loadGallery;
   this.nextPage = nextPage;
   this.previousPage = previousPage;
	this.loadPage = loadPage;

}



