$(function() {

	// Round the corners of the boxes
	$('.text-box').corner('20px');
	$('#left_column h3, #big_column h3').corner('tr br 20px');

	// Use a different plugin to round the menu items, because the JQuery corner plugin doesn't 
    // support transparent backgrounds on the corners.	
    DD_roundies.addRule('.content', '0 0 20px 20px', true);
    DD_roundies.addRule('.contact_box', '20px', true);

	var url = document.location.href;
	var lastSlashIndex = url.lastIndexOf('/') + 1;
	var currentFile = url.substring(lastSlashIndex);

	if (currentFile) {
		// Find the menu tab that links to the current page and show it as
		// selected
		var selectedTab = $('div.menu > ul > li > a[href=' + currentFile + ']')
				.addClass('selected');

	} else {
		// Default to selecting the home page in case the location bar doesn't
		// contain a file name e.g. http://example.org/
		$('div.menu > ul > li > a:first').addClass('selected');
	}

	// Apply drop shadows
	$('.standout').dropShadow({left : 10, top : 10, blur : 3});	
	
	// Bind the event handler to the language links
	$('div.lang').click(function() {

		var currentUrl = document.location.href;
		var frenchPageRegex = /_fr\.html$/;
			
		// Is the currently looking at a French page? If so, it should end in '_fr.html'
		var isFrenchPage = currentUrl.match(frenchPageRegex) != null;
		var clickedLangId = this.id;
		var newUrl = document.location.href;
		
		if (clickedLangId == 'fr' && !isFrenchPage) {
			newUrl = currentUrl.replace(/\.html$/, '_fr.html');
			
			// If nothing was replaced, this is probably because the address is http://www.rivieravaleting.com
			if (newUrl == currentUrl) {
				
				// Be careful to properly handle 'rivieravaleting.com' and 'rivieravaleting.com/'
				var suffix = (newUrl.charAt(newUrl.length - 1)) == '/' ? '' : '/';
				suffix += 'index_fr.html'
				newUrl += suffix;
			}
			
		} else if (clickedLangId == 'en' && isFrenchPage) {
			newUrl = currentUrl.replace(frenchPageRegex, '.html');			
		}
		
		document.location.href = newUrl;
	});
	
});

