function formatText(index, panel) {
	return index + "";
}
    
$(function () {
	anythingSlider();
	
});

function anythingSlider(){
		var thumbIndex = 1;
	$('.anythingSlider').each(function(){
		autoPlaySlider=false;
		image_count=$(this).children('div').children('ul').children('li').length;
		if(image_count>1){
			autoPlaySlider=true;
		}
			
		$(this).anythingFader({
			   autoPlay: autoPlaySlider,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
                delay: 5000,                    // How long between slide transitions in AutoPlay mode
                startStopped: false,            // If autoPlay is on, this can force it to start stopped
                animationTime: 250,             // How long the slide transition takes
                hashTags: true,                 // Should links change the hashtag in the URL?
                buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
                pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
                startText: "Go",                // Start text
                stopText: "Stop",               // Stop text
                navigationFormatter: formatText   // Details at the top of the file on this use (advanced use)
		});	
		if(image_count>1){
			$(this).children('a.arrow.forward').show();
			$(this).children('a.arrow.back').show();
		}
		else {
			$(this).children('a.arrow.forward').hide();
			$(this).children('a.arrow.back').hide();
		}
		$('.viewfinder a').click(function() {
			$('.viewfinder a').each(function(){
				if($(this).hasClass('selected')){
					$(this).removeClass('selected');
				}
			});
			$(this).addClass('selected');
			var jumpIndex = parseInt($(this).children('img').attr('rel'));
			$('.anythingSlider').anythingFader(jumpIndex);
			return false;
		});
		$('#Gallery_thumbslide_prev').hide();
		$('#Gallery_thumbslide_next').hide();
		var totalSize = $('.viewfinder').children().height();
		var viewableSize = $('.viewfinder').height();
		if(totalSize > viewableSize) {
			$('#Gallery_thumbslide_next').show();
		}
		
		$('.viewfinderNav a').click(function(){
			if($(this).html() == 'Back') {
				$('.thumbCol').animate({
					top: '+='+viewableSize
				}, 500);
				thumbIndex--;
			}
			if($(this).html() == 'Next') {
				$('.thumbCol').animate({
					top: '-='+viewableSize
				}, 500);
				thumbIndex++;
			}
			var canSlide = thumbIndex*viewableSize;
			if(thumbIndex >1) {
				$('#Gallery_thumbslide_prev').show();				
			} else {
				$('#Gallery_thumbslide_prev').hide();
			}
			if(canSlide < totalSize) {
				$('#Gallery_thumbslide_next').show();
			} else {
				$('#Gallery_thumbslide_next').hide();
			}
		});
	});

}

function anythingSlider_images(id,data){
	
	images=data.images;
		
	imagesArray=new Array();
	newHTML='';
	for(i in images){
		imagesArray.push(images[i]['Image']);
		newHTML+='<li><div class="caption">'+images[i]['Title']+'</div><img src="'+images[i]['Image']+'" alt="'+images[i]['Title']+'" class="enlargeImg"/></li>';
	}
	
	selectId=data.selectedId;
		
	if(imagesArray.length>0){
		$('#'+id).fadeOut(
			function(){
				$(imagesArray).preloadArray({
					beforeStart:function(){
		
					},					
			
					onComplete: function(){
						$('#'+id).html('<div class="wrapper"><ul>'+newHTML+'</ul></div>');
						$('#'+id).fadeIn();
						$('.tabs-selected').removeClass('tabs-selected');
						$('#'+selectId).addClass('tabs-selected');
						anythingSlider();
					}
				});
				
			}
		);

	}

}

function displayArrow(parent) {
	var pos = parent.offset();  
	var width = parent.width();
	var height = pos.top+20;
	$('#navArrow').show();
	$('#navArrow').css( { "left": (pos.left + (width/2)) + "px", "top": height + "px"} );
}

$(document).ready(
	function() {
		$('#nav li a').each(
			function() {
				if($(this).is('.on')){
					displayArrow($(this));
				}
			}
		);
		$(window).resize(function() {
			$('#nav li a').each(
				function() {
					if($(this).is('.on')){
						displayArrow($(this));
					}
				}
			);
		});
		$('ul#nav').superfish({ 
			hoverClass:  'over',
			delay:       100,                            // one second delay on mouseout 
			animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
			speed:       'fast',                          // faster animation speed 
			autoArrows:  false                           // disable generation of arrow mark-up 
		});
	}
);