/**
*
*/
var alertTimerId = 0;
$(document).ready(function() {
var current_slide = $('#gallery a').length;
slideShow(current_slide);
$('#gallery').hover(
function(){
//$("#gallery .caption").css("background","#e4007f");
//clearTimeout(alertTimerId);
if(current_slide>1) clearTimeout(alertTimerId);
},function(){
//$("#gallery .caption").css("background","#000");
//alertTimerId = setInterval('gallery()',10000);
if(current_slide>1) alertTimerId = setInterval('gallery()',10000);
});
if(current_slide<=1){
$('#gallery .content table tr td:eq(3)').hide();
$('#gallery .content table tr td:eq(1)').hide();
}
$('#gallery .content table tr td:eq(3)').click(function(){
clearTimeout(alertTimerId);
gallery();
}).hover(
function(){ $(this).css("background","url('../new_include/images/arrow_right_o.png') no-repeat"); },
function(){ $(this).css("background","url('../new_include/images/arrow_right.png') no-repeat"); }
);
$('#gallery .content table tr td:eq(1)').click(function(){
clearTimeout(alertTimerId);
gallery_back();
}).hover(
function(){ $(this).css("background","url('../new_include/images/arrow_left_o.png') no-repeat"); },
function(){ $(this).css("background","url('../new_include/images/arrow_left.png') no-repeat"); }
);
});
function slideShow(current_slide) {
//Set the opacity of all images to 0
$('#gallery a').css({opacity: 0.0});
//Get the first image and display it (set it to full opacity)
$('#gallery a:first').css({opacity: 1.0});
//Set the caption background to semi-transparent
$('#gallery .caption').css({opacity: 0.9});
//Resize the width of the caption according to the image width
$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
var total = $('#gallery a').length;
//Get the caption of the first image from REL attribute and display it
//$('#gallery .content').html("<table border='0' width='100%'><tr><td>" + $('#gallery a:first').find('img').attr('rel') + "</td><td width='150'><a href='#'>上一頁</a>1/" + total + "<a href='#'>下一頁</a></td></tr></table>")
$('#gallery .content table tr td:eq(0)').html($('#gallery a:first').find('img').attr('rel'));
$('#gallery .content table tr td:eq(2)').html("1/" + total);
$('#gallery .content').animate({opacity: 0.9}, 400);
//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
//alertTimerId = setInterval('gallery()',10000);
if(current_slide>1){
alertTimerId = setInterval('gallery()',	10000);
}
}
function gallery() {
//if no IMGs have the show class, grab the first image
var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));
var total = $('#gallery a').length;
//Get next image caption
var caption = next.find('img').attr('rel');
var caption2 = ($('#gallery a').index(next) + 1) + "/" + total ;
//Set the fade in effect for the next image, show class has higher z-index
next.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);
//Hide the current image
current.animate({opacity: 0.0}, 1000)
.removeClass('show');
//Set the opacity to 0 and height to 1px
$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:50 }).animate({height: '1px'}, { queue:true, duration:300 });
//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
$('#gallery .caption').animate({opacity: 0.9},100 ).animate({height: '42px'},500 );
//Display the content
$('#gallery .content table tr td:eq(0)').html(caption);
$('#gallery .content table tr td:eq(2)').html(caption2);
//$('#gallery .content').html(caption);
}
function gallery_back() {
//if no IMGs have the show class, grab the first image
var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var prev = ((current.prev().length) ? ((current.prev().hasClass('caption'))? $('#gallery a:last') :current.prev()) : $('#gallery a:last'));
var total = $('#gallery a').length;
//Get next image caption
var caption = prev.find('img').attr('rel');
var caption2 = ($('#gallery a').index(prev) + 1) + "/" + total ;
//Set the fade in effect for the next image, show class has higher z-index
prev.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);
//Hide the current image
current.animate({opacity: 0.0}, 1000)
.removeClass('show');
//Set the opacity to 0 and height to 1px
$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:50 }).animate({height: '1px'}, { queue:true, duration:300 });
//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
$('#gallery .caption').animate({opacity: 0.9},100 ).animate({height: '42px'},500 );
//Display the content
$('#gallery .content table tr td:eq(0)').html(caption);
$('#gallery .content table tr td:eq(2)').html(caption2);
//$('#gallery .content').html(caption);
}

