function showGallery(gallery_id, single)
{
	$('#gallery').remove();

	//get with ajax
	$.ajax({
		url: url_for_gallery,
		type: 'post',
		data: ({'item_id' : gallery_id, 'single' : single}),
		dataType: 'html',

		success: function(msg){
			$('body').append('<div id="gallery" class="jqmWindow">' + msg + '</div>');

			var myOpen = function(hash){ hash.o.fadeIn(200); hash.w.fadeIn(200); };
			var myClose = function(hash){ hash.o.fadeOut(300); hash.w.fadeOut(500); };

			$('#gallery').jqm({onShow : myOpen, onHide: myClose, overlay: 85});
			$('#gallery').jqmShow();

			$('#gallery .go-next').click(function(e){
				e.preventDefault();

				var current = parseInt($('.img-holder.active').attr('rel'));

				var item = $('.img-holder[rel=' + (current + 1) + ']');
				$('.img-holder.active').removeClass('active');

				if(item.length > 0)
				{
					$(item).addClass('active');
				}
				else
				{
					$('.img-holder[rel=1]').addClass('active');
				}
			});

			$('#gallery .go-prev').click(function(e){
				e.preventDefault();

				var current = parseInt($('.img-holder.active').attr('rel'));

				var item = $('.img-holder[rel=' + (current - 1) + ']');
				$('.img-holder.active').removeClass('active');

				if(item.length > 0)
				{
					$(item).addClass('active');
				}
				else
				{
					$('.img-holder:last').addClass('active');
				}
			});
		}
	});
}

$(document).ready(function(){
    //$(document).pngFix();
    
	$('.reading-items ul li a').mouseover(function(){
		$(this).parent().parent().parent().parent().find('.reading-images a.active').removeClass('active');
		$('.reading-images a[rel=' + $(this).attr('rel') + ']').addClass('active');
	});


	$('.selector a').mouseover(function(){
		$(this).parent().parent().find('.selector a').removeClass('hover');
		$(this).addClass('hover');

		$(this).parent().parent().children('a').removeClass('active');
		$(this).parent().parent().children('a.big[rel=' + $(this).attr('rel') + ']').addClass('active');
	});

	//show gallery
	$('.showGallery').click(function(e){
		e.preventDefault();

        var single = 0;
        if($(this).hasClass('single')) single = 1;

		showGallery($(this).attr('rel'), single);
	});

    //show video
    $('#video-player a').click(function(e){
        e.preventDefault();

        //show ajax
        $.ajax({
            url: $(this).attr('href'),
            type: 'post',
            dataType: 'html',

            success: function(msg){
                //replace
                $('#video-player').html(msg);
            }
        });
    });
});