$(document).ready(function() {
	$("a.fancybox").fancybox({
				'zoomSpeedIn' : 300,
				'zoomSpeedOut' : 300,
				'overlayShow' : false
			});
	viewportHeight = window.innerHeight ? window.innerHeight : $(window)
			.height();
	viewportWidth = window.innerWidth ? window.innerWidth : $(window).width();
	if (viewportWidth >= 800 && viewportHeight >= 570) {
		$("a.timetable").fancybox({
					'zoomSpeedIn' : 0,
					'zoomSpeedOut' : 0,
					'overlayShow' : false,
					'frameWidth' : 781,
					'frameHeight' : 553,
					'enableEscapeButton' : false,
					'hideOnContentClick' : false,
					'hideOnOverlayClick' : false
				});
	} else {
		$("a.timetable").click(function(e) {
			window
					.open(
							this.href,
							'designer',
							'width=800,height=570,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,');
			return false;
		});
	}
});

/**
 * 
 * Registration.
 * 
 */
var Registration = {
	init : function(idPartsArray) {
		for (var i = 0; i < idPartsArray.length; i++) {
			// initial hide of all divs
			if (!$('#' + idPartsArray[i] + 'Radio').attr('checked')) {
				$('#' + idPartsArray[i] + 'Div').hide();
			} else {
				$('#' + idPartsArray[i] + 'Div').addClass('divIsExpanded');
			}
			// append listeners for radios
			$('#' + idPartsArray[i] + 'Radio').click(function() {
						Accordion.toggle($(this).val(), idPartsArray);
					});
		}
	}
};

/**
 * 
 * Terms and conditions accordion.
 * 
 */
var TermsAccordion = {
	init : function(idPartsArray) {
		for (var i = 0; i < idPartsArray.length; i++) {
			// initial hide of all divs but first
			if (i === 0) {
				$('#' + idPartsArray[i] + 'Div').addClass('divIsExpanded');
			} else {
				$('#' + idPartsArray[i] + 'Div').hide();
			}
			// append listeners for links
			$('#' + idPartsArray[i] + 'Link').click(function() {
				Accordion.toggle($(this).attr('id').replace(/Link/g, ''),
						idPartsArray);
			});
		}
	}
};

var Accordion = {
	toggle : function(divIdPart, idPartsArray) {
		// hide others
		for (var j = 0; j < idPartsArray.length; j++) {
			if (idPartsArray[j] != divIdPart
					&& $('#' + idPartsArray[j] + 'Div')
							.hasClass('divIsExpanded')) {
				$('#' + idPartsArray[j] + 'Div').removeClass('divIsExpanded')
				$('#' + idPartsArray[j] + 'Div').slideUp(500, function() {
							$('#' + divIdPart + 'Div').slideDown(500);
							$('#' + divIdPart + 'Div')
									.addClass('divIsExpanded');
						});
				return;
			}
		}
		// show matching div
		$('#' + divIdPart + 'Div').slideDown(500);
		$('#' + divIdPart + 'Div').addClass('divIsExpanded');
	}
};

/*----------------------------------------------------------------------------*/
/**
 * ie6 hover fix
 */
/*----------------------------------------------------------------------------*/
sfHover = function() {
	var sfEls = document.getElementById("box").getElementsByTagName("DIV");
	for (i = 0; i < sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			this.className += " sfhover";
		};
		sfEls[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp(" sfhover\\b"),
					"");
		};
	}
	sfEls = document.getElementById("box_spacer").getElementsByTagName("DIV");
	for (i = 0; i < sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			this.className += " sfhover";
		};
		sfEls[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp(" sfhover\\b"),
					"");
		};
	}
};
if (window.attachEvent) {
	window.attachEvent("onload", sfHover);
}

nostalgiaConversionPixel = function() {
	$("body").append('<img border="0" width="1" height="1" '
			+ 'src="https://tracking.adjug.com/AdJugTracking/Tracker.aspx?'
			+ 'CONVERSION_SC/PixelID=762' + '&#38;ConversionCount=1'
			+ '&#38;ConversionAmount=0' + '&#38;CacheBuster='
			+ Math.floor(Math.random() * 99999999) + '" />');
}
