$(document).ready(function(){
	setForm();
	
	$("#footerMenu ul li:first").addClass("first");
	
	
	$('table.alternate tr:odd').addClass('odd');
	$('table.alternate tr:even').addClass('even');
});

function highlightMenu(contentID, parentID) {
	$("#link-" + contentID).addClass("selected");
	if (parentID != 0) { $("#link-" + parentID).addClass("selected");}
}

function repositionForm() {
	$("#reservationContent").appendTo("#contentColumn");
	$("#reservationContent").removeClass("hide");
}

function switchLanguage(lg_id) {
	var langPos = window.location.toString().indexOf('lang=',0); 

	if (langPos == -1) {
		var hasParams = true;
		if (window.location.toString().indexOf('?',0) == -1) {hasParams = false;}
			
		if (hasParams) {
			window.location.href = window.location.href + "&lang=" + lg_id;
		}
		else {
			window.location.href = window.location.href + "?lang=" + lg_id;
		}
	}
	else {
		var url = window.location.toString().substring(0,langPos);
	
		if (window.location.toString().substring(langPos+6).length > 0) {
			window.location.href = url + "lang=" + lg_id + window.location.toString().substring(langPos+6);
		}
		else {
			window.location.href = url + "lang=" + lg_id;
		}
	}
} 

function hideLanguage() {
	$(function() {
		$("#content-switchLanguage").hide();
	});
} 

//CODE FROM http://v2.easy-designs.net/articles/replaceSelect/files/final.html
//to replace the SELECTs
function selectReplacement(obj, layer) {
  // append a class to the select
  obj.className += ' replaced';
  // create list for styling
  var ul = document.createElement('ul');
  ul.className = 'selectReplacement';
  ul.style.zIndex = layer;
  var opts = obj.options;
  for (var i=0; i<opts.length; i++) {
	var selectedOpt;
	if (opts[i].selected) {
	  selectedOpt = i;
	  break;
	} else {
	  selectedOpt = 0;
	}
  }
  for (var i=0; i<opts.length; i++) {
	var li = document.createElement('li');
	var txt = document.createTextNode(opts[i].text);
	li.appendChild(txt);
	li.selIndex = opts[i].index;
	li.selectID = obj.id;
	li.onclick = function() {
	  selectMe(this);
	}
	if (i == selectedOpt) {
	  li.className = 'selected';
	  li.onclick = function() {
		closeAll();	
		this.parentNode.className += ' selectOpen';
		this.onclick = function() {
		  selectMe(this);
		}
	  }
	}
	if (window.attachEvent) {
	  li.onmouseover = function() {
		this.className += ' hover';
	  }
	  li.onmouseout = function() {
		this.className = 
		  this.className.replace(new RegExp(" hover\\b"), '');
	  }
	}
	ul.appendChild(li);
  }
  // add the input and the ul
  obj.parentNode.appendChild(ul);
}

function selectMe(obj) {
  closeAll();	
  var lis = obj.parentNode.getElementsByTagName('li');
  for (var i=0; i<lis.length; i++) {
	if (lis[i] != obj) { // not the selected list item
	  lis[i].className='';
	  lis[i].onclick = function() {
		
		selectMe(this);
	  }
   } else {
	  setVal(obj.selectID, obj.selIndex);
	  obj.className='selected';
	  obj.parentNode.className = 
		obj.parentNode.className.replace(new RegExp(" selectOpen\\b"), '');
	  obj.onclick = function() {
		obj.parentNode.className += ' selectOpen';
		this.onclick = function() {
		  selectMe(this);
		}
	  }
	}
  }
}

function setVal(objID, selIndex) {
  var obj = document.getElementById(objID);
  obj.selectedIndex = selIndex;
  $(function() {
	if ($(obj).attr("onchange")){
		$(obj).trigger( 'change' )
	}
  });

}

function setForm() {
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		//do nothing
	}
	else {
	  var s = document.getElementsByTagName('select');
	  var countDown = 100;
	  for (var i=0; i<s.length; i++) {
		selectReplacement(s[i], countDown--);
	  }
  }
}

function closeAll() {
}

