// JavaScript Document

$(document).ready(function(){
	
	
	//alert($("#nav_level_2_trigger").width());
		
	// llevel-0 drop down nav
	function addMega(){ 
		$("li.mega.selectedNav").removeClass("hovering1");
		$(this).addClass("hovering1"); 
		$(this).find("h2 a").addClass("hover1"); 
	} 
	function removeMega(){ 
		if ( !($(this).hasClass("selectedNav")) ) {
			$(this).removeClass("hovering1");
			if ( !($("li.mega.hovering1").length) ) $("li.mega.selectedNav").addClass("hovering1");
			$(this).find("h2 a").removeClass("hover1"); 
		}
	}	  
    var megaConfig = {
         interval: 200,
         sensitivity: 7,
         over: addMega,
         timeout: 500,
         out: removeMega
		};
    $("li.mega").hoverIntent(megaConfig)
	
	// llevel-1 drop down nav
	function addMega2(){ 
		$($(this).find("h3 a")).addClass("hover2"); 
		$($(this).find("div.boxNavLevel2")).slideDown("medium"); 
		$(this).addClass("hovering2"); 
		} 
	function removeMega2(){ 
		if ( !($(this).find("h3 a").hasClass("selectedNav")) ) {
			$($(this).find("h3 a")).removeClass("hover2"); 
		}	
		$($(this).find("div.boxNavLevel2")).slideUp("fast"); 
		$(this).removeClass("hovering2"); 
		}	
    var mega2Config = {
         interval: 100,
         sensitivity: 4,
         over: addMega2,
         timeout: 300,
         out: removeMega2
		};
    $("li.mega2").hoverIntent(mega2Config)
	
	/*
	Configuration Options
	sensitivity:
	If the mouse travels fewer than this number of pixels between polling intervals, 
	then the "over" function will be called. With the minimum sensitivity threshold of 1, 
	the mouse must not move between polling intervals. With higher sensitivity thresholds 
	you are more likely to receive a false positive. Default sensitivity: 7interval:

	The number of milliseconds hoverIntent waits between reading/comparing mouse coordinates. 
	When the user's mouse first enters the element its coordinates are recorded. The soonest 
	the "over" function can be called is after a single polling interval. Setting the polling 
	interval higher will increase the delay before the first possible "over" call, but also 
	increases the time to the next point of comparison. Default interval: 100

	over:
	Required. The function you'd like to call onMouseOver. Your function receives the same 
	"this" and "event" objects as it would from jQuery's hover method.

	timeout:
	A simple delay, in milliseconds, before the "out" function is called. If the user 
	mouses back over the element before the timeout has expired the "out" function 
	will not be called (nor will the "over" function be called). This is primarily to 
	protect against sloppy/human mousing trajectories that temporarily (and unintentionally) 
	take the user off of the target element... giving them time to return. Default timeout: 0

	out:
	Required. The function you'd like to call onMouseOut. Your function receives the same 
	"this" and "event" objects as it would from jQuery's hover method. Note, hoverIntent 
	will only call the "out" function if the "over" function has been called on that same run.
	*/

	// slideToggle control for mega footer
	var socialTweetBubbleLoaded = false;
	$(".btn-more").click(function(){
		$("#panel").slideToggle( 'medium' );
		if (!socialTweetBubbleLoaded) { 
			$('#tweetBubble').load('/OnosSiteBase/wrap/theme/includes/incTweetBubble.aspx', function() {
				socialTweetBubbleLoaded = true;
			});	
		}
		$(this).toggleClass("btn-more_active"); return false;
	});
		
	// 2nd level nav tooltip-dropdown
	$("#nav_level_2_trigger").tooltip({ 
		relative: true,
		position: 'bottom',
		delay: 1000,
		offset: [0, 10-$("#nav_level_2_trigger").width()],
		onBeforeShow: function() {
			$('#nav_level_2_trigger').addClass('active');
			},
		onHide: function() {
			$('#nav_level_2_trigger').removeClass('active');
			}
	});		
	// 3rd level nav tooltip-dropdown
	$("#nav_level_3_trigger").tooltip({ 
		relative: true,
		position: 'bottom',
		delay: 1000,
		offset: [0,10 -$("#nav_level_3_trigger").width()],
		onBeforeShow: function() {
			$('#nav_level_3_trigger').addClass('active');
			},
		onHide: function() {
			$('#nav_level_3_trigger').removeClass('active');
			}
	});	
		

	// footer bar SOCIAL TOOLTIPS
	var socialTwitterWidgetLoaded = false;
	$("#socialFooterT").tooltip({ 
		events: {
			def:"click,",
			tooltip:""}, 
		lazy: false,
		relative: true,
		position: 'top left',
		offset: [-30, 23],
		effect: 'fade', //toggle is default
		onBeforeShow: function() {
					if (!socialTwitterWidgetLoaded) { 
						$.getScript('http://widgets.twimg.com/j/2/widget.js', function() {
							twitterLoadCallback();
						});
					} // end: loaded check
			$('#socialFooterT').addClass('active');
		},
		onHide: function() {
			$('#socialFooterT').removeClass('active');
		}
	});
	


	
	var socialFBWidgetLoaded = false;
	$("#socialFooterFB").tooltip({ 
		events: {
			def:"click,",
			tooltip:""}, 
		tip: $('#fbTooltip'),
		lazy: false,
		relative: true,
		position: 'top left',
		offset: [-30, 23],
		effect: 'fade', //toggle is default
		onBeforeShow: function() {
			//this is special for FB ONLY
			if (!socialFBWidgetLoaded) { 
					FB_RequireFeatures(["XFBML"], function() {
						FB.Facebook.init("5079e2b84d14907d557d31392d3765ec");
						FB.XFBML.Host.get_areElementsReady().waitUntilReady(function() {

						});
					});
					socialFBWidgetLoaded = true;
			}
			
			$('#socialFooterFB').show();
			},
		onHide: function() {
			$('#socialFooterFB').removeClass('active');
			}
	});
	
	var socialWordPressLoaded = false;
	$("#socialFooterWP").tooltip({ 
		events: {
			def:"click,",
			tooltip:""}, 
		lazy: false,
		relative: true,
		position: 'top left',
		offset: [-30, 23],
		effect: 'fade', //toggle is default
		onBeforeShow: function() {
			if (!socialWordPressLoaded) { 
				$('#blogFeedWidget').load('/OnosSiteBase/wrap/theme/includes/blogfeedwidget.aspx', function() {
					socialWordPressLoaded = true;
				});				
			}		
			$('#socialFooterWP').addClass('active');
			},
		onHide: function() {
			$('#socialFooterWP').removeClass('active');
			}
	});
		
	// footer bar NAV TOOLTIPS
	$("#navFooterNewsSpecials").tooltip({ 
		events: {
			def:"click,",
			tooltip:""}, 
		lazy: false,
		relative: true,
		position: 'top left',
		offset: [-10, 420],
		effect: 'fade', //toggle is default
		onBeforeShow: function() {
			$('#navFooterNewsSpecials').addClass('active');
			},
		onHide: function() {
			$('#navFooterNewsSpecials').removeClass('active');
			}
	});
	
	var navFooterExploreLoaded = false;
	$("#navFooterExplore").tooltip({ 
		events: {
			def:"click,",
			tooltip:""}, 
		lazy: false,
		relative: true,
		position: 'top left',
		offset: [-10, 320],
		effect: 'fade', //toggle is default
		onBeforeShow: function() {
			if (!navFooterExploreLoaded) { 
				$('#navFooterExploreToolTip .scrollableFooterGallery').load('/OnosSiteBase/wrap/theme/includes/incNavFooterExplore.aspx', function() {
					navFooterExploreLoaded = true;
				});				
			}
			$('#navFooterExplore').addClass('active');
		},
		onHide: function() {
			$('#navFooterExplore').removeClass('active');
		}
	});
	
	$("#navFooterEventCal").tooltip({ 
		events: {
			def:"click,",
			tooltip:""}, 
		lazy: false,
		relative: true,
		position: 'top left',
		offset: [-10, 160],
		effect: 'fade', //toggle is default
		onBeforeShow: function() {
			$('#navFooterEventCal').addClass('active');
			},
		onHide: function() {
			$('#navFooterEventCal').removeClass('active');
			}
	});

	//CLOSE class for tooltips
	$(".close").click(function() { 
		$(this).parent().prev().tooltip().hide();
	}); 
	
	//special CLOSE id for explore tooltip
	$('#closeGallery').mouseover(function() {
		$('#closeGallery').addClass('active');
	});	
	$('#closeGallery').mouseout(function() {
		$('#closeGallery').removeClass('active');
	});	
	

	// toggle for email/search forms in header
	$('.toggleHeaderForm').click(function(){
	   $('#formHeadEmail').toggle();
	   $('#formHeadSearch').toggle();
	});
	

	//GALLERY WIDGET thumbnails and background photo changer
	$("a[id^='thumb']").click(function() {
		$("a[id^='thumb']").removeClass('active');
		$(this).addClass('active');
		if ($(this).attr('rel')=="") {
			//$("#homegallery").html("<img src=images/home_gallery_photo1.jpg />");
		}
	});	

	// enable simple overlay for img, a, div tags
	$("img[rel]").overlay({ expose: '#f1f1f1' }).addClass("pointer");
	$("a[rel]").overlay({ expose: '#f1f1f1' }).addClass("pointer");
	$("div[rel]").overlay({ expose: '#f1f1f1' }).addClass("pointer");	

	// lodging page photo gallery
	// html content to swap in/out for each item we want to compare

	$("*[class^='thumbGallery linkGalleryThumb']").click(function() {
		$("*[class^='thumbGallery linkGalleryThumb']").removeClass('active');
		$(this).addClass('active');
		$(".txtGallery").html($(this).attr("title"));
		$(".boxGalleryPhoto img").attr("src",$(this).attr("imgURL"));
	});	

});

