function mycarousel_initCallback(carousel){
       // Disable autoscrolling if the user clicks the prev or next button.
       carousel.buttonNext.bind('click', function() {carousel.startAuto(0);});
       carousel.buttonPrev.bind('click', function() {carousel.startAuto(0);});
       // Pause autoscrolling if the user moves with the cursor over the clip.
       carousel.clip.hover(function() {carousel.stopAuto();}, function() {carousel.startAuto();});
};  


$(document).ready(function(){
	
	/* load images ends */
	
	$("span#updater").html("0000 : 000");
	
	$('#viewer').mousemove(function(e){
		$("span#updater").html(e.pageX +' : '+ e.pageY);
	});
	
	/* height */
	
	/* toolbar functions */
	$('#slide').addClass("selected");
	
	$('#toolbar_ico').find('li').click(function(){
		$('#toolbar_ico').find('li').removeClass("selected");
		$(this).addClass("selected");	
	});
	
	
	$('#slide').click(function(){
		$('#list_app').css({'display':'none'});
		$('#slide_app').fadeIn();
		
		$('#title').html($('#slide_app').find('li.selected').find('input.title').val());
		$('#caption').html($('#slide_app').find('li.selected').find('input.service').val());
	});
	$('#list').click(function(){
		$('#list_app').fadeIn();
		$('#slide_app').css({'display':'none'});
		
		$('#title').html($('#list_app').find('li.selected').find('input.title').val());
		$('#caption').html($('#list_app').find('li.selected').find('input.service').val());
		
		$('#loader').css({'min-height' : $('#menu_list').height() - 20});

	});
	
	/* scroll effect */
	$('.imgControls').css({'opacity' : '0'});
	$('.bottomControl').mouseenter(
		function(){
			$('#img_div').find('img').animate({'top' : '-385px'}, 1500).delay(3000).animate({'top' : '0'}, 1500);
			$(this).css({'backgroundColor' : '#fff'});
		}).mouseleave(function(){
			$(this).animate({'opacity':'0'});
		}
	);
	$('.topControl').mouseenter(
		function(){
			$('#img_div').find('img').animate({'top' : '0'}, 1500);
			$(this).css({'backgroundColor' : '#fff'});
			
	}).mouseleave(function(){
		$(this).animate({'opacity':'0'});
		}

	);
	$('#viewer').mouseleave(function(){
		$('#img_div').find('img').animate({'top' : '0'}, 1500);
	});
	
	$('#img_div li').mouseenter(function(){
		$(this).find('.info').animate({top : '230px'}, 1000, 'easeOutBack');
	}).mouseleave(function(){
		$(this).find('.info').animate({top : '400px'}, 1000, 'easeOutBack');
	});
	
	/* thumb action */
	
	$('#menu li').hover(
    	function(){
    		if($(this).attr('class') != 'selected'){
    			$(this).animate({top : '-=10px' }, 'slow', 'easeOutBack');
    		}
    	},
    	function(){
    		if($(this).attr('class') != 'selected'){
    			$(this).animate({top : '+=10px' }, 'slow', 'easeOutBack');
    		}else{
    			$(this).animate({top : '0px' }, 'slow', 'easeOutBack');
    		}
    	}
    );
    $('ul#img_div li:first .info').stop(true, true).delay(2000).animate({top : '230px'}, 1000, 'easeOutBack').delay(5000).animate({top : '400px'}, 1000, 'easeOutBack');
	
	$('#menu li').click(function(){
		$('ul#img_div li').find('.info').stop(true, true).css({'top' : '400px'});
		$('ul#img_div').stop(true, true).animate({'left' : '-' + $('#'+$(this).find('input.id').val()).position().left + 'px'}, 1400, 'easeOutBack', function(){
			$(this).find('li .info').stop(true, true).delay(1000).animate({top : '230px'}, 1000, 'easeOutBack',function(){
				$(this).delay(5000).animate({top : '400px'}, 1000, 'easeOutBack');
			});
		});
		$('#title').html($(this).find('input.title').val());
		$('#caption').html($(this).find('input.credit').val());
		$('#menu li').removeClass('selected');
		$(this).addClass('selected');
	});

	
	/* tooltip functions start */
	
	var distance = 10;
    var time = 250;
    var hideDelay = 500;

    var hideDelayTimer = null;
	$('.tooltip_wrap').css('opacity', 0);
    var beingShown = false;
    var shown = false;
    
    $("#menu").find("li").mouseover(function(){
    	if(hideDelayTimer) clearTimeout(hideDelayTimer);
    	
    	if (beingShown || shown) {
        	return;
      	} else {
        	beingShown = true;
        	$('.tooltip_wrap').css({
          		top: '-37px',
          		left: $(this).position().left,
          		display: 'block'
       	 	})
        
        	.animate({
          		top: '-=' + distance + 'px',
          		opacity: 1
        	}, time, 'swing', function() {
          		beingShown = false;
          		shown = true;
        	}).html($(this).find('img').attr('alt'));
    	}	
    }).mouseout(function () {
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        $('.tooltip_wrap').animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, 0, 'swing', function () {
          shown = false;
          $('.tooltip_wrap').css('display', 'none');
        });
      }, 0);
    
    });
    
    /* tooltip functions end */
    
    function initCarousel(object, numScroll, isWrap){$(object).jcarousel({ wrap: isWrap , initCallback: mycarousel_initCallback, scroll: numScroll });}
    $('#img_div li').css({'display':'block'});
    initCarousel('#img_div', 1, 'last');
    
    
    /* list app */
    $('#menu_list li:first-child').addClass('selected');
    
    $('#menu_list li').click(function(){
    	$('#menu_list li').removeClass('selected');
    	$(this).addClass('selected');
    	$('#loader').html('<img src="'+ $(this).find('input.url').val() +'" alt="" />');
    	$('#loader').find('img').css({'display' : 'none'});
    	$('#loader').find('img').fadeIn();
    	$('#title').html($(this).find('input.title').val());
		$('#caption').html($(this).find('input.credit').val());
		
    });
    
	
	//load large images
	
	/* load images starts */
	$('#img_div li').each(function(){
		$(this).find('img').attr({
			src : $(this).find('input.img').val()
		});
	});
	
	/* set list images */
	$('#loader').html('<img src="'+ $('#menu_list li:first-child').find('input.url').val() +'" alt="" />');
	
	/* arrow button animations */
	$('.jcarousel-next').hover(
    	function(){
    		$(this).animate({right : '-=5px' }, 'slow', 'easeOutBack');
    	},
    	function(){
    		$(this).animate({right : '+=5px' }, 'slow', 'easeOutBack');
    	}
    );
    $('.jcarousel-prev').hover(
    	function(){
    		$(this).animate({left : '-=5px' }, 'slow', 'easeOutBack');
    	},
    	function(){
    		$(this).animate({left : '+=5px' }, 'slow', 'easeOutBack');
    	}
    );
	
	/*
$('.jcarousel-item').each(function(){
		$('ul#img_div').animate({'left' : '-' + $(this).position().left + 'px'}, 1400, 'easeOutBack', function(){
			$(this).find('.info').stop(true, true).delay(1000).animate({top : '230px'}, 1000, 'easeOutBack',function(){
				$(this).delay(2000).animate({top : '400px'}, 1000, 'easeOutBack');
			});
		}).delay(5000);
	});
*/

	
})