$(function(){
       var pic = {"exuberance_1":{"Full_size":"img/photos/exuberance_1.jpg","Thumb":"img/thumbs/Th_exuberance_1.jpg","background":"black","Title":"This is called Exuberance 1","Desc":"<span class='fabric_title'>Exuberance 1</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"},
		"exuberance_2":{"Full_size":"img/photos/exuberance_2.jpg","Thumb":"img/thumbs/Th_exuberance_2.jpg","background":"black","Title":"This is called Exuberance 2","Desc":"<span class='fabric_title'>Exuberance 2</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"},
		"partyexotic_1":{"Full_size":"img/photos/partyexotic_1.jpg","Thumb":"img/thumbs/Th_partyexotic_1.jpg","background":"black","Title":"This is called Party - Exotic","Desc":"<span class='fabric_title'>Party - Exotic</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"},
		"partyred_3":{"Full_size":"img/photos/partyred_3.jpg","Thumb":"img/thumbs/Th_partyred_3.jpg","background":"black","Title":"This is called Party - Red","Desc":"<span class='fabric_title'>Party - Red</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"},
		"partyturquoise_1":{"Full_size":"img/photos/partyturquoise_1.jpg","Thumb":"img/thumbs/Th_partyturquoise_1.jpg","background":"black","Title":"This is called Party - Turquoise","Desc":"<span class='fabric_title'>Party Turquorise</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"},
		"poppy_1":{"Full_size":"img/photos/poppy_1.jpg","Thumb":"img/thumbs/Th_poppy_1.jpg","background":"black","Title":"This is called Poppy","Desc":"<span class='fabric_title'>Poppy</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"},
        "rhythm_1":{"Full_size":"img/photos/rhythm_1.jpg","Thumb":"img/thumbs/Th_rhythm_1.jpg","background":"black","Title":"This is called Rhythm","Desc":"<span class='fabric_title'>Rhythm</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"},
        "silvertwist_1":{"Full_size":"img/photos/silvertwist_1.jpg","Thumb":"img/thumbs/Th_silvertwist_1.jpg","background":"black","Title":"This is called Silver Twist","Desc":"<span class='fabric_title'>Silver Twist</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"},
        "trapeze_1":{"Full_size":"img/photos/trapeze_1.jpg","Thumb":"img/thumbs/Th_trapeze_1.jpg","background":"black","Title":"This is called Trapeze 1","Desc":"<span class='fabric_title'>Trapeze 1</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"},
        "trapeze_2":{"Full_size":"img/photos/trapeze_2.jpg","Thumb":"img/thumbs/Th_trapeze_2.jpg","background":"black","Title":"This is called Trapeze 2","Desc":"<span class='fabric_title'>Trapeze 2</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"},
        "truecolours_1":{"Full_size":"img/photos/truecolours_1.jpg","Thumb":"img/thumbs/Th_truecolours_1.jpg","background":"black","Title":"This is called True Colours","Desc":"<span class='fabric_title'>True Colour</span><span class='fabric_desc'>Description</span><span class='fabric_price'>&pound;95 per meter at 160cm wide.</span><span class='fabric_text'>A wide range of fabric types are available.<br/> E.g. different weight cottons and silks, cotton canvas,cotton velvets,viscose velvets.<br/>All designs can be printed at different scales</span>"}};

function addItem(ul) {
		for (key in pic ) {
			ul += '<li><a href=\"'+ pic[key].Full_size + '\" title=\"'+ pic[key].Title + '\"><img src=\"'+ pic[key].Thumb + '\"></a></li>';
		}
		return ul;
	}

    //add image to the thumbnail list
    var ul_content = $('#gallery').html();
     //$("#desc").html("something in here"+pic.exuberance_1.Title + " is here<br>" + ul_content + " the END");
    ul_content = addItem(ul_content);	
    $('#gallery').html(ul_content);



    $('#gallery li').each(function(idx) {

        $(this).data('index', (++idx));

    });



    $('#gallery').jcarousel({

        scroll: 2,
        visible:2,

        initCallback: initCallbackFunction

    })

    

    function initCallbackFunction(carousel) {

        $('#img').bind('image-loaded',function() {

            var idx =  $('#gallery li.active').data('index') - 2;

            

            carousel.scroll(idx);

            return false;

        });

        

    };



    // load and fade-in thumbnails

    $('#gallery li img').css('opacity', 0).each(function() {    

        if (this.complete || this.readyState == 'complete') { $(this).animate({'opacity': 1}, 300) } 

        else { $(this).load(function() { $(this).animate({'opacity': 1}, 300) }); }

    });



    

    $('#gallery').galleria({

        // #img is the empty div which holds full size images

        insert: '#img',

        

        // enable history plugin

        history: true,

        

        // function fired when the image is displayed

        onImage: function(image, caption, thumb) {        

            // fade in the image 

            image.hide().fadeIn(500);

            

            // animate active thumbnail's opacity to 1, other list elements to 0.6

            thumb.parent().fadeTo(200, 1).siblings().fadeTo(200, 0.6)

            

            // $('#img').data('currentIndex', $li.data('index')).trigger('image-loaded')

            $('#img')
                .hover(
                    function(){ $('#img .caption').stop().animate({height: 50}, 250) },
                    function(){ 
                        if (!$('#show-caption').is(':checked')) {
                            $('#img .caption').stop().animate({height: 0}, 250) 
                        }
                    }
                );
            var currentPic = window.location.hash;
            var filePath = currentPic.match(/(.*)[\/\\]([^\/\\]+)\.\w+$/);
            $("#desc").html(pic[filePath[2]].Desc);



        },

        

        // function similar to onImage, but fired when thumbnail is displayed

        onThumb: function(thumb) {

            var $li = thumb.parent(),

                opacity = $li.is('.active') ? 1 : 0.6;

            

            // hover effects for list elements

            $li.hover(

                function() { $li.fadeTo(200, 1); },

                function() { $li.not('.active').fadeTo(200, opacity); }

            )

        }        

    }).find('li:first').addClass('active') // display first image when Galleria is loaded

    

    $('#img .caption').css('height', 0)

    

    $('#slideshow').hide()

    

    // this one is for Firefox, which loves to leave fields checked after page refresh

    $('#toggle-slideshow, #show-caption').removeAttr('checked')

    

    $('#show-caption').change(function(){

    	if (this.checked) {

    		$('#img .caption').stop().animate({height: 50}, 250)

    	} else {

            $('#img .caption').stop().animate({height: 0}, 250)   

        }

    })



  

});





