Cufon.set('hover', true);

/* fontFamily: 'Gotham Bold' */
Cufon.replace('.nav ul li a', {fontFamily: 'MCG-Bold'} );
Cufon.replace('div.header div.form form fieldset a.input-button',{fontFamily: 'MCG-Bold'});
Cufon.replace('div.intro ul.tab-list li a span',{
	hoverables: { span: true, small: true },
	fontFamily: 'MCG-Bold'
});
Cufon.replace('div.aside div.article.calendar p',{fontFamily: 'MCG-Bold'});
Cufon.replace('div.article.newsletter h3',{fontFamily: 'MCG-Bold'});
Cufon.replace('div.article ul.nav-list li a', {fontFamily: 'MCG-Bold'});
Cufon.replace('div.article.calendar ul.week li h4',{fontFamily: 'MCG-Bold'});
Cufon.replace('div.article.calendar ul.nav li',{fontFamily: 'MCG-Bold'});
//Cufon.replace('div.aside div.article.login p a',{fontFamily: 'MCG-Bold'});
Cufon.replace('div.aside div.article.login h3',{fontFamily: 'MCG-Bold'});
Cufon.replace('div.article ul.production-list li.season h3 span', {fontFamily: 'MC'});
Cufon.replace('h1', {fontFamily: 'MC'});
Cufon.replace('div.section.content.tokomc ul.tokoagenda li h2 span', {fontFamily: 'MC'});
Cufon.replace('div.section.content.tokomc ul.tokoagenda li h1', {fontFamily: 'MC'});


/*
Cufon.replace('.ticketing_tab_active', { fontFamily: 'MCG-Bold'});
Cufon.replace('.ticketing_tab_nonactive', { fontFamily: 'MCG-Bold'});
Cufon.replace('.ticketing_tab_active_login', { fontFamily: 'MCG-Bold'});
*/
config = window.config || {}
MC = window.MC || {}

/* --------------------------------------------------------------------------------------------------------------------------- */

/* configurable properties */
config = 
{
		debug			:	false,					// if debug mode is needed then true
		production		:	false,					// if this file is in production (live)
		easing			:	'easeInOutQuad',		// default easing method
		jsEnabledClass	:	'hasJS',				// default class on body if Javascript is enabled
		ie6BodyClass	:	'ie6',					// default class on body if IE6 is detected
		ie7BodyClass	:	'ie7',					// default class on body if IE7 is detected
		ie8BodyClass	:	'ie8',					// default class on body if IE7 is detected
		prefixBehaviour	:	'bh-',					// default html className prefix to add JS behaviour (default is 'bh-')
		searchResults	:	'autosuggest.fragment',	// url to autoSuggest result server feedback (JSON / plain text)
		ajaxSuffix		:	'ajax=true'
}
/* --------------------------------------------------------------------------------------------------------------------------- */

