/**
File Name: gallery.js
Plugin Name: ajaxGallery
Plugin URI: http://www.laciudadx.com/trabajos/ajaxgallery
Description: Ajax + Picasa + Thickbox
Author: Sergio Ceron Figueroa
Version: 2.0
Author URI: http://www.laciudadx.com
Copyright (C) 2007 Sergio Ceron F. (http://laciudadx.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* Inicializa los albums
*/
function initAlbums( root ){
gallery.configs.albums = root;
}
/**
* Clase general
* config: Arreglo de configuraciones
*/
function ajaxgallery( config ){
this.configs = config;
/**
* Muestra las caratulas de los albums publicos
* Cada album al hacer click lleva a las imagenes del mismo
* root: Nodo principal de Picasa (JSON)
*/
this.showAlbums = function(root){
if( root )
this.configs.albums = root;
else
root = this.configs.albums;
var feed = root.feed;
var entries = feed.entry || [];
var pwaFetch = feed.entry.length;
var pwaImageSize = 160; // default image size
var div = document.getElementById( this.configs.id );
var table = this.createTable();
for ( i = 0, r = 0, c = 0; i < pwaFetch ; ++i){
var entry = feed.entry[i];
var title = entry.title.$t;
var jsonImage = entry.media$group.media$content[0].url;
var link = entry.link[1].href;
var tr = table.getElementsByTagName("tr")[ r ];
var td = tr.getElementsByTagName( "td" )[ c ];
// Creamos el html dinamicamente
var vinculo = document.createElement( "a" );
vinculo.setAttribute( "href", "#" + this.configs.id );
vinculo.setAttribute( "onclick", "gallery.loadscript('" + entry.id.$t +"')" );
var image = document.createElement( "img" );
image.src = jsonImage + "?imgmax=" + pwaImageSize + "&crop=1";
image.setAttribute( "class", "ag_wp_img" );
vinculo.appendChild( image );
var titulo = document.createElement( "div" );
titulo.innerHTML = title;
titulo.setAttribute( "class", "ag_wp_title" );
td.appendChild( vinculo );
td.appendChild( titulo );
// Fin del html
if( c == this.configs.cols-1 ){
if( r >= this.configs.rows-1 )break;
r++;
c = 0;
}else{
c++;
}
}
div.innerHTML = div.innerHTML;
// Hide loading messsage
$('#loading_ajaxgallery').hide();
};
/*
* Muestra las imagenes de un album especifico
* La funcion es lanzada automaticamente como callback,
* es por eso que no necesita el nombre o id del album
* root: Nodo principal de Picasa (JSON)
* page: Numero de pagina (Paginación)
*/
this.showAlbum = function( root, page ){
var feed = root.feed;
var entries = feed.entry || [];
var pwaFetch = feed.entry.length;
var pwaImageSize = 160; // default image size
var div = document.getElementById( this.configs.id );
var table = this.createTable();
this.configs.album = root;
this.configs.pag = (page?page:0);
for ( i = this.configs.pag, r = 0, c = 0; i < pwaFetch ; ++i){
var entry = feed.entry[i];
var title = entry.title.$t;
var desc = entry.media$group.media$description.$t;
var jsonImage = entry.media$group.media$content[0].url;
var link = entry.link[1].href;
var tr = table.getElementsByTagName("tr")[ r ];
var td = tr.getElementsByTagName( "td" )[ c ];
var url = jsonImage + "?imgmax=" + 640;
var url2 = jsonImage + "?imgmax=" + pwaImageSize;
// Creamos el html dinamicamente
var vinculo = document.createElement( "a" );
vinculo.setAttribute( "href", url );
vinculo.setAttribute( "title", desc );
vinculo.setAttribute( "class", "thickbox" );
vinculo.setAttribute( "rel", "gallery-album" );
var image = document.createElement( "img" );
image.src = url2;
image.setAttribute( "class", "ag_wp_img" );
vinculo.appendChild( image );
var titulo = document.createElement( "div" );
titulo.setAttribute( "class", "ag_wp_title" );
var linkt = document.createElement( "a" );
linkt.setAttribute( "href", link );
linkt.innerHTML = title;
titulo.appendChild( linkt );
var date = document.createElement( "div" );
date.setAttribute( "class", "ag_wp_date" );
date.innerHTML = entry.updated.$t;
td.appendChild( vinculo );
td.appendChild( titulo );
td.appendChild( date );
// Fin del html
/*td.innerHTML= "";
td.innerHTML+= "