window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){arguments.callee=arguments.callee.caller;var a=[].slice.call(arguments);(typeof console.log==="object"?log.apply.call(console.log,console,a):console.log.apply(console,a))}};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());

var siteid = 'SITE_110830_08520217_1QS2T'

$(window).load(function(){

	/* Position the images
	var win = $(window)
	var $l = $('#homephotos .photo img');
	var minW = $l.width()*$('#homephotos .photo').height()/$l.height();
	win.resize(function(){
		var w = win.width();
		if(w < minW) w = minW;
		$l.width(w);
		$l.css('margin-top',(438-$l.height())/2);
	}).resize(); */

	/* Rotate the images */
	$('#homephotos .photo img:first').addClass('active').css('z-index',99).fadeIn({duration:1000,easing:'linear'});
	var loadNext = function(){
		var $t = $('#homephotos .photo img.active');
		var $n = $t.next();
		if($n.length==0)$n = $('#homephotos .photo img:first');
		$n.css('z-index',98).show();
		$t.delay(3300).fadeOut({duration:1000,easing:'linear',complete:function(){
			$n.addClass('active').css('z-index',99);
			$(this).removeClass('active');
			loadNext();
		}});
	};
	setTimeout(function(){loadNext();},1000);

});

$(function() {

	$.fn.scaleMe = function() {
		return this.each(function() {
			var $this = $(this);
			$(window).load(function() {
				var originalWidth = $this.width();
				var originalHeight = $this.height();
				var divHeight = $this.closest('div').height();

				$(window).resize(function() {
					var divWidth = $this.closest('div').width();
					var newWidth = divWidth;
					var newHeight = (divWidth/originalWidth)*originalHeight;

					if( newHeight < divHeight ) {
						newHeight = divHeight;
						newWidth = originalWidth*(newHeight/originalHeight);
					}

					var topMargin = (divHeight-newHeight)/2;
					var leftMargin = (divWidth-newWidth)/2;

					$this.height(newHeight)
					.width(newWidth)
					.css({
						'margin-top' : topMargin,
						'margin-left' : leftMargin
					});

				}).resize();

				$this.fadeIn();

			});
		});
	};

	$('#subphotos .photo1 img,#subphotos .photo2 img,#subphotos .photo3 img,#homephotos .photo img').scaleMe();


	$.fn.shrinkMe = function() {
		return this.each(function() {
			var $this = $(this);
			$(window).load(function() {
				var originalWidth = $this.width();
				var originalHeight = $this.height();

				$(window).resize(function() {
					var divWidth = $this.parent().width();
					var newWidth;
					var newHeight;

					if( originalWidth > divWidth ) {
						newWidth = divWidth;
						newHeight = originalHeight*(newWidth/originalWidth);
					}else{
						newHeight = originalHeight;
						newWidth = originalWidth;
					}
					$this.height(newHeight).width(newWidth);

				}).resize();

				$this.fadeIn();

			});
		});
	};

	$('.content img').shrinkMe();
});





/****************************************
 * 
 * Title:	Sitemap Generator v0.1
 * Author:	Derek Bredensteiner
 * Date: 	07/21/2011
 * 
 * Description:
 * 			- Based on the sitemap.json that's now standardly published across all sites
 * 			- Generates a table styled like the old sitemap tables
 * 			- Was originally written for rosewood, caneel bay
 *
 * Usage/HTML:
 *
 *		<!--- Provide a target element, and trigger the function --->
 *		<div id="sitemap"></div>
 *		<script>loadSiteMap();</script>
 *
 ****************************************/
function loadSiteMap(){
  $(function(){
	$.ajax({
		url: '/i/'+siteid+'/sitemap.json?'+new Date()+Math.random(),
		datatype: 'jsonp',
		cache: false,
		success:function(pages){

			var getByParent = function(id){
				for(var i in pages){
					if(pages[i].PARENTID==id) return pages[i];
				} return false;
			}
			var getById = function(id){
				for(var i in pages){
					if(pages[i].PAGEID==id) return pages[i];
				} return false;
			}
			String.prototype.repeat = function( num )
			{
			    return new Array( num + 1 ).join( this );
			}


			
			var level = -1;
			var addChildren = function(id){
				level++;
				for(var i in pages){
					if(pages[i].PARENTID==id){
						
						if(document.location.href.match(/\?task\=builder&pageid=/i))
							pages[i].HREF = '?task=builder&pageid='+pages[i].PAGEID;
						

						var $tr =
							(level==0
								?'<tr class="cell-light">'
								:'<tr class="cell-dark">')
								+'<td>'
									+' '.repeat(level*4)
									+'<a href="'+pages[i].HREF+'">'
										+(level==0
											?pages[i].NAV_LABEL.toUpperCase()
											:pages[i].NAV_LABEL)
									+'</a>'
								+'</td>'
							+'</tr>'

						$table.append($tr);

						addChildren(pages[i].PAGEID,$table);

					}
				}
				level--;
			}
			var $table = $('<table width="100%" cellpadding="3"></table>');
			$('#sitemap').append($table);

			addChildren(getByParent('').PAGEID,$table)

		}
	});
  });
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}




$(function() {
	$(".siteMapNav li:even").addClass("dark");
});
