
   /*
    * Author: Karl O'Leary
    * Company: Emagine Media, http://www.emagine.ie
    * Description: Specific logic for site
    *
    * Updated:
	* - 20091012.1252, Karl, adjusted the slideshow to handle the 3 images sizes
    * - 20090915.1154, Karl, created
    */

    var count = 0;
    var current_i = 0;
    var google_map = null;

   /*
    * On load code.
    */
    $(document).ready(function() {	        
        $('*').pngFix();

        // lightbox stuff
        $('a.lightbox').lightBox({
			overlayBgColor: '#0C3B43',
			overlayOpacity: 0.85,
			imageLoading: '/graphics/loadingAnimation.gif',
			imageBtnClose: '/graphics/lightbox-btn-close.gif',
			imageBtnPrev: '/graphics/lightbox-btn-prev.gif',
			imageBtnNext: '/graphics/lightbox-btn-next.gif',
			containerResizeSpeed: 350,
			txtImage: 'Image',
			txtOf: 'of'
		});     
       
        // gallery slideshow stuff
		$("#thumbnails a.page1").bind("click", function() { $('div.pages').scrollTo("ul.page1", 1500); });		
		$("#thumbnails a.page2").bind("click", function() { $('div.pages').scrollTo("ul.page2", 1500); });		
		$("#thumbnails a.page3").bind("click", function() { $('div.pages').scrollTo("ul.page3", 1500); });

        $("#thumbnails .images_list a").bind("click", function() {
            var src_current = $("img", this).attr("src");
            var src_guess = "";
            var i=1;           
            var pos = $(this).parent().attr("class");
            transition(pos);
            return false;
		});


        // sub text right slideshow
		// - the a.rel attribute holds the large format image
		// - the li a.href hold the path to the intermediate image size
        $(".slideshow_images a").bind("click", function() {            			
			var src_main = $(this).attr("rel");			
			var src_mini = $(this).attr("href");	
            var caption = $(this).attr("title");
            transition_new(src_main, src_mini, caption);
            return false;
		});

        // google map stuff
        google_map = googleMapsLoad("google_map", 52.259713, -7.107, 16);
        googleMapsAddMarker(google_map, 52.259713, -7.107, '<img src="/graphics/map_thumbnail.jpg"/>');        
    });

    /*
     * On close code.
     */
    $(window).unload(function () {
        googleMapsUnload();
    });


    function transition_new(src_main, src_mini, caption) {
        $(".slideshow_main_image").attr("title", caption);
        $(".slideshow_main_image").attr("href", src_main);
        $(".slideshow_main_image span").text(caption);
        $(".slideshow_main_image img").attr("alt", caption);
        $(".slideshow_main_image img").attr("title", caption);
		$(".slideshow_main_image img").attr("src", src_mini);
    }


    function transition(to_i) {	
        var src = $("#thumbnails li."+to_i+" a").attr("href");
		var caption = $("#thumbnails li."+to_i+" a").attr("title");
	
		//alert("src = "+src);
		$("#thumbnails li").removeClass("current");
		$("#thumbnails li."+to_i).addClass("current");
		$("#slideshow .main_image").attr("src", src);
        $("#slideshow .main_image").attr("alt", caption);
        $("#slideshow .main_image").attr("title", caption);
		$("#slideshow .caption span").text(caption);
		current_i = to_i;
    }

    function get_next_i() {
        if (current_i==count)
            return 1;
		else
            return current_i+1;
    }

    function get_previous_i() {
        if (current_i==1)
            return count;
		else
            return current_i-1;
    }