MC = {
	
	config: config,
	
	init: function()
	{
		// global methods:
		this.Browser.init();						// initializes Browser specific methods
		this.Utils.init();							// initializes Utils set
		this.Font.init();							// initializes MC Font / font optimization
		this.FormFields.defaultValue();				// initializes default formfield value method
		this.Linkable.set();
		
		// component specific methods:
		this.MCPost.toggleForm();					// toggles MCPost form
		this.MCPost.init(250,2000,-1,-1);			// initializes MCPost form params: fadeSpeed,successTimeout, errorTimeout, validationTimeout
		this.Login.toggleForm();					// toggles Login form
		this.Login.init(250,2000,-1,-1);			// initializes Login form params: fadeSpeed,successTimeout, errorTimeout, validationTimeout
		this.Carousel.init();						// initializes Carousel slider on homepage
		this.Calendar.init();						// initializes Calendar hover / click handler
		this.Mosaic.init();							// toggles hover on Mosaic list item
		this.Overlay.load();						// set overlay / modal screen 
		this.Search.Results.init();					// initializes Search Results specific behaviour
		this.Search.Calendar.init();				// initializes Search Calendar specific behaviour
		this.Search.News.init();				    // initializes Search News specific behaviour
		this.Search.Productions.init();				// initializes Search Productions specific behaviour
		this.Search.autoSuggest();					// adds auto suggest handler to search input field
		this.Details.toggle();						// enables toggle detail information
		this.TOKOMC.overlay();	

	},

	TOKOMC :{
		overlay: function(){
			$('.toko-event').each(function(){

			config = {    
			     over: function(){
					$(this).parent().find('div.overlay').fadeIn();	
				},    
			     timeout: 0, // number = milliseconds delay before onMouseOut    
			     out: function(){
					$(this).parent().find('div.overlay').fadeOut();	
				}   
			};

			$(this).hoverIntent( config )
				
				$(this).mousemove(function(e){
					var off = $(this).offset();	
					$(this).parent().find('div.overlay').css({
								top: (e.pageY - off.top + 'px') , 
								left: (e.pageX - off.left + 180 + 'px')
					});	
				})	
			})	
		}
	},
	
	Font: {
		
		init: function()
		{
			$("h1:contains('MC')").each(function() {
		        	$(this).html($(this).html().replace(/\bMC\b/gi, "<span class='logo'>M</span>"));
            // Cufon.replace('h1',  { fontFamily: 'MC' }); 
			});
			Cufon.replace('h1',  { fontFamily: 'MC' }); 
			this.CufonInput();
			this.optimize();
		},
		
		optimize: function()
		{
			/*
			 * optimize Webkit font rendering for text with font-size >= 15px
			 */
			if ( MC.Browser.name.webkit) 
			{
				$('h1, h2, h3, h4, p').each(
					function()
					{
						var fontSize = $(this).css('font-size');
						fontSize = parseFloat(fontSize, 10);
						
						if ( fontSize >= '15') $(this).css({
							'text-rendering': 'optimizeLegibility'
						});				
					}
				);
			} // end if
		},
		
		CufonInput: function()
		{
			$('div.header div.form form fieldset input.button').each(function()
			{
				$(this).hide().after('<a class="input-button" href="#" />').next('a.input-button').html($(this).val()).click(function(e){
					e.preventDefault();
			        $(this).prev('input.button').click();
			    });
			});
		}
		
	},
	
	Browser: {
		name: null,
		isIE: false,
		init: function() 
		{
			$('body').addClass(MC.config.jsEnabledClass);
			var Browser = MC.Browser;
			Browser.name = $.browser;
			if (Browser.name.msie) Browser.isIE = true;
			if (Browser.name.msie && Browser.name.version.substr(0,1) == 6) {
				Browser.ie6();				
			}
			if (Browser.name.msie && Browser.name.version.substr(0,1) == 7) {
				Browser.ie7();				
			}	
			if (Browser.name.msie && Browser.name.version.substr(0,1) == 8) {
				Browser.ie8();				
			}
			if (Browser.name.webkit) {
				Browser.webkit();				
			}			
		},
	
		ie6: function()
		{
			$('body').addClass(config.ie6BodyClass);
		},
		
		ie7: function()
		{
			$('body').addClass(config.ie7BodyClass);
		},
		ie8: function()
		{
			$('body').addClass(config.ie8BodyClass);
		},
		webkit: function()
		{
			$('body').addClass('webkit');
		}
	},
	
	FormFields: {
		defaultValue:function(){
			$('input:text, input:password').each(function()
			{
				$(this).addClass("no-focus");
				
				if ($(this).hasClass('label-value')) {
					var labelElem = $(this).parent().find('label');
					$(labelElem).addClass('text-only');
					var labelValue = $(labelElem).html();
					$(this).val(labelValue);
				}
				
				if (!$(this).hasClass('hold-value')) { // exceptions
					var initValue = $(this).val();
					$(this).focus(function(){
						$(this).removeClass("no-focus");
						if($(this).val() == initValue) $(this).val('');
					})
					$(this).blur(function(){
						if ($(this).val() == "") $(this).addClass("no-focus");	// set class no-focus only if value is cleared
						if($(this).val() == '') $(this).val(initValue);
					})
				}
			});
			
			$('textarea').each(function()
			{
				$(this).addClass("no-focus");
				if (!$(this).hasClass('hold-value')) { // exceptions
					var initValue = $(this).val();
					$(this).focus(function(){
						$(this).removeClass("no-focus");
						if($(this).val() == initValue) $(this).val('');
					})
					$(this).blur(function(){
						if ($(this).val() == "") $(this).addClass("no-focus");	// set class no-focus only if value is cleared
						if($(this).val() == '') $(this).val(initValue);
					})
				}			
			});
			
			$('select').each(function()
			{
				$(this).addClass("no-focus");
				$(this).focus(function(){
					$(this).removeClass("no-focus");
				});
				$(this).blur(function(){
					$(this).addClass("no-focus");
				});
			});
		}
	},
	
	MCPost: {
		init: function(fadeSpeed,successTimeout, errorTimeout, validationTimeout){
			var MCPost = this;
			this.fadeSpeed = fadeSpeed;
			this.$newsLetterForm = $('div.article.teaser.newsletter form');
			this.currentMessageSelector = null;
			this.messageWidth=null;
			
			$('input[type=submit]',this.$newsLetterForm).click(function(event){
				event.preventDefault();
				if((checkResult=MCPost.check())==null){
					$.ajax({
						url: MCPost.$newsLetterForm.attr('action')+'?'+MCPost.serialize(MCPost.getValueMap()),
						dataType: 'json',
						async: false,
						success: function(json) {
							MCPost.showMessage('h3#success',fadeSpeed,successTimeout,function(){
								$('h3:first',MCPost.$newsLetterForm.parent()).trigger('click');
							});
						},
						error:function() {
							MCPost.showMessage('h3#failure',fadeSpeed,errorTimeout,null);
						}
					});
				}else{
					MCPost.showMessage('h3#'+checkResult,fadeSpeed,validationTimeout,null);
				}
			});
		},
		check: function(){
			status=null;
			var fields = this.getValueMap();
			
			var noName = fields.receiverName==null;
			var noEmail = fields.receiverEmail==null;
			var noAddress = fields.receiverAddress==null && fields.receiverPostalCode==null && fields.receiverCity==null;
			var partialAddress = !noAddress && (fields.receiverAddress==null || fields.receiverPostalCode==null || fields.receiverCity==null);
			
			if(noName){
				status='noName'; 
			}else if(noEmail && noAddress){
				status='noAddress'; 
			}else if(partialAddress){
				status='partialAddress'; 
			}
			
			return status;
		},
		getValueMap:function(includeEmpty, emptyValue){
			var all = (includeEmpty!=null && includeEmpty==true ? true : false);
			var nill = (emptyValue!=null ? emptyValue : null);
			
			var $newsLetterForm = $('div.article.teaser.newsletter form');
			var defaultsMap = {};
			$('label',$newsLetterForm).each(function(index,labelElem){
				$labelElem = $(labelElem);
				defaultsMap[$labelElem.attr('for')]=$labelElem.text();
			});
			var fields = $newsLetterForm.serializeArray();
			var fieldMap = {};
			for(i=0;i<fields.length;i++){
				var isNotEmpty = fields[i].value!=defaultsMap[fields[i].name];
				if(all || isNotEmpty ){
					fieldMap[fields[i].name]=(isNotEmpty ? fields[i].value : nill);
				}
			}
			return fieldMap;
		},
		serialize:function(fieldMap){
			var serializedMap = '';
			for(key in fieldMap){
				serializedMap+=(serializedMap.length>0 ? '&' : '')+escape(key)+'='+escape(fieldMap[key]);
			}
			return serializedMap;
		},
		showMessage:function(messageSelector, fadeSpeed, timeout, callBack){
			var MCPost = this;
			if(this.currentMessageSelector != messageSelector){
				if(this.currentMessageSelector==null){
					$('div.newsletter.message',this.$newsLetterForm).slideDown(fadeSpeed,function(){
							MCPost.messageWidth = $('h3.message.hidden',MCPost.$newsLetterForm).width();
							$('h3.message',MCPost.$newsLetterForm).width(MCPost.messageWidth+'px');//width:159px;
							MCPost.setMessage(messageSelector, fadeSpeed, timeout, callBack);
						
					});
					if(this.messageWidth!=null){
						this.currentMessageSelector = messageSelector;
						if(this.currentMessageSelector != null) $(this.currentMessageSelector,this.$newsLetterForm).fadeIn(fadeSpeed);
					}

				}else if(messageSelector==null){
					if(this.currentMessageSelector != null) $(this.currentMessageSelector,this.$newsLetterForm).fadeOut(fadeSpeed);
					this.currentMessageSelector = messageSelector;
					$('div.newsletter.message',this.$newsLetterForm).slideUp(fadeSpeed);
					this.setMessage(messageSelector, fadeSpeed, timeout, callBack);
				}else{
					this.setMessage(messageSelector, fadeSpeed, timeout, callBack);
				}
			}else{
				this.setMessage(messageSelector, fadeSpeed, timeout, callBack);
			}
		},
		setMessage: function(messageSelector, fadeSpeed, timeout, callBack){
			var MCPost = this;
			if(this.currentMessageSelector != messageSelector){
				if(this.currentMessageSelector != null) $(this.currentMessageSelector,this.$newsLetterForm).fadeOut(fadeSpeed);
				this.currentMessageSelector = messageSelector;
				if(this.currentMessageSelector != null) $(this.currentMessageSelector,this.$newsLetterForm).fadeIn(fadeSpeed);
			}
			if(timeout>0){
				setTimeout(function(){
					MCPost.showMessage(null,fadeSpeed,-1,null);
					if(callBack!=null){
						callBack.call(this);
					}
				},timeout);
			}
		},
		
		toggleForm: function()
		{
			var MCPost = this;
			$('div.article.teaser.newsletter.bh-toggle-form').each(function()
			{
				$(this).find('h2, h3').css({cursor: 'pointer'});
				$(this).addClass('minimized');
				$(this).find('form').toggle();
								
				$(this).find('h2, h3').click(function()
				{
					if ( $(this).parent().hasClass('minimized') ) {
						$(this).parent().find('form').slideDown({
							easing: "easeInOutExpo",
							time: 600
						});
					} else 
					{
						MCPost.showMessage(null,MCPost.fadeSpeed,-1,null);
						$(this).parent().find('form').slideUp({
							easing: "easeInOutExpo",
							time: 600
						})
					}
					
					$(this).parent().toggleClass('minimized');	
				});
			});			
		}
	},

        
	Login: MCE.LoginForm,
	LoginDeprecated: {
		init: function(fadeSpeed,successTimeout, errorTimeout, validationTimeout){
			var Login = this;
			this.fadeSpeed = fadeSpeed;
			this.$loginForm = $('div.article.teaser.login form');
			this.currentMessageSelector = null;
			this.messageWidth=null;
			this.$loginCaption = $('div.article.teaser h3#login');
			this.$logoutCaption = $('div.article.teaser h3#logout');
			this.originalLogoutCaptionHtml = this.$logoutCaption.text();
			this.loggedInName=null;
			
			$('input[type=submit]',this.$loginForm).click(function(event){
				event.preventDefault();
				if((checkResult=Login.check())==null){
					Login.showMessage('h3#loggingIn',fadeSpeed,-1,null);
					$.ajax({
						url: Login.$loginForm.attr('action')+'?'+Login.serialize(Login.getValueMap()),
						dataType: 'json',
						async: true,
						success: function(json) {
							if(json.error!=null){
								Login.showMessage('h3#unsuccessfull',fadeSpeed,successTimeout,null);
							}else{
								Login.loggedInName = json.customer.first_name+' '+json.customer.last_name;
								Login.$logoutCaption.html(Login.originalLogoutCaptionHtml.replace("##NAME##",Login.loggedInName));
								Login.showMessage('h3#success',fadeSpeed,successTimeout,function(){
									Login.$loginCaption.trigger('click');
									Login.$loginCaption.fadeOut(Login.fadeSpeed);
									Login.$logoutCaption.fadeIn(Login.fadeSpeed);
								});
							}
						},
						error:function() {
							Login.showMessage('h3#failure',fadeSpeed,errorTimeout,null);
						}
					});
				}else{
					Login.showMessage('h3#'+checkResult,fadeSpeed,validationTimeout,null);
				}
			});
		},
		check: function(){
			status=null;
			var fields = this.getValueMap();
			
			var noEmail = fields.email==null;
			var noPassword = fields.password==null;
			var noCredentials = noEmail && noPassword;
			
			if(noCredentials){
				status='noCredentials'; 
			}else if(noEmail){
				status='noEmail'; 
			}else if(noPassword){
				status='noPassword'; 
			}
			
			return status;
		},
		getValueMap:function(includeEmpty, emptyValue){
			var all = (includeEmpty!=null && includeEmpty==true ? true : false);
			var nill = (emptyValue!=null ? emptyValue : null);
			
			var defaultsMap = {};
			$('label',this.$loginForm).each(function(index,labelElem){
				$labelElem = $(labelElem);
				defaultsMap[$labelElem.attr('for')]=$labelElem.text();
			});
			var fields = this.$loginForm.serializeArray();
			var fieldMap = {};
			for(i=0;i<fields.length;i++){
				var isNotEmpty = fields[i].value!=defaultsMap[fields[i].name];
				if(all || isNotEmpty ){
					fieldMap[fields[i].name]=(isNotEmpty ? fields[i].value : nill);
				}
			}
			return fieldMap;
		},
		serialize:function(fieldMap){
			var serializedMap = '';
			for(key in fieldMap){
				serializedMap+=(serializedMap.length>0 ? '&' : '')+escape(key)+'='+escape(fieldMap[key]);
			}
			return serializedMap;
		},
		showMessage:function(messageSelector, fadeSpeed, timeout, callBack){
			var Login = this;
			if(this.currentMessageSelector != messageSelector){
				if(this.currentMessageSelector==null){
					$('div.login.message',this.$loginForm).slideDown(fadeSpeed,function(){
							Login.messageWidth = $('h3.message.hidden',Login.$loginForm).width();
							$('h3.message',Login.$loginForm).width(Login.messageWidth+'px');//width:159px;
							Login.setMessage(messageSelector, fadeSpeed, timeout, callBack);
						
					});
					if(this.messageWidth!=null){
						this.currentMessageSelector = messageSelector;
						if(this.currentMessageSelector != null) $(this.currentMessageSelector,this.$loginForm).fadeIn(fadeSpeed);
					}

				}else if(messageSelector==null){
					if(this.currentMessageSelector != null) $(this.currentMessageSelector,this.$loginForm).fadeOut(fadeSpeed);
					this.currentMessageSelector = messageSelector;
					$('div.login.message',this.$loginForm).slideUp(fadeSpeed);
					this.setMessage(messageSelector, fadeSpeed, timeout, callBack);
				}else{
					this.setMessage(messageSelector, fadeSpeed, timeout, callBack);
				}
			}else{
				this.setMessage(messageSelector, fadeSpeed, timeout, callBack);
			}
		},
		setMessage: function(messageSelector, fadeSpeed, timeout, callBack){
			var Login = this;
			if(this.currentMessageSelector != messageSelector){
				if(this.currentMessageSelector != null) $(this.currentMessageSelector,this.$loginForm).fadeOut(fadeSpeed);
				this.currentMessageSelector = messageSelector;
				if(this.currentMessageSelector != null) $(this.currentMessageSelector,this.$loginForm).fadeIn(fadeSpeed);
			}
			if(timeout>0){
				setTimeout(function(){
					Login.showMessage(null,fadeSpeed,-1,null);
					if(callBack!=null){
						callBack.call(this);
					}
				},timeout);
			}
		},
		
		toggleForm: function()
		{
			var Login = this;
			var $loginDiv = $('div.article.teaser.login.bh-toggle-form');
			
			Login.originalLogoutCaption = $('>h3#logout',$loginDiv).html();
			
			//	$loginDiv = $(this);
				$loginDiv.find('h2, h3').css({cursor: 'pointer'});
				$loginDiv.addClass('minimized');
				$loginDiv.find('form').toggle();
								
				$loginDiv.find('h2, h3#login').click(function(){
					if ( $(this).parent().hasClass('minimized') ) {
						$(this).parent().find('form').slideDown({
							easing: "easeInOutExpo",
							time: 600
						});
					} else 
					{
						Login.showMessage(null,Login.fadeSpeed,-1,null);
						$(this).parent().find('form').slideUp({
							easing: "easeInOutExpo",
							time: 600
						})
					}
					$(this).parent().toggleClass('minimized');	
				});
				$loginDiv.find('h3#logout').click(function(){
					Login.$loginCaption.fadeIn(Login.fadeSpeed);
					Login.$logoutCaption.fadeOut(Login.fadeSpeed);
				});
		}
	},
	
	Details: {
		
		toggle: function()
		{
			if ( ! $('.bh-toggle-details').length > 0 ) return false;
			
			var toggleLink = {
				linkText:	$('.bh-toggle-details li.details h3').html().toLowerCase()+' &raquo',
				show:		'Toon ',
				hide:		'Verberg '
			}
			
			$('.bh-toggle-details li.details').hide();
			$('.bh-toggle-details li.details h3').remove();
			$('<li><h3><a href="#" class="link-toggle show">'+toggleLink.show+toggleLink.linkText+'</a></h3></li>').appendTo($('ul.contact-list:first'));
			
			$('a.link-toggle').click(function(e){
				e.preventDefault();
				
				$(this).hasClass('show') ? $(this).html(toggleLink.hide+toggleLink.linkText) : $(this).html(toggleLink.show+toggleLink.linkText);
				
				if ( $(this).hasClass('show') ) 
				{
					$('.bh-toggle-details li.details').slideDown({
						easing: "easeInOutExpo",
						time: 600
					})
				} else 
				{
					$('.bh-toggle-details li.details').slideUp({
						easing: "easeInOutExpo",
						time: 600
					})
				}
				
				//$('.bh-toggle-details li.details').toggle();
				$(this).toggleClass('show');
			});
			
		}
		
	},
	/*
	 *Mosaic parameters:
	 *<ol>
	 *	<li>the time to wait before triggering the hover event in ms</li>
	 *	<li>fade in speed in ms</li>
	 *	<li>fade out speed in ms</li>
	 *	<li>move in the Y direction only (optional)</li>
	 *</ol> 
	 */
	Mosaic: new Mosaic(500,200,150,false),
	
	/*
	 *Calendar parameters:
	 *<ol>
	 *	<li>the time to wait before triggering the hover event in ms</li>
	 *	<li>fade in speed in ms</li>
	 *	<li>fade out speed in ms</li>
	 *	<li>move in the Y direction only (optional)</li>
	 *</ol> 
	 */
	Calendar: new Calendar(1000,200,150,true),
	
	Linkable: {
		
		set: function()
		{
			$('.bh-linkable').each(function()
			{
				var target = $(this).find('a').attr('href');
				$(this).hover(
					function()
					{
						$(this).addClass('hover');
					},
					function()
					{
						$(this).removeClass('hover');
					}
				);
				$(this).click(function()
				{
					location.href = target;
				});
			});
		}
		
	},
	
	Search: {
		
		Results: {
			
			init: function()
			{
				if ( $('div.zoeken').length == 0  || $('div.zoeken a.link.more-results').length == 0 ) return false;


				var loadingContainer = $('<div class="article news loading"><div class="results-loading"></div></div>');
				if ($('body').hasClass('ie7')) loadingContainer = $('<div class="article news loading"><div class="pre-article"></div><div class="results-loading"></div></div>');
				
				var link = $('div.zoeken a.link.more-results').attr('href')
				var id = link.substring(0,link.indexOf('&page='))
				
				
				$(window).infinitescroll({
				    url: id + '&page=##PAGE##' +  '&' + MC.config.ajaxSuffix,					
				    triggerAt: 250,				
				    processData: this.processData,
				    insertAfter: 'div.content.zoeken div.article.news:last',
				    delay: 400	
				});
				
				$('div.section.content').bind('infinitescroll.beforesend', function(){
				    $('div.zoeken a.link.more-results').addClass('loading');					
					if ($('body').hasClass('ie7')) $('div.article.news').not(':last-child').removeClass('no-curl');
				});
				
				$('div.section.content').bind('infinitescroll.maxreached', function(){
					$('div.zoeken a.link.more-results').hide();
					MC.Utils.fixLastChild();
				});
				
				
				$('div.section.content').bind('infinitescroll.finish', function(){
					$('div.zoeken a.link.more-results').removeClass('loading');
					MC.Utils.fixLastChild();
					if ($.browser.msie) {
						MC.Utils.fixIE();
						$('div.article.news').not(':last-child').removeClass('no-curl');
					} 
				})
				
		
			},
				processData: function(data){
					$content = $('div.article.news',$(data.html));
					$content.find('div.divider-top-first').addClass('divider-top').removeClass('divider-top-first');
					return $content;
				}
	
		},
		
		autoSuggest: function(){
			
			$('div.bh-autosuggest input.field').hintbox(
			{
				url: MC.config.searchResults,
				autoDimentions: false,
				zIndex:	'1099',
				params: {},
				onListLoaded: function()
				{
					//$('div.hintbox_list_container').appendTo($('body'));
				},
				onBeforeListLoad: function()
				{
					//$('body > div.hintbox_list_container').remove();	
				}
			});
			
			$('body').click(function(e){
				if ( $(e.target).hasClass('hintbox_list_container') ) return;
				if ( $('div.hintbox_list_container').is(':visible') ) $('div.hintbox_list_container').hide();
			});
			
		},
		
		Calendar: {
			
			init: function(){
				if ( $('div.zoeken').length == 0  || $('div.zoeken a.link.more-dates').length == 0 ) return false;
				
				$firstDayLastWeek = $('div.section.content div.article.calendar ul.week:last > li:first a');
			        splitHref = $firstDayLastWeek.attr('href').split('/');
				firstDayLastWeekStr = splitHref[(splitHref.length-1)];
				year = new Number(firstDayLastWeekStr.substr(0,4));
				month = new Number(firstDayLastWeekStr.substr(5,2));
                var id = '/mc/home';
                if(window.location.href.indexOf('?')!=-1){
                	if(window.location.href.split('?')[1].indexOf('/mc/agenda')!=-1) id = '/mc/agenda';
                	if(window.location.href.split('?')[1].indexOf('/mc/theater')!=-1) id = '/mc/theater';
                }
				
				$(window).infinitescroll({
				    url: '?id='+id+'/##PAGE##&'+ MC.config.ajaxSuffix,					
				    page: { 'year': year, 'month': month },
				    getNextPage: function(curPage){ return { 'year':(curPage['month']<12? curPage['year']:curPage['year']+1), 'month':(curPage['month']<12? curPage['month']+1 : 1) };},
				    pageToString: function(page){ return page['year']+'-'+page['month']; },
				    processData: this.processData,
				    insertAfter: 'div.section.content div.article.calendar ul.week:last',
				    noAutoScroll: false,
				    fadeInSpeed: 500,
				    container: $(document),
				    triggerAt: 250,					// n px measured from bottom
					delay: 400						// time (delay) before triggering load
				});
				
				$('div.section.content').bind('infinitescroll.beforesend', function(){
					$('div.zoeken a.link.more-dates').addClass('loading');
					if ($('body').hasClass('ie7')) $('div.article.calendar').not(':last-child').removeClass('no-curl');
				});
				
				$('div.section.content').bind('infinitescroll.finish', function(){
					Cufon.replace('div.section.content div.article.calendar ul.week > li > h4 > a', {fontFamily: 'MCG-Bold'});					
					$('div.zoeken a.link.more-dates').removeClass('loading');
					MC.Utils.fixLastChild();
					if ($.browser.msie) {
						MC.Utils.fixIE();
						$('div.article.calendar').not(':last-child').removeClass('no-curl');
					} 
				});
				$('div.section.content').bind('infinitescroll.maxreached', function(){
					Cufon.replace('div.section.content div.article.calendar ul.week > li > h4 > a', {fontFamily: 'MCG-Bold'});					
					$('div.zoeken a.link.more-dates').remove();
					MC.Utils.fixLastChild();
					if ($.browser.msie) {
						MC.Utils.fixIE();
						$('div.article.calendar').not(':last-child').removeClass('no-curl');
					} 
				});
				
				$('div.zoeken a.link.more-dates').bind('click', function(event){
					event.preventDefault();
					$(window).trigger('infinitescroll.scrollpage');
				});
			},
			
			processData: function(data){
				$content = $('ul.week',$(data.html));
				if($content.length>0){
					var startLastWeek = $('div.section.content div.article.calendar ul.week:last li:first a').text();
					var startFirstWeek = $('li:first a',$content.eq(0)).text();
					if(startLastWeek==startFirstWeek){
						$content = $content.slice(1);
					}
				}
				MC.Calendar.initCalendarWeeks($content);
				return $content;
			}
		},
		
		News: {
			
			init: function(){
				if ( $('div.zoeken').length == 0  || $('div.zoeken a.link.more-news').length == 0 ) return false;
				var splitHref = $('div.zoeken a.link.more-news').attr('href').split('=');
				var page = new Number(splitHref[splitHref.length-1] -1);
				$('div.zoeken a.link.more-news').attr('href','#');
                var id = (window.location.href.indexOf('?')!=-1 ? window.location.href.split('?')[1].split('&')[0].split('=')[1] : '/mc/home');//too quick too dirty, i know				
				
				$(window).infinitescroll({
				    url: '?id='+id+'&##PAGE##&'+ MC.config.ajaxSuffix,					
				    page: page,
				    getNextPage: function(curPage){ return curPage+1;},
				    pageToString: function(page){ return 'page='+page; },
				    processData: this.processData,
				    insertAfter: 'div.zoeken div.article.news:last',
				    noAutoScroll: true,
				    fadeInSpeed: 500,
				    container: $(document),
				    triggerAt: 250,					// n px measured from bottom
					delay: 400						// time (delay) before triggering load
				});
				
				$('div.section.content').bind('infinitescroll.beforesend', function(){
					$('div.zoeken a.link.more-news').addClass('loading');
//					if ($('body').hasClass('ie7')) $('div.article.calendar').not(':last-child').removeClass('no-curl');
				});
				
				$('div.section.content').bind('infinitescroll.finish', function(){
					$('div.zoeken a.link.more-news').removeClass('loading');
/*					MC.Utils.fixLastChild();
					if ($.browser.msie) {
						MC.Utils.fixIE();
						$('div.article.calendar').not(':last-child').removeClass('no-curl');
					}*/ 
				});
				$('div.section.content').bind('infinitescroll.maxreached', function(){
					$('div.zoeken a.link.more-news').remove();
/*					MC.Utils.fixLastChild();
					if ($.browser.msie) {
						MC.Utils.fixIE();
						$('div.article.calendar').not(':last-child').removeClass('no-curl');
					} */
				});
				
				$('div.zoeken a.link.more-news').bind('click', function(event){
					event.preventDefault();
					$(window).trigger('infinitescroll.scrollpage');
				});
			},
			
			processData: function(data){
				$html=$(data.html);
				$content = $('div.article.news',$html);
				$linkMoreNewsLink = $('a.link.more-news',$html);
				if($linkMoreNewsLink.size()==0){
					this.triggerMaxReached=true;
				}
/*				if($content.length>0){
					var startLastWeek = $('div.section.content div.article.calendar ul.week:last li:first a').text();
					var startFirstWeek = $('li:first a',$content.eq(0)).text();
					if(startLastWeek==startFirstWeek){
						$content = $content.slice(1);
					}
				}
				MC.Calendar.initCalendarWeeks($content);*/
				return $content;
			}
		},
		Productions: {
			
			init: function(){
				if ( $('div.zoeken').length == 0  || $('div.section.content.producties a.link.more-productions').length == 0 ) return false;
				var lastProductionId = $('div.zoeken ul.production-list ul>li:last').attr('id').split('_');
				var totalProductions = new Number(lastProductionId[1]);
				var lastShownProduction = new Number(lastProductionId[2]);
				var lastIsSeasonLabel = (lastProductionId[0].indexOf('season')!=-1);
				var page = (lastIsSeasonLabel ? lastShownProduction-1 : lastShownProduction);
                var id = (window.location.href.indexOf('?')!=-1 ? window.location.href.split('?')[1].split('&')[0].split('=')[1] : '/mc/home');//too quick too dirty, i know				
				
				$(window).infinitescroll({
				    url: '?id='+id+'&##PAGE##&'+ MC.config.ajaxSuffix,					
				    baseUrl: '?id='+id+'&##PAGE##&'+ MC.config.ajaxSuffix,					
				    page: page,
				    getNextPage: function(curPage){ return curPage+1;},
				    pageToString: function(page){ return 'page='+page; },
				    processData: this.processData,
				    insertAfter: 'div.zoeken ul.production-list ul>li:last',
				    noAutoScroll: false,
				    fadeInSpeed: 500,
				    container: $(document),
				    triggerAt: 250,					// n px measured from bottom
					delay: 400						// time (delay) before triggering load
				});
				
				$('div.section.content').bind('infinitescroll.beforesend', function(){
					$('div.section.content.producties a.link.more-productions').addClass('loading');
//					if ($('body').hasClass('ie7')) $('article.bh-mosaic.zoeken').not(':last-child').removeClass('no-curl');
				});
				
				$('div.section.content').bind('infinitescroll.finish', function(){
					Cufon.replace('div.article ul.production-list li.season h3 span', {fontFamily: 'MC'});					
					$('div.section.content.producties a.link.more-productions').removeClass('loading');
					MC.Utils.fixLastChild();
					if ($.browser.msie) {
						MC.Utils.fixIE();
						$('article.bh-mosaic.zoeken').not(':last-child').removeClass('no-curl');
					} 
				});
				$('div.section.content').bind('infinitescroll.maxreached', function(){
					Cufon.replace('div.article ul.production-list li.season h3 span', {fontFamily: 'MC'});					
					$('div.section.content.producties a.link.more-productions').remove();
/*					MC.Utils.fixLastChild();
					if ($.browser.msie) {
						MC.Utils.fixIE();
						$('article.bh-mosaic.zoeken').not(':last-child').removeClass('no-curl');
					} */
				});
				
				$('div.section.content.producties a.link.more-productions').bind('click', function(event){
					event.preventDefault();
					$(window).trigger('infinitescroll.scrollpage');
				});
			},
			
			processData: function(data){
				$html=$(data.html);
				$content = $('li.production-item',$html);
				if($content.size()>0){
				//figure out the last page and set it in this.settings
					var lastProductionId = $content.eq($content.size()-1).attr('id').split('_');
					var totalProductions = new Number(lastProductionId[1]);
					var lastShownProduction = new Number(lastProductionId[2]);
					var lastIsSeasonLabel = (lastProductionId[0].indexOf('season')!=-1);
					var page = (lastIsSeasonLabel ? lastShownProduction-1 : lastShownProduction);
					this.settings.page=page;
					if( page>=totalProductions){
						this.triggerMaxReached=true;
					}
					if(lastIsSeasonLabel){
						this.settings.url = this.settings.baseUrl+'&suppress=true';
					}else{
						this.settings.url = this.settings.baseUrl;
					}
					MC.Mosaic.initProductionItems($content);
				}
				return $content;
			}
		}
		
		
	},
	
	Overlay: {
		showModal: function()
		{
			$('body').append('<div id="Modal"></div>');
			$('div#Modal').css({
				height: $(document).height()
			});
			$('div#Modal').show();
		},
		content: null,
		image: null,
		load: function()
		{
			if (! $('div.section.content').hasClass('overlay') ) return false;
			this.showModal();
			this.content = $('a.promo-link').attr('href');
			$('body').append('<div id="Overlay"></div>');
			this.image = $('<img src="'+this.content+'" alt="" id="OverlayContent" />');
			$('div#Overlay').append($(this.image));
			$('body').append($('<a href="#" class="close">close</a>'))
			
			$('body a.close').click(function(e){
				e.preventDefault();
				MC.Overlay.hideOverlay();
			});
			
			$('img#OverlayContent').bind('load',function(){
				MC.Overlay.showOverlay();	
			})
			$('div#Overlay, div#Modal').click(function(){
				MC.Overlay.hideOverlay();
			});
			
			
		},
		showOverlay: function()
		{
			var overlay = {
				width:	$('div#Overlay').width(),
				height: $('div#Overlay').height()
			};
			var doc = {
				width:	$(window).width()
			}
			var pos = {
				left: doc.width / 2 - overlay.width / 2
			}
			$('div#Overlay').css(
				'left', pos.left
			);
			$('div#Overlay').fadeIn('slow');
		},
		hideOverlay: function()
		{
			$('div#Overlay, div#Modal').fadeOut();
			$('a.close').remove();
		}
		
	},
	
/*
 *Carousel parameters:
 *<ol>
 *	<li>the fade in and fade out speed in ms</li>
 *	<li>the transition type 'linear' or 'swing'</li>
 *	<li>the time to wait before advancing to next slide in ms</li>
 *	<li>the time to wait before advancing to next slide after manual slide navigation in ms</li>
 *</ol> 
 */
 	Carousel: new Carousel(500,'linear',5000,5000),
 	
	Utils: {
		init: function()
		{
//			this.fixHeader();
			if ($.browser.msie) this.fixIE();
			this.curlyItems();
			this.fixLastChild();
//			this.zebraRows();
			this.hoverRows();
		},
		
		fixIE: function()
		{
			$('div.section.content div.article').not(":first").each(function(){
				if (! $(this).find('.pre-article').length ) $('<div class="pre-article"></div>').prependTo($(this));
			});
			if (! $('div.section.content div.article:last-child').hasClass('no-curl')) $('div.section.content div.article:last-child').addClass('no-curl');
			
			$('div.article.calendar ul.week li:last-child').addClass('last-child');
			$('div.article.calendar ul.week li ul li:last-child ').addClass('last-child');
			
			if ( $('div.calendar').length ) {
				$('div.article.calendar ul.week li ul:last-child').each(function(){
				
					if ($(this).find('li.no-border').length) $(this).addClass('no-border');
					
				});
			}
		},
		
//		fixHeader: function()
//		{
//			var docWidth = $(document).width();
//			$('body').prepend($('<div id="headerMask"></div>'));
//			
//		},
		
//		zebraRows: function()
//		{
			//$('.bh-zebra-rows').each(function()
			//{
			//	$(this).children('tbody').find('tr:odd').addClass('odd');
			//});
//		},
		
		curlyItems: function()
		{
			if ( $('div.section.content > div.article').length < 2 && ( ! $('div.section.content').hasClass('agenda')) && ( ! $('div.article.intro').hasClass('has5Curls')) ) {
				$('div.section.content div.article:first').addClass('no-curl');
			}
		},
		
		hoverRows: function()
		{
			$('.bh-hover-rows').each(function()
			{
				$(this).find('tr').hover(
					function()
					{
						$(this).addClass('hover');
					},
					function()
					{
						$(this).removeClass('hover');
					}
				);
				$(this).find('td').click(function(e){
					e.preventDefault();
					var target = $(this).parent().find('a').attr('href');
					location.href=target;
				});
			});
		},
		
		fixLastChild: function()
		{
			$('div.content div.article').each(function(){
				if (! $(this).find('p:last').hasClass('last-child')) $(this).find('p:last').addClass('last-child'); 
			});
		}
	}
	
	
};




