$(document).ready(function(){
$('.gallItem').click(function(event) {
getGallery($(this).attr('title'),$(this).attr('id'));
});

$('.gallItem').mouseover(function(event) {
$(this).css('cursor','pointer');
});

$('.gallItem').mouseout(function(event) {
$(this).css('cursor','default');
});


$(window).scroll(function() {
$("#bgTrans").height($(document).height());
});

});


function getGallery(galleryTAG,galleryID) {
$('#dispGallery').empty();
$('#dispGallery').addClass('loadingImg');
$.get("script/flickr.php", {tag:galleryTAG,id_galleria:galleryID},function(data){
$('#dispGallery').removeClass('loadingImg');
$('#dispGallery').html(data);

/*force class assignment*/
/* $('.foto').addClass('foto'); */

$('.foto').mouseover(function(event){
$(this).css('cursor','pointer');
});

$('.foto').mouseout(function(event){
$(this).css('cursor','default');
});

$('.foto').click(function(event) {
winWidth = $(window).width();
winHeight = $(document).height();
bgCss = {
'position': 'absolute',
'top': '0px',
'left': '0px',
'background': 'url(img/semi03.png) repeat',
'width': winWidth+'px',
'height': winHeight+'px',
'display':'block'
}

$("#bgTrans").css(bgCss);

fotoShow($(this));
});

}, "html");

}




function fotoShow(triggerImg) {

prevImg = triggerImg.prev('img');
nextImg = triggerImg.next('img');

$('#dispFoto').empty();
$("#dispFoto").css('display','none');

imgFrameYPos = $(document).scrollTop()+50;

loadingFotoCss = {
'position': 'absolute',
//'top': '150px',
'top': imgFrameYPos,
'left': '120px'
}

$("#loadingFoto").css(loadingFotoCss);
$('#loadingFoto').addClass('dispFotoLoading');
$('#loadingFoto').addClass('loadingImg');

imgFrameCss = '';

imgFrameCss = {
'position': 'absolute',
//'top': '150px',
'top': imgFrameYPos,
'left': '120px',
'padding':'1px',
'display':'block'
}

$("#dispFoto").css(imgFrameCss);

$(document.createElement('img')).appendTo('#dispFoto').css({display:'none'}).attr('src',triggerImg.attr('fotourl')+ '?random=' + (new Date()).getTime()).attr('id','IMG'+triggerImg.attr('id'));
$('#IMG'+triggerImg.attr('id')).load(function(event){
$('#loadingFoto').removeClass('loadingImg');
$('#loadingFoto').removeClass('dispFotoLoading');
$('#dispFoto').css('background-color','#3F3F3F');

if (typeof(prevImg.attr('fotourl'))!='undefined') {
$(document.createElement('div')).appendTo('#dispFoto').addClass('lftPlay').attr('id','LFT').html('&lt;');
}

if (typeof(nextImg.attr('fotourl'))!='undefined') {
$(document.createElement('div')).appendTo('#dispFoto').addClass('rghPlay').attr('id','RGH').html('&gt;');
}
$(document.createElement('div')).appendTo('#dispFoto').addClass('clsPlay').attr('id','CLS').html('X');
//$(document.createElement('div')).appendTo('#dispFoto').addClass('clearBoth').attr('id','CLR');
$(document.createElement('p')).appendTo('#dispFoto');

$('.lftPlay, .rghPlay, .clsPlay').mouseover(function(event){
$(this).css('cursor','pointer');
});

$('.lftPlay, .rghPlay, .clsPlay').mouseout(function(event){
$(this).css('cursor','default');
});


$('#LFT').click(function() {
event.stopPropagation();
//prevImg = triggerImg.prev('img');
if (typeof(prevImg.attr('fotourl'))=='undefined') {
return false;
}
else {
fotoShow(prevImg);
}
}); 

$('#RGH').click(function() {
event.stopPropagation();
//nextImg = triggerImg.next('img');
if (typeof(nextImg.attr('fotourl'))=='undefined') {
return false;
}
else {
fotoShow(nextImg);
}

}); 

$('#CLS').click(function() {
closeAll();
});


$(this).slideDown(500);
$(this).mouseover(function(event){
$(this).css('cursor','pointer');
});

});

}

function closeAll() {
$('#dispFoto').empty();
$('#dispFoto').css('display','none');
$('#bgTrans').css('display','none');
}
