$(function(){
	initPage();
	expandFooter();
	initHomeGallery();
	initGallery();
})
$(window).resize(function() {
  expandFooter();
});

function initPage() {

	// UI Fixes
	jQuery('.noJs').removeClass('noJs');
	//jQuery('.showElem').removeClass('showElem');
	//jQuery('.hideElem').addClass('hiddenElem');
	
	// Print Buttons
	jQuery('.printPage').click(function() {
  		window.print();
  		return false;
 	});
 
}

function expandFooter(){
	var fh = $('#footer').height();
	var ft = $('#footer').position().top;
	var wh = $(window).height();	
	if((ft+fh) < wh){
		$('#footer').height(wh-ft);
	}
}


function initHomeGallery(){
	$('.slideshow').fadeGallery({
		slideElements: '.text-slide li',
		duration:700,
		autoRotation:true,
		//pagerLinks:'div#nums a',
		switchTime: 4000
	})
	//initGallery
	$('.slideshow').galleryCircle({
		btPrev: 'a.link-prev',
		btNext: 'a.link-next',
		holderList: '.image-list-holder',
		duration: 700,
		switchTime:4000,
		numHolder: '#nums',
		numCreate: true,
		vertical:true
	})
}

function initGallery(){
	var _thumbs = $('.gallery-slider .slider-holder ul li');
	$('.gallery').fadeGallery({
		slideElements: '.gallery-holder ul li',
		pagerLinks: '.gallery-slider .slider-holder ul li',
		btnNext: '.link-next2',
		btnPrev: '.link-prev2',
		duration:700,
		autoRotation:true,
		onChange: function(_this, _slides, _prevIndex, _currentIndex){
			if (_thumbs.eq(_currentIndex).position().left < -parseInt(_this.css('margin-left'))) {
				var _step = _currentIndex * _thumbs.eq(0).outerWidth()
				$('.gallery-slider .slider-holder ul').animate({
					'margin-left': -_step
				}, 700)
				$('.gallery-slider').get(0).curInd = Math.floor(_thumbs.eq(_currentIndex).position().left/$('.gallery-slider .slider-holder').width()) + 1;
				_this.get(0).switchSlide
			}
			if (_thumbs.eq(_currentIndex).position().left > -parseInt(_this.css('margin-left')) + $('.gallery-slider .slider-holder').width()) {
				if (_currentIndex > _thumbs.length-5) _currentIndex = _thumbs.length-5;
				var _step = _currentIndex * _thumbs.eq(0).outerWidth()
				$('.gallery-slider .slider-holder ul').animate({
					'margin-left': -_currentIndex * _thumbs.eq(0).outerWidth()
				}, 700)
				$('.gallery-slider').get(0).curInd = Math.floor(_thumbs.eq(_currentIndex).position().left/$('.gallery-slider .slider-holder').width()) + 1;
				_this.get(0).switchSlide
			}
		}
	})
	$('.gallery-slider').scrollGallery({
		sliderHolder: '.slider-holder',
		btnNext: '.link-next1',
		btnPrev: '.link-prev1',
		duration: 700
	})
}