//Calendar Object START ////////////////////////////////////////////////////////////////////////////////
//TODO  PUT IN SEPARATE JS FILE AND LINK SCRIPT IN TEMPLATES //////////////////////////////////////////

function Calendar(showTimeout, fadeInSpeed, fadeOutSpeed, moveYOnly){
	this.jQSDetailBox = 'div#calendarDetails';
	this.jQSItems = 'div.calendar';
	this.showTimer = null;
	this.showTimeout = showTimeout;
	this.fadeInSpeed = fadeInSpeed;
	this.fadeOutSpeed = fadeOutSpeed;
	this.moveYOnly = (moveYOnly!=null ? moveYOnly : false);
	this.timedout=false;
	this.dataLoaded=false;
	this.mousePos = {};
	this.posLeft=0;
	this.day=null;
}
Calendar.prototype.init=function(){
	if (! $(this.jQSItems).length > 0 ) return false;
	
	var calendar = this;
	$('body').append($('<div id="calendarDetails"><a href="#" class="close-details">close</a></div>'));
	calendar.$detailBox = $('div#calendarDetails');
	calendar.$detailBox.hide();
	$('a.close-details',calendar.$detailBox).click(function(event){
		event.preventDefault();
		calendar.hideDetails();
	});
	
	calendar.initCalendarWeeks($(this.jQSItems+' ul.week'));
};
Calendar.prototype.initCalendarWeeks=function($calendarWeeks){
	$calendarWeeks.each(function(index,weekElem){
		$week = $(weekElem);
		$lastDay=$('>li:last a',$week);
		splitHref = $lastDay.attr('href').split('/');
		lastDayStr = splitHref[(splitHref.length-1)];
		year = new Number(lastDayStr.substr(0,4));
		month = new Number(lastDayStr.substr(5,2));
		day = new Number(lastDayStr.substr(8,2));
		lastDayDate = new Date(year,month-1,day);
		var curDate = new Date();
		curDate = new Date(curDate.getFullYear(),curDate.getMonth(),curDate.getDate());
		if(lastDayDate < curDate){
			$week.hide();
		}
	});
	
	$calendarDays = $('> li',$calendarWeeks);
	this.setEmptyDays($calendarDays);
	$calendarDays.each(function(){
		$('div:last ul li:last',this).css("border-width","0px");
	});
	this.makeDaysHoverable($calendarDays);
	this.makeDaysClickable($calendarDays);
}
Calendar.prototype.setEmptyDays=function($calendarDays){
	$calendarDays.each(function(){
		if ( $(this).children('div').length < 1 ) {
			$(this).addClass('disabled');
		}
	});
};
Calendar.prototype.makeDaysClickable=function($calendarDays){
	var calendar = this;
	$calendarDays.each(function(){
		var $clickItem = $(this);
		$clickItem.click(function(event){
			event.preventDefault();
			if( $clickItem.hasClass('disabled') ){
				calendar.hideDetails();
				return false;
			}
			var item = {};
			item.pos			=	$clickItem.offset();
			item.width			=	$clickItem.width();
			item.spacing		=	30;
			item.day			=	$('h4',$clickItem).text();

			calendar.day=item.day
			calendar.timedout=true;
			calendar.dataLoaded=false;
			calendar.mousePos.x = event.pageX;
			calendar.mousePos.y = event.pageY;
		
			calendar.posLeft = (calendar.moveYOnly ? item.pos.left - ( item.width / 2 ) - item.spacing : calendar.mousePos.x - ( calendar.$detailBox.width() / 2 ));
			if ( calendar.posLeft > 735) calendar.posLeft = 735;
		
			var target = $('h4 a',$clickItem).attr('href');
			var ajaxUrl = target + '&'+ MC.config.ajaxSuffix;
			calendar.loadDetails(ajaxUrl,calendar.day);
		});
	});
};
Calendar.prototype.makeDaysHoverable=function($calendarDays){
	var calendar = this;
	$calendarDays.each(function(){
		var $hoverItem = $(this);
		$hoverItem.mouseover(function(event){
			if (calendar.$detailBox.is(':visible') && calendar.$currentHoverItem!=$hoverItem) {
				calendar.hideDetails();
				calendar.$currentHoverItem=null;
			}
			if ( $hoverItem.hasClass('disabled') || calendar.$currentHoverItem==$hoverItem) return false;
			var item = {};
			item.pos			=	$hoverItem.offset();
			item.width			=	$hoverItem.width();
			item.spacing		=	30;
			item.day			=	$('h4',$hoverItem).text();
			
			if(calendar.showTimer!=null){
				clearTimeout(calendar.showTimer);
				calendar.showTimer=null;
			}
			
			calendar.$currentHoverItem=$hoverItem;
			calendar.day=item.day;
			calendar.timedout=false;
			calendar.dataLoaded=false;

			calendar.mousePos.x = event.pageX;
			calendar.mousePos.y = event.pageY;
			
			calendar.posLeft = (calendar.moveYOnly ? item.pos.left - ( item.width / 2 ) - item.spacing : calendar.mousePos.x - ( calendar.$detailBox.width() / 2 ));
			if ( calendar.posLeft > 735) calendar.posLeft = 735;			

			var target = $('h4 a',$hoverItem).attr('href');
			var ajaxUrl = target + '&' + MC.config.ajaxSuffix;
			calendar.loadDetails(ajaxUrl,item.day);
			
			calendar.showTimer=setTimeout(function(){
				calendar.showTimer=null;
				calendar.timedout=true;
				calendar.showDetails();
			}, calendar.showTimeout);
		}).mousemove(function(event){
			if(!calendar.$detailBox.is(':visible')){
				calendar.mousePos.x = event.pageX;
				calendar.mousePos.y = event.pageY;
			}
		});
	});
};
Calendar.prototype.showDetails=function(){
	if(this.dataLoaded && this.timedout){
		if(!this.moveYOnly){
			this.posLeft = this.mousePos.x - ( this.$detailBox.width() / 2 );
			if( this.posLeft > 735) this.posLeft = 735;
		}
		this.$detailBox.css({
			left: this.posLeft +'px',
			top: this.mousePos.y+10+'px'
		});
		this.$detailBox.fadeIn(this.fadeInSpeed);
	}
};
Calendar.prototype.loadDetails=function(target, day){
	var calendar = this;
	$.ajax({
		url: target,
		success: function(data){
			calendar.dataLoadedHandler(data, day);
		}
	});
};
Calendar.prototype.dataLoadedHandler=function(data, day){
	var calendar = this;
	if(calendar.day==day){
		calendar.setDetails(day,data);	
		calendar.dataLoaded=true;
		calendar.showDetails();
	}
};
Calendar.prototype.hideDetails=function(){
	this.$detailBox.fadeOut(this.fadeOutSpeed);
};
Calendar.prototype.setDetails=function(day,data){
	var calendar = this;
	$('h3, ul',calendar.$detailBox).remove();
	calendar.$detailBox.append('<h3>'+day+'</h3>');
	calendar.$detailBox.append(data);
};
//Calendar Object END //////////////////////////////////////////////////////////////////////////////////

