jQuery.noConflict();

function openVirtualTour(){
	jQuery('body').append('<div id="tour"><div id="flash_tour"></div></div>');
	
	var minWidth = 768;
	var minHeight = 600;
	
	var maxWidth = 1600;
	var maxHeight = 1250;
	
	var ratioFlash = minWidth/minHeight;
	
	var isResized = false;
	
	setTimeout(function(){
					
		setTimeout(function(){
			jQuery('#tour').css('overflow','hidden');
			
			
			var attributes = {id:"testObject", name:"testObject" }; 
			swfobject.embedSWF("/fileadmin/templates/html/flash/tour/swfloader.swf", "flash_tour",  "100%", "100%", "9.0.124", false, { fvSwfUrl : "/fileadmin/templates/html/flash/tour/tourExperience.swf", fvBaseUrl: "/fileadmin/templates/html/flash/tour/"}, {wmode: "gpu"}, attributes);//fvDataXmlUrl : "/fileadmin/templates/html/flash/tour/xml/data.xml", 
			//swfmacmousewheel.registerObject(attributes.id);
		},100);
		
		var ratioScreen = jQuery(window).width()/jQuery(window).height();
		
		if(ratioScreen < ratioFlash){
			var vWidth = Math.round(jQuery(window).width());
			var vHeight = Math.round((vWidth/minWidth)*minHeight);
		}else{
			var vHeight = Math.round(jQuery(window).height());
			var vWidth = Math.round((vHeight/minHeight)*minWidth);
		}
		
		if(vWidth < minWidth || vHeight < minHeight)
		{
			vWidth = minWidth;
			vHeight = minHeight;
		}
		
		if(vWidth > maxWidth || vHeight > maxHeight)
		{
			vWidth = maxWidth;
			vHeight = maxHeight;
		}

		jQuery('#tour').dialog({modal: true,height: vHeight, width: vWidth, dialogClass : 'virtual_tour'});
	}, 100);
	jQuery(window).resize(function(){
	
		var ratioScreen = jQuery(window).width()/jQuery(window).height();
		
		if(ratioScreen < ratioFlash){
			var vWidth = Math.round(jQuery(window).width());
			var vHeight = Math.round((vWidth/minWidth)*minHeight);
		}else{
			var vHeight = Math.round(jQuery(window).height());
			var vWidth = Math.round((vHeight/minHeight)*minWidth);
		}
		
		if(vWidth < minWidth || vHeight < minHeight)
		{
			vWidth = minWidth;
			vHeight = minHeight;
		}
		
		if(vWidth > maxWidth || vHeight > maxHeight)
		{
			vWidth = maxWidth;
			vHeight = maxHeight;
		}
		
		jQuery('#tour').dialog('option','width',vWidth);
		// set width and height on the directly on the div. setting dialog height has no effect.
		jQuery('#tour').css("height", vHeight);//.dialog('option','height',vHeight);
		
		// set left margin
		var leftMargin = ((jQuery(window).width()-vWidth) / 2);
		if(leftMargin < 0){ leftMargin = 0; }
		jQuery('.virtual_tour').css("left", leftMargin);
	});
}

function setFlashDivHeight(height) {
	jQuery('#flash').css('height', height + 'px');
	if (jQuery('#tfe_flash_checker .fullpage-mask').length > 0 && height < 500) {
		jQuery('#tfe_flash_checker .mask').animate({'opacity':0}, function() { jQuery(this).removeClass('fullpage-mask');});
	} /*else if(jQuery('#tfe_flash_checker .fullpage-mask').length==0) {
		jQuery('#tfe_flash_checker .mask').addClass('fullpage-mask').css({'opacity':0.85});
	}*/
}

function tfeCarouselCufonCallBack() {
	/*Cufon.replace('#main .tfe-carrousel-wrapper .navigation li', { color: '#FFF', fontFamily: 'Stone Sans', fontWeight: 'normal', hover: 'true' });
	Cufon.replace('#main .tfe-carrousel-wrapper .navigation li.active', {fontFamily: 'Stone Sans', fontWeight: 'normal', hover: 'true' });*/
}

function showOverlay(){
	jQuery('#tfe_flash_checker .mask').addClass('fullpage-mask').css({'opacity':0.85});
}

function closeVirtualTour(){
	var tour = jQuery('#tour');
	tour.dialog('destroy');
	tour.remove();
}

(function($) {
	$().ready(function() {
		if(!jQuery.browser.msie || jQuery.browser.version.search('6')==-1) {
			$("#main select").selectbox();
		}
				
		var addSearchLink = function() {
			var searchresult = $(".tx-indexedsearch-res");
			searchresult.find("span.read-more").click(function() {
				document.location.href = $(this).parents(".tx-indexedsearch-res > div").find("h2 a").attr("href");
			}).hover(
				function(){this.style.background = '#730033';},
				function(){this.style.background = '#021E62';}
			);
		}();
		
		var initLanding = function() {
			var a_tags = $("ul.overview a");
			a_tags.each(function() {
				var a_tag = this;
				$(a_tag).find('span.more').hover(
					function(){this.style.backgroundColor = '#730033'},
					function(){this.style.backgroundColor = '#021E62'}
				);
				$(a_tag).find('span.title').hover(
					function(){Cufon.replace(this,{fontFamily: 'Stone Sans', fontWeight: 'normal',color: '#7A0D3D'})},
					function(){Cufon.replace(this,{fontFamily: 'Stone Sans', fontWeight: 'normal',color: '#021E62'})}
				);
			});
		}();
		var accordion = function() {
			var a_tags = $('.tfe-accordion h2 a');
			a_tags.click(function() {
				setTimeout(function() {
						Cufon.replace('.tfe-accordion h2.ui-state-default a', { color: '#021E62', fontFamily: 'Stone Sans', fontWeight: 'normal', hover: 'true' });
					}, 100
				);
			});
		}();
		
		setTimeout(function() {
			Cufon.replace('.overview span.title, .overview-items a.title', {fontFamily: 'Stone Sans', fontWeight: 'normal', hover: true});
			Cufon.replace('.tfe-carrousel .description a span, .banner h3', {fontFamily: 'Stone Sans', fontWeight: 'bold'});
			Cufon.replace('#main h2,.tx-indexedsearch h2 a, #tfe_flash_checker .buttons a, .jcarousel-container .description div, .overview li a.title',{fontFamily: 'Stone Sans', fontWeight: 'normal', hover : 'true'});
			Cufon.replace('.ui-dialog-titlebar-close', {fontFamily: 'Stone Sans', fontWeight: 'normal', hover: true});
			Cufon.replace('.tfe-carrousel h3,.tfe-carrousel h4, .jcarousel-container .description div, h1, .aandachtsgebied h2',{fontFamily: 'Stone Informal', fontWeight: 'bold'});
			Cufon.replace('#modal_content h1, .date-time, .categorie-label, ul.category', {fontFamily: 'Stone Sans', fontWeight: 'normal'});	
		}, 100);
		
		Cufon.now();
		$(window).unload(function(){
			$("canvas, span.cufon").remove();
		});
		
		$('a[rel="lightbox"]').click(function(e) {
			e.preventDefault();
			$.get($(this).attr('href'), {type:110}, function(data, textStatus) {
				$('#modal_content').html(data);
				Cufon.refresh();
			}, 'html');
			$('#modal_content').dialog({modal:true, width: 776})
			
			$(this).click(function(e){
				e.preventDefault();
				$('#modal_content').dialog("open");
			});
		});
	});
})(jQuery);