jQuery(function($) {
	init();
});

var $i = 0;
function init() {
	initSlideshowOnHomepage('#superbgimage');
	initNewsOverlay();
	//$.loadImages(['MH_hotel-(11).jpg', 'MH_hotel-(12).jpg'], function() {  })
	initGallery(); 
	initPager();
	// setContentHeight($('#content'));
	// 	$(window).resize(function() {setContentHeight(el)});
}

/*
 * Set height of content
 */
function setContentHeight(el) {
	var offsetTop = 105;
	el.css('min-height', $(window).height() - offsetTop );
	
}

function initGallery() {
	
		$('#gallery').cycle({
		    fx:     'fade',
	       speed:  900,
	       timeout: 0,
	       pager:  '#nav',
	       pagerAnchorBuilder: function(idx, slide) {
  				  return '#nav li:eq(' + idx + ') a'; 
  				  // $width = ($(slide).width() > $(slide).height() ) ? 70 : 31;
  				  //   	           return '<li><a href="#"><img src="' + slide.src + '" width="'+$width+'" /></a></li>';
  	       }
	   });
}

function initNewsOverlay() {
	$('a.inline').fancybox({
		width:960
		,height:550
		,autoDimensions:false
	});
}

function initPager() {
	if( $('.no-fancybox').length == 0 ) {
			// $("#gallery > img").wrap('<a></a>');
			// 			$("#gallery > a").each( function(i) {
			// 				$(this).attr('href', $(this).find('img').attr('src'));
			// 			});
	
			$("#gallery > a").fancybox({
					'transitionIn'	:	'elastic',
					'transitionOut'	:	'elastic',
					'speedIn'		:	400, 
					'speedOut'		:	300, 
					'overlayShow'	:	false,
					'hideOnContentClick': true
			
				});
	}
}

/*
 * Slideshow on homepage
 */
function initSlideshowOnHomepage(bg) {
	
	$.fn.superbgimage.options = {
	   randomtransition: 0, // 0-none, 1-use random transition (0-7)
	   slideshow: 1, // 0-none, 1-autostart slideshow
	   slide_interval: 4500, // interval for the slideshow
	   randomimage: 0, // 0-none, 1-random image
	   speed: 'slow', // animation speed
	   inlineMode: 0,
	   vertical_center: 1,
		preload: 1,
	   isFullscreen: true,
	   offsetTop: 0
	};

	// initialize SuperBGImage
	$(bg).superbgimage();
}


