$(function()
	{
	$('#camscarousel a').lightBox();
	//$('a[@rel^=lightbox]').lightBox();
	//$('a.fred').lightBox();
	});

function slideSwitch()
	{
	var $active = $('#slideshow IMG.active');
	if ( $active.length == 0 )
		$active = $('#slideshow IMG:last');
	// use this to pull the images in the order they appear in the markup
	var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');
	// uncomment the 3 lines below to pull the images in random order
	// var $sibs  = $active.siblings();
	// var rndNum = Math.floor(Math.random() * $sibs.length );
	// var $next  = $( $sibs[ rndNum ] );
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function()
			{
			$active.removeClass('active last-active');
			});
	}
$(function()
	{
	setInterval( "slideSwitch()", 5000 );
	});

$(document).ready(function()
	{ // when html is loaded
	var h = 0;
	setupGallery(100);
	$("#featurecarousel li").each(function()
		{ // iterate features to get the max height
		if ($(this).height() > h)
			h = $(this).height();
		});
	$("#featurecarousel li").each(function()
		{ // iterate features to set the max height
		$(this).height(h);
		});
	$("#featurecarousel").height(h);
	$(function()
		{ 
		$("div#newsticker ul").liScroll({travelocity: 0.05}); 
		});
	$("#camscarousel").jCarouselLite(
		{
		auto: 2000,
		speed: 1000,
		visible: 1,
		pauseOnHover: true,
		btnNext: null,
		btnPrev: null,
		btnGo:
			[".externalControl .1", ".externalControl .2",
			 ".externalControl .3", ".externalControl .4",
			 ".externalControl .5", ".externalControl .6",
			 ".externalControl .7", ".externalControl .8"]
		});
	$("#featurecarousel").jCarouselLite(
		{
		auto: 5000,
		speed: 1000,
		visible: 1,
		pauseOnHover: true,
		btnNext: null,
		btnPrev: null
		});
	setTall();
	});

function setTall()
	{
	var content = $('#content');
	var contentOuterHeight = content.outerHeight(true);
	var contentPadEtc = contentOuterHeight - content.height();

	var sidebar = $('#sidebar');
	var sidebarOuterHeight = 0;
	if (sidebar != null)
		sidebarOuterHeight = sidebar.outerHeight(true);

	var maxHeight = Math.max(contentOuterHeight, sidebarOuterHeight);
	content.height(maxHeight - contentPadEtc);
	}

function setupGallery(thumbheight)
	{
	var h = 0;
	var pad = 2;
	var current = null;
	var thumbcarousel = $(document.createElement('div')).addClass('thumbcarousel');
	var thumbcontainer = $(document.createElement('div')).addClass('gallerythumb');
	thumbcarousel.append(thumbcontainer);
	thumbcontainer.width(0);
	$('.galleryimage').each(function(index)
		{
		if ($(this).height() > h)
			h = $(this).height();
		});
	$('.galleryimage img').each(function(index)
		{
		if ($(this).height() > h)
			h = $(this).height();
		});
	//thumbcontainer.children().remove();
	var loc = new Array();
	loc[0] = 0;
	$('.galleryimage').each(function(index)
		{
		var div = $(this);
		div.height(h);
		var img = div.find('img');
		var src = img.attr('src');
		var thumbwidth = Math.ceil(img.attr('width') / img.attr('height') * thumbheight);
		if (index == 0)
			{
			current = div;
			div.before(thumbcarousel);
			}
		else
			div.css('display', 'none');
		thumbcontainer.width(thumbcontainer.width() + thumbwidth + pad);
		loc.push(thumbcontainer.width());
		var thumb = $(document.createElement('img')).attr('border', '0').attr('src', src).css({ height: thumbheight, width: thumbwidth });
		thumb.click(function()
			{
			if (current)
				current.css('display', 'none');
			div.css('display', 'block');
			current = div;
			return false;
			});
		var a = $(document.createElement('a')).attr('href', '#');
		a.append(thumb);
		thumbcontainer.append(a);
		});
	if (thumbcontainer.width() > thumbcarousel.width())
		{
		var thumbnav = $(document.createElement('div')).addClass('thumbnav');
		var prev = $(document.createElement('a')).attr('href', '#').addClass('prev').append(document.createTextNode('< Prev'));
		var next = $(document.createElement('a')).attr('href', '#').addClass('next').append(document.createTextNode('Next >'));
		thumbnav.append(prev);
		thumbnav.append(next);
		thumbcarousel.before(thumbnav);
		prev.click(function()
			{
			var e = - thumbcontainer.position().left;
			var s = e - thumbcarousel.width() - pad
			if (s < 0)
				s = 0;
			var n = 999;
			for (var i = 0; i < loc.length; i++)
				{
				if (loc[i] < s)
					continue;
				if (loc[i] <= e)
					n = -loc[i];
				break;
				}
			if (n != 999)
				{
				thumbcontainer.animate({left: n+'px'}, 'slow');
				next.css('display', 'block');
				}
			if (n == 0)
				prev.css('display', 'none');
			else
				prev.css('display', 'block');
			return false;
			});
		next.click(function()
			{
			var s = - thumbcontainer.position().left;
			var e = s + thumbcarousel.width() + pad;
			var n = 0;
			for (var i = 0; i < loc.length; i++)
				{
				if (loc[i] < s)
					continue;
				if (loc[i] > e)
					break;
				n = -loc[i];
				}
			if (n < 0)
				{
				if (thumbcontainer.width() + n <= thumbcarousel.width() + pad)
					{
					n = thumbcarousel.width() + pad - thumbcontainer.width();
					next.css('display', 'none');
					}
				else
					next.css('display', 'block');
				thumbcontainer.animate({left: n+'px'}, 'slow');
				prev.css('display', 'block');
				}
			return false;
			});
		prev.css('display', 'none');
		if (thumbcontainer.width() <= thumbcarousel.width())
			next.css('display', 'none');
		}
	}

function showWin()
  {
  var w = window.open('','popup',
      'width=750,height=540,resizable,scrollbars,status,left=80,top=0');
  w.document.clear();
  w.focus();
  return true;
  }
function showSearch()
	{
	window.name='origin';
	var w = window.open('','search',
		'width=250,height=550,resizable,scrollbars,status,top=0,left=0');
	w.document.clear();
	w.focus();
	return true;
	}

function mailIt()
	{
  var email = "info"
  var emailHost = "snowholidays.com.au"
  document.write("<a href=" + "mail" + "to:" + email + "@" + emailHost + ">(Click here)</a>")
	}

	/*!
 * liScroll 1.0
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2009 Gian Carlo Mingati
 * Version: 1.0.1 (07-DECEMBER-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 * 
 */

jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).width();
				});
				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};