var iLoadCount=0;
function twitterLoadCallback() {
	if (TWTR) loadTweets();
	else {
		iLoadCount++;
		if (iLoadCount < 10) setTimeout('twitterLoadCallback()', 2000);
	}
}

function loadTweets() {	
	var oTweets = new TWTR.Widget({
		id: 'twitterWidget',
		version: 2,
		type: 'profile',
		rpp: 5,
		interval: 6000,
		width: 250,
		height: 260,
		theme: {
		shell: {
			background: '#ffffff',
			color: '#352f25'
			},
		tweets: {
			background: '#ffffff',
			color: '#352f25',
			links: '#c36a05'
			}
		},
		features: {
		scrollbar: true,
		loop: false,
		live: false,
		hashtags: true,
		timestamp: true,
		avatars: false,
		behavior: 'all'
		}
	});		
	if (oTweets) oTweets.render().setUser('onoseyewear').start();				
	socialTwitterWidgetLoaded = true;
}

function openEbook() { 
	window.open("/ebook", "propertyFinder", "width=1010,height=500, top=50, left=100, resizable=no, scrollbars=no, toolbar=no"); 
}


function openVideoModal(iWhich) {
	if ( !$('#videoModal').length) {
		$('<div id="videoModal"></div>').appendTo( $('BODY') );
	}
	$('#videoModal').load('/OnosSiteBase/wrap/theme/includes/videoGalleryModal.aspx?vid='+iWhich);
		
}

