

$(document).ready(function () {

	Cufon.replace('h1');
	Cufon.replace('.replace');

	$('a[href^=http://]').addClass('external');
    $('a[href=mailto:]').removeClass('external');
	if($('.view-things-to-know').length)
		$('.view-things-to-know').jScrollPane();
	$("div.show-holidays").css("display", "none");
	$("a.show-holidays").mouseover(function() {
		var cssObj = {
			'display' : 'block',
		}

		$("div.show-holidays").css(cssObj).prepend('<div class="small-triangle-florish"></div>');
		console.log();

	});
	$("a.show-holidays").mouseout(function() {
											
		$("div.show-holidays").css("display", "none");
		$(".small-triangle-florish").remove();

	});



$(".slidetabs").tabs(".images > div", {

	// enable "cross-fading" effect
	effect: 'fade',
	fadeOutSpeed: "slow",

	// start from the beginning after the last tab
	rotate: true

// use the slideshow plugin. It accepts its own configuration
}).slideshow();


//	jQuery("a[rel='zoomer']").colorbox({transition:"none", width:"75%", height:"75%"}); 


	// What on Earth gallery
	var imgGallery = $(".mini-thumb").size(); 

	if (imgGallery) 
	{
		$(".mini-thumb").overlay({
			effect: 'apple',
			target: '#gallery', 
			expose: '#000',
		}).gallery({
			// the plugin accepts its own set of configuration options
			speed: 800,
			opacity: 1
		});
	}

	var imgGallery = $(".zoomer").size(); 

	if (imgGallery) 
	{
		$(".zoomer").overlay({
			effect: 'apple',
			target: '#gallery', 
			expose: '#000',
		}).gallery({
			// the plugin accepts its own set of configuration options
			speed: 800,
			opacity: 1
		});
/*
		$(".zoomer").overlay({
			target: '#gallery', 
			expose: '#000',
		});
*/
/*		.slideshow({}); */
	}
	if ($('#timeline').length)
		$("#timeline").scrollable({size: 1}).navigator({indexed: true, api: true});

//	jQuery('.carousel').jcarousel({
	/* setting the width in css, because of the addition of the frame messes up jcarousel's width calculation.
		visible: 1, */
//		auto: 5, 
//		scroll: 1,
//		initCallback: mycarousel_init,
//		itemVisibleInCallback: change_status,
//	});

//	$('.view-things-to-know').jScrollPane();
	$("#show-holidays").tooltip({ effect: 'fade', tip: '.holiday-schedule', position: 'center right', offset: [120,10] });  
	$('.holiday-schedule').append('<div class="small-triangle-florish"><div>');


/*
if ($('#player').length)
{
//	$f("player", "/sites/all/themes/common/js/flowplayer/flowplayer-3.1.5.swf",  {
	$f("player", "/sites/all/themes/common/js/flowplayer/flowplayer-3.2.1-0.swf",  {
		
	// default configuration for a clip
		clip: conf.defaults,
	
		onStart: function (clip) {
			var w = parseInt(clip.metaData.width, 10),
				h = parseInt(clip.metaData.height, 10);
			$(this.getParent()).css({width: w, height: h});
		},
		plugins: {		
//			controls: conf.skins.gray		
			controls: {
				autoHide: "always"
			},
		}
	
	});
}
*/
if ($('#player').length)
{
	flashembed("player", {
		src: "/sites/all/themes/common/js/flowplayer/flowplayer-3.2.1-0.swf",
	},{
		config: { 
			clip: {
				autoPlay: false,
				autoBuffering: true,
				url: $('#player').attr('href')
			},
			plugins: {		
				controls: {
					autoHide: "always"
				}
			}
		}
	});
	$('#player').bind("click", function(event) { event.preventDefault() });
}

if ($('#audio').length){
	$f("audio", "http://releases.flowplayer.org/swf/flowplayer-3.1.5.swf", { 
 
    // fullscreen button not needed here 
    plugins: { 
        controls: { 
            fullscreen: false, 
            height: 30 
        } 
    }, 
 
    clip: { 
        autoPlay: false, 
 
        // optional: when playback starts close the first audio playback 
        onBeforeBegin: function() { 
            $f("player").close(); 
        } 
    } 
 
});
}



//     $.fn.media.defaults.mp3Player = 'player.swf';
//     $.fn.media.mapFormat('mp3','flash'); 

// global defautls; override as needed 
/*
$.fn.media.defaults = { 
//    preferMeta:    1,         // true if markup metadata takes precedence over options object 
//    autoplay:      0,         // normalized cross-player setting 
//    bgColor:       '#ffffff', // background color 
//    params:        {},        // added to object element as param elements; added to embed element as attrs 
//    attrs:         {},        // added to object and embed elements as attrs 
//    flashvars:     {},        // added to flash content as flashvars param/attr 
//    flashVersion:  '7',       // required flash version 
 
    // default flash video and mp3 player 
    // @see: http://jeroenwijering.com/?item=Flash_Media_Player 
    flvPlayer:     '/sites/all/themes/common/js/jmedia/player.swf',
    mp3Player:     '/sites/all/themes/common/js/jmedia/player.swf',
//    mp3Player:     '/sites/all/themes/common/js/jmedia/singlemp3player.swf',
 
}; 
*/



//$('.play-audio').media( { width: 300, height: 20 } ); 

if ($('.photo-carousel').length)
	$(".photo-carousel").scrollable({size: 1, speed: 1500}).autoscroll().navigator();

  function mycarousel_init(carousel)
  {
  /*	jQuery('.carousel-control a:first').addClass('active-pager');
  */	jQuery('.carousel-control a').bind('click', function() {
											carousel.startAuto(0);
											carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
  /*										  jQuery(this).addClass('active-pager');
  */										  return false;
										});
	  // Pause autoscrolling if the user moves with the cursor over the clip.
	  carousel.clip.hover(function() {
		  carousel.stopAuto();
	  }, function() {
		  carousel.startAuto();
	  });
  
  
  }
  function change_status(carousel, li, i, state)
  {
  // alert(i);
	  var current = i-1;
	  jQuery('.active-pager').removeClass('active-pager');
	  jQuery('.carousel-control a:eq('+ current + ')').addClass('active-pager');
	  return false;
  }

  $(function() {
  //	$('#accordion h3').append('<span class="icon"></span>');
  //	$("#accordion").accordion({ header: 'h3', active: true, collapsible: true, autoHeight: false, change: function(e, ui) { $(e.target).filter('.scroll-content').jScrollPane() }  });
  });


$(".banner-thumbnails a").click(function(e) { 
 

	e.preventDefault();

	// calclulate large image's URL based on the thumbnail URL (flickr specific) 
    var url = $(this).attr("href"); 
 
//alert(url);
	// get handle to element that wraps the image and make it semitransparent 
    var wrap = $("#banner-image").fadeTo("medium", 0.5); 
 
    // the large image from flickr 
    var img = new Image(); 
 
    // call this function after it's loaded 
    img.onload = function() { 
 
        // make wrapper fully visible 
        wrap.fadeTo("fast", 1); 
 
        // change the image 
        wrap.find("img").attr("src", url); 
 
    }; 
 
    // begin loading the image from flickr 
    img.src = url; 
 
// when page loads simulate a "click" on the first image 
}).filter(":first").click();



//initialize();
setupMap();

$('#toAddress').focus(function() { $(this).val(''); } );
});






    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

	function setupMap() {

if(typeof GBrowserIsCompatible == 'function') { 
      if (GBrowserIsCompatible()) {

		var point = new GLatLng(38.958577, -95.243581);

		map = new GMap2(document.getElementById("map-canvas"));
        map.addControl(new GLargeMapControl());
        map.setCenter(point, 16);
        map.enableDoubleClickZoom();

/*	when there's a replacement pin.
		var iconDyche = new GIcon(); 
		iconRed.image = '/images/map-pin.png';
		iconRed.shadow = '/images/map-pin-shadow.png';
		iconRed.iconSize = new GSize(30, 56);
		iconRed.shadowSize = new GSize(58, 56);
		iconRed.iconAnchor = new GPoint(15, 56);
		iconRed.infoWindowAnchor = new GPoint(5, 1);

		var options = { 
		  icon: iconRed,
		  draggable: false
		};

		var marker = new GMarker(point, options);
*/
		var marker = new GMarker(point);

		map.addOverlay(marker);

        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
	  }
}
	}
    function setDirections(fromAddress) {
		locale = 'en_US';
		toAddress = '1261 Oread Ave., Lawrence, Kansas 66045';
		gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}
	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}





