// Slideshow Settings
// height ratio: 690h/1400w = .4929
jQuery(document).ready(function(){
	
	var Slide = {
	cache: {},
	ready: false,
	add: function(src) {
        if (this.cache[src]) {
            return this.cache[src];
        }
        var image = new Image();
        image.src = src;
        if (image.complete && image.width) {
            this.cache[src] = image;
            return image;
        }
        image.onload = function() {
            return function() {
                this.cache[src] = image;
            };
        }
        return image;
		
	},
	display: function(src,href,title) {
		if(!src) { alert('Slide.display: src is undefined.'); return false; }
		slideHTML = '\n\t<div><img src="'+src+'" alt="" class="imgScale" /></div>\n';
		jQuery('#slides').append( slideHTML );	
		return true;
	}
	//EOC
	};

	
	var sliderWidth = jQuery('#slides').outerWidth(false);
	var slideImgHeight = sliderWidth*.4929;
	jQuery('#slides').height(slideImgHeight);
	jQuery('#slides img.imgScale').width(sliderWidth);
	jQuery('#slides img.imgScale').height(slideImgHeight);
	jQuery('#slides').css('overflow','hidden');
	//iterate through slideLinks and pull images
	var iSrc = 0;
	jQuery('#slideLinks li a').each(function(){
		iSrc++;
		if(iSrc > 1) {
			src = jQuery(this).attr('href');
			nextSlide = Slide.add(src);
			Slide.display(src);
		}
	}); 
	jQuery('#slides') // NOTE: this is the DIV ID that will be used for the slideshow
		
		.cycle({ 
			//fx:     'scrollLeft', 
			fit: 0,
			containerResize: 0,
			speed:  1400, // speed of transition in milliseconds
			easing: 'easeOutQuint', //requires the easing.js plugin
			timeout: 7000, // how long each slide displays
			pause:	1, // pause the slideshow when hovering over it
			pager:  '#pager', // must match div specified in .after (6 lines above)
			next:   '.next', // class of the next button
			prev:   '.previous', // " of the previous "
			after:  onAfter,
			before: onBefore
	});
		
	function onBefore() {
		//jQuery("#slides span").hide()	
	}
		
	function onAfter() { 
		//jQuery("#slides span").fadeIn(2000);
	}

});
jQuery(window).smartresize(function(){
	
	sliderWidth = jQuery('#slides').outerWidth(false);
	slideImgHeight = sliderWidth*.4929;
	jQuery('#slides').height(slideImgHeight);
	jQuery('#slides img.imgScale').width(sliderWidth);
	jQuery('#slides img.imgScale').height(slideImgHeight);
	/*
	newWidth = $('#slides').outerWidth(false);
	newHeight = (newWidth/.4929);
	$('#slides img.imgScale').width(newWidth);
	$('#slides img.imgScale').css('height','auto');
	var newSliderHieght = 0;
	$('#slides img.imgScale').each(function(){
		if ($(this).height() > newSliderHieght) newSliderHieght = $(this).height();										
	});
	$('#slides').css('height',newSliderHieght);
	*/
});

