$(document).ready(function() {
	// Snowflakes
	// swfobject.embedSWF("/App_Themes/Burris/Flash/BurrisSnow.swf", "fallingsnowflakes", "280", "85", "9.0.0");

	// Accordions
	$("#directions > ul:first").addClass("accordion");
	$("#directions > ul:first > li:first").addClass("active");
	// "<a href='#'></a>"
	$(".accordion").accordion({ event: 'click', header: 'a', autoheight: false });
	$("#accordion").accordion({ event: 'click', header: 'h3', autoheight: false, active: false, collapsible: true, alwaysOpen: false });

	// Panels
	panels({ rootClass: "panelcontainer", childElement: "li", initialIndex: 0 }, null);

	$("ul.top-nav li:first", "#header").addClass("first");

	// Tabs
	$("#tabs").tabs();

	// Cycle the homepage featured items
	$('#featured').cycle({
		fx: 'blindY',
		easing: 'easeInQuart',
		timeout: 6000,
		pause: true,
		cleartypeNoBg: true
	});

	// Carousels
	$("#mycarousel").jcarousel({ scroll: 1, wrap: "both" });

	// Navigation highlights
	// Using the current path (e.g. /Section/Page)
	var path = location.pathname;

	// Handle links to the current path
	if (path) {
		$('a[href$="' + path + '"]').parents().filter('li').addClass('active');
	}

	$(".forms li").corners();

	// Handle links to parts of the current path
	var parts = path.split('/')
	for (i = 0; i < parts.length; i++) {
		if (parts[i].length > 0) {
			$('a[href$="/' + parts[i] + '"]').addClass('active');
		}
	}

	// Not a slider anymore... but tooltips!
	$(".slider div.details").hide();
	$(".slider .contact").each(function() {
		if ($(this).find("div.details").text()) {
			$(this).addClass("hasTooltip").corners().qtip({
				content: $(this).find("div.details").html(), show: { delay: 0 }, position: { corner: { tooltip: 'leftBottom' }, adjust: { x: 6, y: -20} }, style: { width: 440, border: { width: 6, radius: 5, color: "#003488" }, tip: { corner: 'leftBottom', color: '#003488'} }
			});
		}
		else {
			$(this).addClass("hasNoTooltip");
		}
	});

	// Play vimeo videos inline
	$('a[href*="vimeo."]', '#sidebar').each(function() {
		// Grab video ID from the url
		var videoID = $(this).attr('href').match(/vimeo\.com\/(.+)+/);
		videoID = videoID[1];

		// Create content using url as base
		$(this).qtip(
		  {
		  	// Create content DIV with unique ID for swfObject replacement
		  	content: '<div id="vimeo-embed-' + videoID + '">You need Flash player 8+ to view this video.</div>',
		  	position: {
		  		corner: {
		  			tooltip: 'rightMiddle', // ...and position it center of the screen
		  			target: 'leftMiddle' // ...and position it center of the screen
		  		},
		  		adjust: { x: -6, y: 0 }
		  	},
		  	show: {
		  		when: 'click', // Show it on click...
		  		solo: true // ...and hide all others when its shown
		  	},
		  	hide: 'unfocus', // Hide it when inactive...
		  	style: {
		  		width: 535,
		  		height: 284,
		  		padding: 0,
		  		tip: true,
		  		name: 'dark',
		  		border: { width: 6, radius: 16, color: "#0E327E" }
		  	},
		  	api: {
		  		onRender: function() {
		  			// Setup video paramters
		  			var params = { allowScriptAccess: 'always', allowfullScreen: 'true' };
		  			var attrs = { id: 'vimeo-video-' + videoID };

		  			// Embed the youtube video using SWFObject script
		  			swfobject.embedSWF('http://vimeo.com/moogaloop.swf?clip_id=' + videoID + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=0E327E&amp;fullscreen=1&amp;autoplay=1', 'vimeo-embed-' + videoID, '505', '284', '9', null, null, params, attrs);
		  		},

		  		onHide: function() {
		  			// Pause the video when hidden
		  			//var playerAPI = this.elements.content.find('#vimeo-video-' + videoID).get(0);
		  			//if (playerAPI && playerAPI.pauseVideo) playerAPI.pauseVideo();
		  		}
		  	}
		  }).attr('href', '#').click(function() {
		  	return false;
		  });
	});

	$("a[href*='/Media/Flash/']", "#sidebar").each(function() {
		var swf = $(this).attr("href");
		$(this).qtip({
			content: "<div style='background: #003488; color: White; font-weight: bold; padding: 4px;'>Click and drag to expore:</div><div id='panorama' style='margin: 0; padding: 0; overflow: hidden;'>Loading...</div>",
			show: { when: "click", solo: true },
			hide: { fixed: true, delay: 500 },
			position: { corner: { target: 'leftMiddle', tooltip: 'rightMiddle' }, adjust: { x: 0, y: 0} },
			style: { width: 760, height: 350, padding: 0, border: { width: 6, radius: 5, color: "#003488" }, tip: { corner: 'rightMiddle', color: '#003488'} },
			api: {
				onRender: function() {
					var params = { wmode: "transparent" };
					var attrs = {};
					// Embed the flash video using SWFObject script
					swfobject.embedSWF(swf, "panorama", "760", "350", "8", null, null, params, attrs);
				}
			}
		});
	}).attr('href', '#').attr("onclick", "return false;");

	// Post Salesforce contact form to a the Web-To-Lead URL
	$("#salesforcesubmit").click(function() {
		$("#form1").attr("action", "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8");
	});
});
