$(document).ready(function() {
	$("#billboard ul").jqGalScroll({
		ease: 'easeInOutCubic',
		speed:1000,
		height: 360,
		width: 960,
		titleOpacity : .0,
		direction : 'horizontal'
	});
	
	var gallery = $('#minigallery .pics');
	var picsWrap = gallery.find('.picsWrap');
	var gal_speed = 600;
	var current_pic = 0;
	
	var picslinks = gallery.find('a');
	picslinks.filter('.popup').fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false });
	/*
	picslinks.filter('.link').click(function(event){
		event.preventDefault();
		var url = $(this).attr('href');
		if (url != "") {
			popwin = window.open(url, "popup"); //, "menubar=no, width=450, height=450, toolbar=no"
		}
	});
	*/
	var gal_size = picslinks.size()-1;
	function move_gal_next(){
		if (current_pic == gal_size) {
			current_pic = 0;
			picsWrap.animate({"top": "+=" + (105 * gal_size) + "px"}, gal_speed);
		} else {
			picsWrap.animate({"top": "-=105px"}, gal_speed);
			current_pic++;
		}
	}
	function move_gal_prev(){
		if (current_pic == 0) {
			current_pic = gal_size;
			picsWrap.animate({"top": "-=" + (105 * gal_size) + "px"}, gal_speed);
		} else {
			picsWrap.animate({"top": "+=105px"}, gal_speed);
			current_pic--;
		}
	}
	
	
	runGallery = function(){
	  move_gal_next();
	};
	setInterval ( runGallery, 5000 );
	
	
	$('#prevGal').click(function(event){
		event.preventDefault();
		move_gal_prev();
	});
	$('#nextGal').click(function(event){
		event.preventDefault();
		move_gal_next();
	});
	if ( document.body.clientWidth < 960) {
		$('#page').width(980);
	} else { $('#page').width('100%'); }
	$(window).resize(function(){
		if ( document.body.clientWidth < 960) {
			$('#page').width('980px');
		} else { $('#page').width('100%'); }
	});
});