$(function() {
		
	function b_test(idx, slide){
		return createPager('big-pager-', 'small-pager-', idx, slide);
    }
	
	function s_test(idx, slide){	
		return createPager('small-pager-', 'big-pager-', idx, slide); 
    }
	
	function createPager(prefix, target, idx, slide) {
		 return $('<a  id="' + prefix + (idx+1) + '" href="#">' + (idx+1) + '  </li>').click(function(event) { 
			 if(event.originalEvent) {
				 $('#' + target + (idx+1)).click(); 
				 return false;
			 }
		 });
	}
	
	var info = $('#big-gallery-info');
	function updateImageInfo() {
		info.html($(this).attr('alt'));		
	}
	
		
	$('#big-slideshow').before('<div id="big-slide-nav-index">').cycle({timeout: 0,  pager:  '#big-slide-nav-index', pagerAnchorBuilder: b_test, before:  updateImageInfo });
	$('#small-slideshow').before('<div id="small-slide-nav-index">').cycle({timeout: 0,  pager:  '#small-slide-nav-index', pagerAnchorBuilder: s_test });	 
		 
	 $(function() {
		 $nav = $('#slideshow-container .slideshow-nav a');
		 $bnav = $('#big-slideshow-container-inner .slideshow-nav a');
		 
		 $('img', $nav)
		  	.mouseover(function() { 
	            var src = $(this).attr("src").match(/[^\.]+/) + "over.png";
	            $(this).attr("src", src);
	        })
	        .mouseout(function() {
	            var src = $(this).attr("src").replace("over", "");
	            $(this).attr("src", src);
	        });
		 
		 $('img', $bnav)
		  	.mouseover(function() { 
	            var src = $(this).attr("src").match(/[^\.]+/) + "over.png";
	            $(this).attr("src", src);
	        })
	        .mouseout(function() {
	            var src = $(this).attr("src").replace("over", "");
	            $(this).attr("src", src);
	        });
		 
		 $nav.click(function () {
			 	$('#small-slideshow').cycle($(this).attr('class'));	
			 	$('#big-slideshow').cycle($(this).attr('class'));	
	        	return false;
	     });
		 
		 $bnav.click(function () {
			 	$('#small-slideshow').cycle($(this).attr('class'));
			 	$('#big-slideshow').cycle($(this).attr('class'));	
	        	return false;
	     });
	       	
	});
	
	 
	 $('#show-large-image').click(function() {		 
		 $('#big-slideshow-dialog').show();
		 var y  =  ($('#big-slideshow-dialog').height()/2) - ($('#big-slideshow-container').height()/2);
		 var x  =  ($('#big-slideshow-dialog').width()/2) - ($('#big-slideshow-container').width()/2);
		 $('#big-slideshow-container').css('margin-top', y + 'px').css('margin-left', x +'px');
		 return false;
	 });	 
	 
	 $('#close-gallery').click(function() {
		 $('#big-slideshow-dialog').hide();
		 return false;
	 });
	 
});


   
