﻿(function () {

"use strict";

Cufon.set("fontFamily", "Varela");

Cufon("h1");
Cufon(".menu a", {hover: true});
Cufon(".banner .call-us", {textShadow: "1px 1px #111"});
Cufon(".page-home .links a");
Cufon(".sidebar a");

Cufon.now();


}());

;(function($) {
$(document).ready(function() {

	if($('#whats-on').length) {
		$('#whats-on > li').each(function() {
			if($(this).children('dl').children('dd.days').text()!='') {
				var days = $(this).children('dl').children('dd.days').text().toLowerCase().split(',');
				for(var day in days) {
					if($('#days li.' + days[day]).children('ul').length == 0) $('#days li.' + days[day]).append('<ul></ul>');
					if($(this).children('div.introduction').children('p').text()=='') $(this).children('div.introduction').remove();
					if($(this).children('div.image').children('img').attr('src')=='') $(this).children('div.image').remove();
					$(this).children('dl').children('dd').each(function() {
						var content = $.trim($(this).text());
						if(content=='' || content=='$' || content=='$0') {
							$(this).prev('dt:not(.contact)').remove();
							$(this).remove(); 
						}						
					});

					$(this).clone().appendTo('#days li.' + days[day] + ' ul'); 
				}
			}
		});
		$('#days > li').each(function() {
			if(!$(this).children('ul').length) $(this).remove();
		});
	}
	if($('#whos-who').length) {
		$('#whos-who > li').each(function() {
			if($(this).children('div.image').children('img').attr('src').substring(0,1) == '?') $(this).children('div.image').children('img').remove();
			$(this).children('dl').children('dd').each(function() {
				if($.trim($(this).text())=='') {
					$(this).prev('dt').remove();
					$(this).remove();
				}
			});
		});
	}
	if($('.page-home .slider').length) {
		$.getScript('/js/jquery.nivo.slider.pack.js', function(data, textStatus){
			// sliceDown, sliceDownLeft, sliceUp, sliceUpLeft, sliceUpDown, sliceUpDownLeft, fold, fade,
			// random, slideInRight, slideInLeft, boxRandom, boxRain, boxRainReverse, boxRainGrow, boxRainGrowReverse
			$('.page-home .slider').nivoSlider({
				effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
				slices:15, // For slice animations
				boxCols: 8, // For box animations
				boxRows: 4, // For box animations
				animSpeed:500, // Slide transition speed
				pauseTime:3000, // How long each slide will show
				startSlide:0, // Set starting Slide (0 index)
				directionNav:false, // Next & Prev navigation
				directionNavHide:true, // Only show on hover
				controlNav:true, // 1,2,3... navigation
				controlNavThumbs:false, // Use thumbnails for Control Nav
				controlNavThumbsFromRel:false, // Use image rel for thumbs
				controlNavThumbsSearch: '.jpg', // Replace this with...
				controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
				keyboardNav:true, // Use left & right arrows
				pauseOnHover:false, // Stop animation while hovering
				manualAdvance:false, // Force manual transitions
				captionOpacity:0.8, // Universal caption opacity
				prevText: '', // Prev directionNav text
				nextText: '', // Next directionNav text
				beforeChange: function(){}, // Triggers before a slide transition
				afterChange: function(){}, // Triggers after a slide transition
				slideshowEnd: function(){}, // Triggers after all slides have been shown
				lastSlide: function(){}, // Triggers when last slide is shown
				afterLoad: function(){} // Triggers when slider has loaded
			});
		});
	}
	if($('#map').length) {
		$.getScript('/js/jquery-ui-1.8.16.custom.min.js', function(data, textStatus){
		$.getScript('/js/gmap3.min.js', function(data, textStatus){
			$('#locations').accordion({
				autoHeight: false
			});
			$('#map').gmap3(
				{
					action: 'init',
					options: {
						center:[-26.695676, 153.06015],
						zoom: 10
					},
					onces: {
						bounds_changed: function(){
							$(this).gmap3({
								action:'getBounds', 
								callback: function (bounds){
									if (!bounds) return;
									var map = $(this);
									$('#locations li').each(function(lindex) {
										addPantoMarker(map, lindex, $(this).children('div.content').children('span.lat').text(), $(this).children('div.content').children('span.lng').text());
									});

								}
							});
						}
					}
				},
				{
					action: 'autoFit'
				}
			);
			function addPantoMarker($this, i, lat, lng){
				$this.gmap3({
					action : 'addMarker',
					lat: lat,
					lng: lng,
					callback: function(marker){
						$('#locations li').eq(i).find('a.locate').click(function(e) {
							var location = $(this).parent().parent().parent();
							console.log(location);
							e.preventDefault();
							$this.gmap3(
								{
									action:'panTo',
									args:[marker.position]
								},
								{
									action: 'addInfoWindow', 
									lat: lat,
									lng: lng,
									map:{
										center: true,
										zoom: 14
									},
									infowindow:{
										options:{
											content: location.find('dd.address').text()
										},
										events:{
											closeclick: function(infowindow, event){
												//alert('closing : ' + $(this).attr('id') + ' : ' + infowindow.getContent());
												
											}
										}
									}
								}
							);
						});
						if($('#map.single').length) $('#locations li').eq(i).find('a.locate').click();
					}
				});
			}
		});
		});
	}
})
})(jQuery);
