// Activate fancybox
$('#hidden-fancybox-button').fancybox({
	overlayColor       : '#000000',
	overlayOpacity     : 0.8,
	hideOnContentClick : false,
	hideOnOverlayClick : true,
	type               : 'iframe',
	autoScale		   : true
});

// Function to open a popup window
var popCounter = 0;
function launchPopupWindow(documentUrl, width, height) {
	//$.fn.fancybox.defaults.width  = (width  == 'undefined') ? 820 : parseInt(width);
	//$.fn.fancybox.defaults.height = (height == 'undefined') ? 661 : parseInt(height);
	//$.fn.fancybox.defaults.width  = 820;
	//$.fn.fancybox.defaults.height = (height == 'undefined') ? 661 : parseInt(height);
	//$('#hidden-fancybox-button').attr('href', documentUrl);
	//$('#hidden-fancybox-button').click();
	if(isNaN(width)) { width = 750; }
	if(isNaN(height)) { height = 620; }
	var winl = (screen.width  - width)/2;
	var wint = (screen.height - height)/2;
	var resizable = height > 670 ? '1' : '0';
	var scrollbars = height > 670 ? '1' : '0';
	window.open(documentUrl, 'citroenWindow' + (++ popCounter), 'width='+ width +',height='+ (height > 670 ? 661 : height) +',left='+ winl +',top='+ wint +',status=no,menubar=no,directories=no,toolbar=no,resizable='+resizable+',scrollbars='+scrollbars);
}

// Function to track page views:
function trackPageView($pageNumber) {
	if(pageTracker) {
		pageTracker._trackPageview($pageNumber);
		// alert("Track page view: " + $pageNumber);
	}
}

// Function to keep UI Elements in place
function alignUI() {
	$(window).resize(function() {
		// Facebook plugin
		var $ifp = $('iframe');
		if($ifp.length > 0) {
			var t = $(document).height()  - 75;
			if(t < 570) {
				t = 570;
			}
			$ifp.css({top : t});

			// Min-height
			var h = $('#flash-client-wrapper').height();
			if(h < 750) {
				h = 750;
			}

			$('#book').css('height', h +'px');
		}
	});
}

// Align facebook plugin
$(document).ready(function() {
	alignUI();
	$(window).resize();
});
