$(document).ready(function(){
	
	Shadowbox.init({
		flashVars: {skin: aud.baseurl + 'js/shadowbox/glow.zip'}
	});
	
	if($('.link-plan').length){
		$('.link-plan:not(.active)').live('click', function(){
			
			if($(this).hasClass('.active')){
				return false;
			}
			
			var obj = {},
				link = $(this).find('a');
			
			obj.plan = link.attr('href');
			obj.coord = link.attr('rel');
			
			aud.plan(obj);
			
			$(this).addClass('active')
				   .siblings('.link-plan')
				   .removeClass('active');
			
		}).find('a').click(function(e){
			try{
				e.preventDefault();
			}catch(exc){
				return false;
			}
		});
	}
	if($('#mapcanvas').length){
    	aud.map(obj = {lat: 41.83021, lng: 12.45809});
    	
    	$('form.calculate-routes').submit(function(form){
    		var start = $(this).serializeArray();
    		aud.calculateRoutes(start[0].value, aud.address);
    		
    		try{
    			form.preventDefault();
    		}catch(ex){
    			return false;
    		}
    	});
    }
    
    if( $('.contact-form').length ){
		$('#questions-form, #request-form').submit(function(e){
			var a = $(this).serializeArray();
			f.validateForm(a);

			try{
				e.preventDefault();
			}catch(exception){
				return false;
			}
		});
	}
	
	if($('#gallery-slider-wrap').length){
		gal('#gallery-slider-wrap');
	}
	
	if($('.col_sx').length){
		var col_sx = $('.col_sx').height(),
			col_dx = $('.col_dx').height();
		var h = Math.max(col_sx, col_dx);
		/*
console.group('Cols Heights');
		console.info('col_sx: ' + col_sx);
		console.info('col_dx: ' + col_dx);
		console.info('max height: ' + h);
		console.groupEnd('Cols Heights');
*/
		$('.col_dx, .col_sx').height(h);
	}
	
	if($('.virtualtour').length){
		$('.virtualtour').find('.tourbox')
						 .click(function(){
			var tour = {
		        player: "flv",
		        content: aud.baseurl + 'upload/virtual-tour/virtual-tour.flv',
		        width: 864,
		        height: 500,
		        title: 'Virtual Tour Auditorium del Massimo'
		    },
		    	options = {
		        continuous: true,
		        counterType: "skip"
		    };
		    
		    Shadowbox.open(tour, options);
		}).find('a')
		  .click(function(e){
		  	try{
		  		e.preventDefault();
		  	}catch(esx){
		  		return false;
		  	}
		  });
	}
});
