var _gaq = _gaq || [];

$(document).ready(function () {
	// Highlight active path
	var path = location.pathname;
	if (path) {
		$('a[href$="' + path + '"]').addClass('active').parents().filter("li").addClass("active");
	}

	var windowHeight = $(window).height();
	$("a[rel='donate']").click(function () {
		window.open(this.href, "Donate", "status=1, resizable=1, scrollbars=1, width=560, height=" + windowHeight);
		return false;
	});

	// Gallerific

	var onMouseOutOpacity = 0.67;

	$('#thumbs ul.thumbs li').opacityrollover({
		mouseOutOpacity: onMouseOutOpacity,
		mouseOverOpacity: 1.0,
		fadeSpeed: 'fast',
		exemptionSelector: '.selected'
	});

	try {

		var gallery = $('#thumbs').galleriffic({
			delay: 3000, // in milliseconds
			numThumbs: 10, // The number of thumbnails to show page
			preloadAhead: 2, // Set to -1 to preload all images
			enableTopPager: false,
			enableBottomPager: false,
			maxPagesToShow: 7,  // The maximum number of pages to display in either the top or bottom pager
			imageContainerSel: '#slideshow', // The CSS selector for the element within which the main slideshow image should be rendered
			controlsContainerSel: '#controls', // The CSS selector for the element within which the slideshow controls should be rendered
			captionContainerSel: '#caption', // The CSS selector for the element within which the captions should be rendered
			loadingContainerSel: '#loading', // The CSS selector for the element within which should be shown when an image is loading
			renderSSControls: true, // Specifies whether the slideshow's Play and Pause links should be rendered
			renderNavControls: true, // Specifies whether the slideshow's Next and Previous links should be rendered
			playLinkText: 'Play',
			pauseLinkText: 'Pause',
			prevLinkText: 'Previous',
			nextLinkText: 'Next',
			nextPageLinkText: 'Next &rsaquo;',
			prevPageLinkText: '&lsaquo; Prev',
			enableHistory: false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes
			enableKeyboardNavigation: true, // Specifies whether keyboard navigation is enabled
			autoStart: true, // Specifies whether the slideshow should be playing or paused when the page first loads
			syncTransitions: false, // Specifies whether the out and in transitions occur simultaneously or distinctly
			defaultTransitionDuration: 1000, // If using the default transitions, specifies the duration of the transitions
			onSlideChange: function (prevIndex, nextIndex) {
				// 'this' refers to the gallery, which is an extension of $('#thumbs')
				this.find('ul.thumbs').children()
								.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
								.eq(nextIndex).fadeTo('fast', 1.0);
			}, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
			onPageTransitionOut: function (callback) {
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn: function () {
				this.fadeTo('fast', 1.0);
			}
		});
	}
	catch (e) { }

	// Google Analytics
	var UACode = "UA-8258713-1"; // Default Code

	// Pivot around the current site
	var host = window.location.hostname.replace("www.", "");

	// Change the code based on the hostname
	switch (host) {
		case "fbph.com":
			UACode = "UA-8258713-1";
			break;
		case "breasthealthinternational.com":
			UACode = "UA-16141624-1";
			break;
		case "uk.breasthealthinternational.com":
			UACode = "UA-16141624-2";
			break;
		case "it.breasthealthinternational.com":
			UACode = "UA-16141624-3";
			break;
		case "de.breasthealthinternational.com":
			UACode = "UA-16141624-4";
			break;
		case "prostatehealthinternational.com":
			UACode = "UA-16141627-1";
			break;
	}

	// DEBUG:
	// window.status = host + ": " + UACode;

	_gaq.push(['_setAccount', UACode]);
	_gaq.push(['_setDomainName', '.' + host]);
	_gaq.push(['_trackPageview']);

	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
});

