var theInt = null;
var jQuerycrosslink, jQuerynavthumb;
var curclicked = 0;

theInterval = function( cur ) {
	clearInterval( theInt );

	if( typeof cur != 'undefined' )
		curclicked = cur;

	jQuerycrosslink.removeClass( 'active-thumb' );
	jQuerynavthumb.eq( curclicked ).parent().addClass( 'active-thumb' );
		jQuery( '.stripNav ul li a' ).eq( curclicked ).trigger( 'click' );

	theInt = setInterval(function(){
		jQuerycrosslink.removeClass( 'active-thumb' );
		jQuerynavthumb.eq( curclicked ).parent().addClass( 'active-thumb' );
		jQuery( '.stripNav ul li a' ).eq( curclicked ).trigger( 'click' );
		curclicked++;
		if( 3 == curclicked )
			curclicked = 0;

	}, 3000);
};

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();
	} );
};

jQuery( function() {

	// tabs
	jQuery( '#container-1' ).tabs();
	jQuery( '#container-2' ).tabs( 2 );
	jQuery( '#container-3' ).tabs( { fxSlide: true } );
	jQuery( '#container-4' ).tabs( { fxFade: true, fxSpeed: 'fast' } );
	jQuery( '#container-5' ).tabs( { fxSlide: true, fxFade: true, fxSpeed: 'normal' } );
	jQuery( '#container-6' ).tabs( {
		fxFade: true,
		fxSpeed: 'fast',
		onClick: function() {
			alert( 'onClick' );
		},
		onHide: function() {
			alert( 'onHide' );
		},
		onShow: function() {
			alert( 'onShow' );
		}
	} );

	// carousel 1
	jQuery( '#mycarousel' ).jcarousel( {
		auto: 5,
		wrap: 'last',
		scroll: 1,
		initCallback: mycarousel_initCallback
	} );

	// carousel 2
	jQuery( '#mycarousel2' ).jcarousel( {
		auto: 5,
		wrap: 'last',
		scroll: 2,
		initCallback: mycarousel_initCallback
	} );

	// carousel 3
	jQuery( '#mycarousel3' ).jcarousel( {
		auto: 5,
		wrap: 'last',
		scroll: 4,
		initCallback: mycarousel_initCallback
	} );

	// fancybox
	jQuery( 'a.single_image' ).fancybox();
	jQuery( 'a.iframe' ).fancybox( { 'overlayOpacity': 0.6, 'frameHeight': 230, 'frameWidth': 500, 'hideOnContentClick': false } );
	jQuery( 'a.inline' ).fancybox( { 'hideOnContentClick': true } );
	jQuery( 'a.group' ).fancybox( { 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false } );

	// coda slider
	jQuery( '#main-photo-slider' ).codaSlider();

	jQuerynavthumb = jQuery( '.nav-thumb' );
	jQuerycrosslink = jQuery( '.cross-link' );

	jQuerynavthumb
	.click( function() {
		var jQuerythis = jQuery( this );
		theInterval( jQuerythis.parent().attr( 'href' ).slice( 1 ) - 1 );
		return false;
	} );

	theInterval();

	// galleria
	//jQuery.browser.firefox = true;

	//jQuery( 'ul.galleria' ).galleria( {
		//history   : true, // activates the history object for bookmarking, back-button etc.
		//clickNext : false, // helper for making the image clickable
		//insert    : '#main_image', // the containing selector for our main image
		//onImage   : function( image, caption, thumb ) { // let's add some image effects for demonstration purposes
			// fade in the image & caption
			//image.css( 'display','none' ).fadeIn( 1000 );
			//caption.css( 'display','none' ).fadeIn( 1000 );

			// fetch the thumbnail container
			//var _li = thumb.parents( 'li' );

			// fade out inactive thumbnail
			//_li.siblings().children( 'img.selected' ).fadeTo( 500, 0.3 ).removeClass( 'selected' );

			// fade in active thumbnail
			//thumb.fadeTo( 'fast', 1 ).addClass( 'selected' );

			// add a title for the clickable image
			//image.attr( 'title', '' );
		//},
		//onThumb   : function( thumb ) { // thumbnail effects goes here
			// fetch the thumbnail container
			//var _li = thumb.parents( 'li' );

			// if thumbnail is active, fade all the way.
			//var _fadeTo = _li.is( '.active' ) ? '1' : '0.3';

			// fade in the thumbnail when finnished loading
			//thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);

			// hover effects
			//thumb.hover(
				//function() { thumb.fadeTo( 'fast', 1 ); },
				//function() { _li.not( '.active' ).children( 'img' ).fadeTo( 'fast', 0.3 ); } // don't fade out if the parent is active
			//)
		//}
	//} );


} );