//Mosaic Object START //////////////////////////////////////////////////////////////////////////////////
//TODO:  PUT IN SEPARATE JS FILE AND LINK SCRIPT IN TEMPLATES //////////////////////////////////////////

function Mosaic(showTimeout, fadeInSpeed, fadeOutSpeed, moveYOnly){
	this.detailBox = '<div class="detail-box hidden"><h2>heading</h2><p></p></div>';
	this.jQSDetailBox = 'div.detail-box';
	this.jQSItems = 'div.bh-mosaic ul';
	this.showTimer = null;
	this.showTimeout = showTimeout;
	this.fadeInSpeed = fadeInSpeed;
	this.fadeOutSpeed = fadeOutSpeed;
	this.moveYOnly = (moveYOnly!=null ? moveYOnly : false);
	this.people = {
			width:	46
		};
	this.production = {
			width:	10
		};
}
Mosaic.prototype.init=function(){
	var mosaic = this;
	$('body').append($('<div class="detail-box"><h2>heading</h2><p></p></div>'));
	this.$detailBox = $('div.detail-box');
	this.$detailBox.hide();

	if ($(this.jQSItems).hasClass('people-list')) this.$detailBox.addClass('people');
	if ($(this.jQSItems).hasClass('production-list')) this.$detailBox.addClass('productions');
	this.initProductionItems($(this.jQSItems+'.production-list li ul li, '+this.jQSItems+'.people-list li'));
};
Mosaic.prototype.initProductionItems=function($content){
	var mosaic = this;
	$content.each(function(){
		var $hoverItem = $(this);
		if ($hoverItem.hasClass('season')) return;

		var mousePos = {};
		var item = {};
		item.title 			=	$hoverItem.find('dl dt a');
		item.description	=	$hoverItem.find('dl dd').html();
		item.target 		=	$hoverItem.find('a').attr('href');
		item.pos			=	$hoverItem.offset();
		item.width			=	$hoverItem.width();
		item.spacing		=	0;
		
		$('img',$hoverItem).attr('title','');
		
		$hoverItem.mouseover(function(event){
			mousePos.x = event.pageX;
			mousePos.y = event.pageY;
			
			item.pos	=	$(this).offset();
			item.width	=	$(this).width();
			
			if (mosaic.$detailBox.hasClass('people')) {
				item.spacing = mosaic.people.width;
			} else if (mosaic.$detailBox.hasClass('productions')) {
				item.spacing = mosaic.production.width;
			}
			
			var posLeft = (mosaic.moveYOnly ? item.pos.left - ( item.width / 2 ) + item.spacing : mousePos.x - ( mosaic.$detailBox.width() / 2 ));
			if ( mosaic.$detailBox.hasClass('productions') && posLeft > 755) posLeft = 755;
			if ( mosaic.$detailBox.hasClass('people') && posLeft > 825) posLeft = 825; 
			
			mosaic.$detailBox.css({
				left: posLeft +'px',
				top: mousePos.y+'px'
			});
			
			$(this).addClass('hover');
			$('h2',mosaic.$detailBox).html(item.title);
			$('p',mosaic.$detailBox).html(item.description);
			if(mosaic.showTimer!=null) clearTimeout(mosaic.showTimer);
			mosaic.showTimer=setTimeout(function(){
				mosaic.$detailBox.fadeIn(mosaic.fadeInSpeed);	
				mosaic.showTimer=null;
			}, mosaic.showTimeout);
		});
	
		$hoverItem.mouseout(function(event){
			mosaic.$detailBox.fadeOut(mosaic.fadeOutSpeed);
			if(mosaic.showTimer!=null) clearTimeout(mosaic.showTimer);
			mosaic.showTimer=null;
			$(this).removeClass('hover');
		});
		
		$hoverItem.mousemove(function(event){
			mousePos.x = event.pageX;
			mousePos.y = event.pageY;
			if(mosaic.moveYOnly){
				mosaic.$detailBox.css({top: mousePos.y+'px'});
			}else{
				var posLeft = mousePos.x - ( mosaic.$detailBox.width() / 2 );
				if ( mosaic.$detailBox.hasClass('productions') && posLeft > 755) posLeft = 755;
				if ( mosaic.$detailBox.hasClass('people') && posLeft>825)  posLeft = 825; 
				mosaic.$detailBox.css({ left: posLeft+'px', top: mousePos.y+'px'});
			}
		});
		
		$hoverItem.click(function(event){
			location.href= item.target;
		});
	});
}

