jQuery(document).ready( function($) {
	$('a.popup-trigger').click( function() {
		var rel = $(this).attr('rel'),
			href = $(this).attr('href') + 'details';

		$('li', $(this).parents('ul')).removeClass('current');
		$(this).parents('li').addClass('current');

		$('.MicrositeHomePage .content').hide();

		$(rel + '> *').remove();
		
		$(rel).load(href, function() {
			$(rel).css('top', null).find('.inner').css('overflow', 'hidden');
			
			$(rel).slideDown( function() { $('.inner', $(rel)).css('overflow', 'auto');	});
			if ($('#iscroll').length > 0) {
//				var iscroller = new iScroll('iscroll', { zoom: false, hScroll: false });
			}
			$.fn.topImageHooks();
			$.fn.formHooks();
		});
		return false;
	});
	$.fn.topImageHooks = function() {
		$('.top-images img[rel]').click( function() {
			$('.top-images-large').show();
			$('#inner .padder').css('visibility', 'hidden');
			$($(this).attr('rel')).show().click( function() {} );
			$('a.btn-close-image').show().click( function() {
				$('img', $(this).parents('.top-images-large')).hide();
				$(this).parents('.top-images-large').hide();
				$('#inner .padder').css('visibility', 'visible');
			});
		});
	};
	$.fn.initThumbnailScroller = function() {
		$('.jThumbnailScroller').thumbnailScroller({
			scrollerType:"hoverPrecise",
			scrollerOrientation:"horizontal",
			scrollSpeed:2,
			scrollEasing:"easeOutCirc",
			scrollEasingAmount:600,
			acceleration:4,
			scrollSpeed:800,
			noScrollCenterSpace:10,
			autoScrolling:0,
			autoScrollingSpeed:2000,
			autoScrollingEasing:"easeInOutQuad",
			autoScrollingDelay:500
		});
	}
	$.fn.initThumbnailScroller();
	
	if ($('#iscroll').length > 0) {
//		var iscroller = new iScroll('iscroll', { zoom: false, hScroll: false });
	}

	$.fn.topImageHooks();

//	var bubble = new google.bookmarkbubble.Bubble();
//	bubble.showIfAllowed();

	$(window).bind('resize', (function() {
		return function() {
			var $window = $(window), cw = $window.width(), ch = $window.height(), dX = 0, dY = 0, footerTop = 157;
			if ((this.width) && (this.height)) {
				if (((ch < 768) && (this.height >= 768)) || ((ch > 768) && (this.height <= 768))) {
					$.fn.initThumbnailScroller();
				}
			}
			this.width = $(window).width();
			this.height = $(window).height();
		};
	})());

});


