$(document).ready(function() {
jQuery.fn.extend({
	scrollTo : function(speed, easing) {
		return this.each(function() {
			var targetOffset = $(this).offset().top;
			$('html,body').animate({scrollTop: targetOffset}, speed, easing);
		});
	}
});
function getTinyURL(longURL, success) {
	var API = 'http://json-tinyurl.appspot.com/?url=';
	var URL = API + encodeURIComponent(longURL) + '&callback=?';
	$.getJSON(URL, function(data){
		success && success(data.tinyurl);
	});
}
/* tool tips */
$('.tooltip').each(function() {
	var $t = $(this);
	var $info = $t.attr('title')
	$t.removeAttr('title');
	var $info = $info.split('||');
	var $title = $info[0];
	var $content = $info[1];
	if($content.length > 0) {
		$t.qtip({
			content: {
				text: $content, 
				title: {
					text: $title,
					button: false
				}
			},
			position: {
				my: 'right center', // Use the corner...
				at: 'left center' // ...and opposite corner
			},
			style: {
				classes: 'ui-tooltip-shadow ui-tooltip-light'
			}
		});
	}
	$t.click(function() {
		return false;
	});
});
$('.tips').each(function() {
	var $t = $(this);
	var $info = $t.attr('title')
	$t.removeAttr('title');
	var $content = $info;
	if($content.length > 0) {
		$t.qtip({
			content: {
				text: $content
			},
			position: {
				my: 'bottom center', // Use the corner...
				at: 'top center' // ...and opposite corner
			},
			style: {
				classes: 'ui-tooltip-shadow ui-tooltip-light'
			}
		});
	}
	$t.click(function() {
		return false;
	});
});
$('.tips-right').each(function() {
	var $t = $(this);
	var $info = $t.attr('title')
	$t.removeAttr('title');
	var $content = $info;
	if($content.length > 0) {
		$t.qtip({
			content: {
				text: $content
			},
			position: {
				my: 'left center', // Use the corner...
				at: 'right center' // ...and opposite corner
			},
			style: {
				classes: 'ui-tooltip-shadow ui-tooltip-light'
			}
		});
	}
	$t.click(function() {
		return false;
	});
});
//popups
$('a.hotelinfo').colorbox({'iframe':true, 'width':'50%', 'height':'80%', 'opacity':.5});
$('a.colorbox').colorbox({
	'width':'60%', 'maxWidth':'900px', 'height':'70%', 'opacity':.5,
	onComplete:function() {$('a.colorbox').colorbox({'width':'60%', 'maxWidth':'900px', 'height':'70%', 'opacity':.5}); content_init();}
});
$('.camp-staff-pic a').colorbox({'width':'975', 'height':'80%', 'opacity':.5});
$('a.colorbox-iframe').colorbox({'iframe':true, 'width':'600', 'height':'620px', 'opacity':.5});
$('a.colorbox-youtube').each(function() {
	var str = '';
	var $rel = $(this).attr('rel');
	if($rel) {
		str = $rel;
	}
	var h = 565;
	var w = 345;
	if(str.length > 0) {
		var demi = str.split('_');
		h = demi[0];
		w = demi[1];
	}
	$(this).colorbox({'innerWidth':h, 'innerHeight':w, 'opacity':.5});
});
//load hotel info on location page popup
$('a.colorbox-hotel').colorbox({
	'width':'900', 'height':'80%', 'opacity':.5,
	onComplete: function() {
		$('#hotel-list li.hotel a').click(function(event){
			event.preventDefault();
			var $url = $(this).attr('href');
			var $result_el = $('#hotel-info');
			$result_el.html('<div style="margin-top:50px; text-align:center"><img src="images/ajax-loader.gif" alt="Loading" /></div>');
			$.get($url, function(data) {
				$result_el.html(data);
			});
		});
	}
});


//rollover images
$('.rollover').each(function() {
	var img = $(this).find('img');
	var src = img.attr('src');
	var new_src = src.split(".");
	new_src = new_src[0]+'_over.'+new_src[1];
	
	//preload rollover images
	(new Image()).src=new_src;
	
	//on mouse over add _over to the src before the extension (ex. "btn.jpg" becoms "btn_over.jpg" on mouseover)
	$(this).mouseover(function() {
		img.attr('src',new_src);
	});
	//revert back to original image on mouse out
	$(this).mouseout(function() {
		img.attr('src',src);
	});
});


//FOOTER ROLLOVER
var $f = $('#footer');
var $f_nav = $('#footer-nav');
var $f_height = $f_nav.height();
$f_nav.hide().css('height',0);
$f.hover(
	function() {
		$f_nav.css({'display':'block'}).stop().animate({height:$f_height},500);
	},
	function() {
		$f_nav.stop().animate({height:0},500,function(){$f_nav.css({'display':'none'})});
	}
);

//content collapsible fields
function content_init() {
	var $btns = $('a.collapsible-btn');
	var $sections = $('div.collapsible-section');
	//hide sections
	$sections.hide().slideUp();
	//toggle click
	$btns.click(function(){
		var $t = $(this);
		var $content = $t.next();
		if($t.hasClass('active')) {
			$t.removeClass('active');
			$content.slideUp('fast');
		} else {
			$t.addClass('active');
			$content.slideDown('fast');
		}
		return false;
	});
}
content_init();

//masonry implementation
var $leaders_page = $('#leaders');
$leaders_page.imagesLoaded(function(){
	$leaders_page.masonry({
		itemSelector: '.guest'
	});
});

/*---------------------------------------------------------
--------- SLIDE SHOW IMPLEMENTATIONS ----------------------
----------------------------------------------------------*/
$('#location-slide').simpleSlides({'width':600,'height':400, 'arrows': true, 'nav': true});

$('#homepage-slideshow').simpleSlides({'width':545,'height':503, 'arrows': false, 'nav': true});

});//-----------END PRIMARY FUNCTION---