//Mosaic Object END ////////////////////////////////////////////////////////////////////////////////////

//Carousel Object START ////////////////////////////////////////////////////////////////////////////////
//TODO:  PUT IN SEPARATE JS FILE AND LINK SCRIPT IN FIRST TEMPLATE /////////////////////////////////////
function Carousel(animationSpeed, easing, autoAdvanceTimeout, reEnableAutoAdvanceTimeout){
	this.autoAdvanceTimer = null;
	this.autoAdvanceTimeout = autoAdvanceTimeout;
	this.reEnableAutoAdvanceTimer = null;
	this.reEnableAutoAdvanceTimeout = reEnableAutoAdvanceTimeout;
	this.jQSItems = 'div.article.bh-carousel';
	this.animationSpeed = animationSpeed;
	this.easing = easing;
	this.autoAdvanceSlideTimer=null;
};
Carousel.prototype.init=function(){
	var $slides=$(this.jQSItems);
	this.slideCount = $slides.size();
	this.currentIndex=-1;
	if( this.slideCount==0  ) return false;//no slides, no ball
	
	this.$nav = $('div.carousel > div.thumbNav');
	if(this.slideCount>1){
		this.currentIndex=0;
		var carousel = this;
		$slides.each(function(index,slideElem){
			var $slide = $(slideElem);
			$slideLink = $('<a href="#">'+index+'</a>');
			if(index==carousel.currentIndex) $slideLink.addClass('active cur');
			
			$slideLink.click(function(event){
				if($slideLink.hasClass('active')){
					carousel.disableAutoAdvance();
					carousel.showSlide(index);
					carousel.reEnableAutoAdvanceAfterTimeout();
				}
				event.preventDefault();
			});
			
			$("ul", carousel.$nav).append($slideLink);
			$slideLink.wrap("<li />");
		});
		this.$navLinks = this.$nav.find('li > a');
		$slides.each(function(index,slideElem){
			var $slide = $(slideElem);
			$imagesOnSlide = $('img',$slide);
			$slideLink=carousel.$navLinks.eq(index);
			var noImagesInSlide = !carousel.addImageTrackers($imagesOnSlide, $slideLink);
			if(noImagesInSlide){
				$slideLink.addClass('active');
			}			
		});
		if(this.currentIndex==-1) this.autoAdvanceSlide();
		this.enableAutoAdvance();
	}
};
Carousel.prototype.addImageTrackers=function($images, $slideLink){
	if($images!=null){
		var imageCount = $images.size();
		if($images.size()>0){
			$slideLink.data('imagesLoading',imageCount);
			var carousel = this;
			$images.one('load',function(){
				var imagesLoading = $slideLink.data('imagesLoading')-1;
				if(imagesLoading<=0){
					$slideLink.removeData('imagesLoading');
					$slideLink.addClass('active');
					if(carousel.currentIndex==-1) carousel.autoAdvanceSlide();
				}else{
					$slideLink.data('imagesLoading',imagesLoading);
				}
			}).each(function(){
				if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6))
					$(this).trigger('load');
			}); 
			return true;
		}
	}
	return false;
};
Carousel.prototype.reEnableAutoAdvanceAfterTimeout=function(){
	if(this.autoAdvanceTimer==null && this.autoAdvanceTimeout!=null && this.slideCount>1){
		if(this.reEnableAutoAdvanceTimer==null && this.reEnableAutoAdvanceTimeout!=null){
			var carousel = this;
			this.reEnableAutoAdvanceTimer = setTimeout(function(){ carousel.enableAutoAdvance(); carousel.autoAdvanceSlide();},this.reEnableAutoAdvanceTimeout);
		}else{
			this.enableAutoAdvance();
		}
	}
};
Carousel.prototype.enableAutoAdvance=function(){
	if(this.autoAdvanceTimer==null && this.autoAdvanceTimeout!=null && this.slideCount>1){
		var carousel = this;
		this.autoAdvanceTimer = setInterval(function(){ carousel.autoAdvanceSlide(); },this.autoAdvanceTimeout);
	}
};
Carousel.prototype.disableAutoAdvance=function(){
	if(this.autoAdvanceTimer!=null){
		clearInterval(this.autoAdvanceTimer);
		this.autoAdvanceTimer=null;
	}
	if(this.reEnableAutoAdvanceTimer!=null){
		clearTimeout(this.reEnableAutoAdvanceTimer);
		this.reEnableAutoAdvanceTimer=null;
	}
};
Carousel.prototype.autoAdvanceSlide=function(){
	this.showSlide(this.getNextAvailableIndex());
};
Carousel.prototype.clearViewPort=function(){
	$(this.jQSItems).hide();
	this.currentIndex = -1;
	this.$nav.find('.cur').removeClass('cur');
};
Carousel.prototype.showSlide=function(_newIndex){
	var newIndex = this.normalizeIndex(_newIndex);
	
	if(newIndex!=-1 && newIndex!=this.currentIndex){
		if(this.currentIndex!=-1) $(this.jQSItems).eq(this.currentIndex).fadeOut(this.animationSpeed);
		this.$nav.find('.cur').removeClass('cur');
		$(this.jQSItems).eq(newIndex).fadeIn(this.animationSpeed);
		this.currentIndex = newIndex;
		$(this.$navLinks[this.currentIndex]).addClass('cur');
	}else{
		if(newIndex==-1){
			if(this.currentIndex!=-1) $(this.jQSItems).eq(this.currentIndex).fadeOut(this.animationSpeed);
			this.clearViewPort();
		}
	}
}; 
Carousel.prototype.getNextAvailableIndex=function(){
	var nextIndex = this.normalizeIndex(this.currentIndex+1);
	var firstIndex=nextIndex;
	while(nextIndex!=this.currentIndex && !$(this.$navLinks[nextIndex]).hasClass('active')){
		nextIndex=this.normalizeIndex(nextIndex+1);
		if(nextIndex==firstIndex && this.currentIndex==-1) return -1;
	}
	return nextIndex;
};
Carousel.prototype.normalizeIndex=function(index){
	slideCount = $(this.jQSItems).size();
	if(this.slideCount>0){
		while(index<0) index+=this.slideCount;
		while(index>=this.slideCount) index-=this.slideCount;
	}else{
		index=-1;
	}
	return index;
};
// Carousel Object END /////////////////////////////////////////////////////////////////////////////////
/* --------------------------------------------------------------------------------------------------------------------------- */

/* document.ready initializes MC object containing behaviour triggers */
 $(document).ready(function()
	{
		MC.init(); 			
	}
);

