var $ = jQuery.noConflict();

jQuery(document).ready(function() {

	var wrapper = $('#gallery'); // The outer wrapper
	var carousel = $('#gallery_content'); // The inner wrapper
	var items = $('#gallery_content li'); // The different elements, this is an array
	var item_width = 148; // The full width of a single item (incl. borders, padding, etc ... if there is any)
	var max_margin = (items.length)* 148 -385;
	var maxlenght = (items.length) * 148;

	// Set up the animation
	//var animation = new Fx.Tween(carousel, {duration: 500});
	
	// The function to browse forward
	function previous_item(pos){
		if(pos <= -max_margin){
			//animation.start('left', 0);
			carousel.animate({
			    left: 0  
			}, 500);
		} else {
			var newposition = pos - item_width;
			//animation.start('left', newposition);
			carousel.animate({
			    left: newposition  
			}, 500);
		}
	};

	// The function to browse backward
	function next_item(pos){
		if(pos >= 0){
			//animation.start('left', -max_margin);
			carousel.animate({
			    left: -max_margin  
			}, 500);
		} else {
			var newposition = pos + item_width;
			//animation.start('left', newposition);
			carousel.animate({
			    left: newposition  
			}, 500);
		}
	};
	
	$('#next').click(function(){
		if(carousel.css('left') == 'auto') {
			var left = 0;
		} else {
			var left = carousel.css('left');
		}
		var position = parseInt(left);
		previous_item(position);
		return false;
	});
	$('#previous').click(function(){
		if(carousel.css('left') == 'auto') {
			var left = 0;
		} else {
			var left = carousel.css('left');
		}
		var position = parseInt(left);
		next_item(position);
		return false;
	});

});



$(document).ready(function(){ 
    $("ul.sf-menu").supersubs({ 
        minWidth:    15,
        maxWidth:    27,
        extraWidth:  1 
    }).superfish({ 
        delay:       500,
        animation:   {opacity:'show',height:'show'}, 
        speed:       'fast', 
        autoArrows:  true, 
        dropShadows: false,
        minWidth:    20
    }).find('ul').bgIframe({opacity:false});

    $('#iCarouselTT').webTicker({travelocity: 0.1, direction: 1});
    
    /*$('#iCarouselTT').bxSlider({
        ticker:true,
        tickerSpeed: 1500,
        tickerHover: true
    });*/

	$('a.imggall').live('mouseover keypress keydown', function() {
		$(this).fancybox({
	    	'transitionIn' : 'elastic',
	    	'transitionOut' : 'elastic',
	    	'speedIn' : 600,
	    	'speedOut' : 200,
	    	'overlayShow' : true,
	    	'type' : 'image',
	    	'titleShow' : true,
	    	'overlayOpacity': '0.8',
	    	'overlayColor' : '#000'
		});
	});

});





