/* Powered by Gaetano 'FiR3N3T' Padalino - gaetano<dot>padalino<at>gmail.com */

function show_pictures(tempgallery) {
    galleryArray = tempgallery;
    var while_pictures = 0;

    while (while_pictures < galleryArray.length) {
        var new_anchor = new Element('a', { 'href': galleryArray[while_pictures].replace('_thumb', ''), 'title': 'Santa Tecla Hotel Palace', 'rel': 'lightbox' });

		var new_image = new Element('img', {
		    'src': galleryArray[while_pictures],
		    'id': 'image_' + while_pictures,
		    'title': "Santa Tecla Hotel Palace"
		});


		new_anchor.inject($('inside'));
		new_image.inject(new_anchor);

	    var preload_image = new Element('img', {
	            'src': galleryArray[while_pictures][1],
	            'class': 'hide'
	        });


		preload_image.inject($('container'));
		
		while_pictures++;
}
}
window.addEvent('domready', function() {

    show_pictures(tempgallery);

    var vertical_moves = 0;
    var rows = Math.ceil(galleryArray.length / 3);

    if (rows > 5) {

        $('btn_up').addEvent('click', function(event) {
        if (!$('btn_up').hasClass('deactivated')) {
                vertical_moves--;
                $('btn_down').erase('class');
                $('inside').tween('margin-top', '-' + (62 * vertical_moves) + 'px');
                if (vertical_moves == 0) {
                    $('btn_up').set('class', 'deactivated');
                }
            }
        });


        $('btn_down').addEvent('click', function(event) {
        if (!$('btn_down').hasClass('deactivated')) {
                vertical_moves++;
                $('btn_up').erase('class');
                $('inside').tween('margin-top', '-' + (62 * vertical_moves) + 'px');
                if (vertical_moves == (rows - 5)) {
                    $('btn_down').set('class', 'deactivated');
                }
            }
        });
    } else {
    $('btn_up').set('class', 'deactivated');
    $('btn_down').set('class', 'deactivated');
    }

    var current_id = 1;

    $('left').addEvent('click', function() {
        if (!$('left').hasClass('deactivated')) {
            current_id = $('big_picture').get('class').replace('image_', '');
            current_id--;
            if (current_id > 0);
            {
                $('big_picture').fade('hide');
                $('big_picture').set('src', galleryArray[current_id].replace('_thumb', ''));
                $('big_picture').fade(1);
                $('big_picture').set('class', 'image_' + current_id);
                if (current_id == 0) { $('left').set('class', 'deactivated'); }
                if (current_id == (galleryArray.length - 1)) { $('right').erase('class'); }
            }
        }
    });

    $('right').addEvent('click', function() {
        if (!$('right').hasClass('deactivated')) {
            current_id = $('big_picture').get('class').replace('image_', '');
            current_id++;
            if (current_id > galleryArray.length);
            {
                $('big_picture').fade('hide');
                $('big_picture').set('src', galleryArray[current_id].replace('_thumb', ''));
                $('big_picture').fade(1);
                $('big_picture').set('class', 'image_' + current_id);
                if (current_id == 1) { $('left').erase('class'); }
                if (current_id == galleryArray.length - 1) { $('right').set('class', 'deactivated'); }
            }
        }
    });
});