var jtk = new JoookToolkit();

function toggleClass(emtIds, classes){
	for(var i = 0; i < emtIds.length; i++){
		var emt = jtk.select('#' + emtIds[i])[0];
		var emtClasses = emt.className.split(" ");
		for(var j = 0; j < emtClasses.length; j++){
			if(emtClasses[j] == classes[0]){
				jtk.replaceClass(emt, classes[0], classes[1]);
				break;
			}
			else if(emtClasses[j] == classes[1]){
				jtk.replaceClass(emt, classes[1], classes[0]);
				break;
			}
		}
	}
}

function updateTitleLayout(){
	$("#main_image").css({'background' : "transparent url(" + $("#main_image img").attr("src") + ") no-repeat left top", 'width' : $("#main_image img").width() + "px", 'height' : $("#main_image img").height() + "px"});
	$("#main_image img").replaceWith($("#title"));
	Cufon.replace('#title');
}



var Geopos = {
	currentLatId: null,
	currentLngId: null,
	
	geocoder: new GClientGeocoder(),
	
	geocodeSlot: function(addrId, latId, lngId){
		Geopos.currentLatId = latId;
		Geopos.currentLngId = lngId;
		var addrEmt = document.getElementById(addrId);
		
		Geopos.geocoder.getLatLng(addrEmt.getElementsByTagName("div")[0].innerHTML, Geopos.handleGeocoding);
	},
	
	handleGeocoding: function(point){
		document.getElementById(Geopos.currentLatId).getElementsByTagName("div")[0].innerHTML = point.lat();
		document.getElementById(Geopos.currentLngId).getElementsByTagName("div")[0].innerHTML = point.lng();
		if(!window.Save || !Save.u4_disabled){top.main.postData();}
	}
}

var Hotels = {
	mapping: [
		{value: "VANTAA", path: "/hotellit/airport/"},
		{value: "NOKIA", path: "/hotellit/eden/"},
		{value: "JYVÄSKYLÄ", path: "/hotellit/laajavuori/"},
		{value: "VAASA", path: "/hotellit/tropiclandia/"},
		{value: "FORSSA", path: "/hotellit/forssa/"},
		{value: "IMATRA", path: "/hotellit/imatran-valtionhotelli/"},
		{value: "IKAALINEN", path: "/hotellit/ikaalinen/"},
		{value: "JOUTSA", path: "/hotellit/joutsenlampi/"},
		{value: "ROVANIEMI", path: "/hotellit/pohjanhovi/"},
		{value: "RUKATUNTURI", path: "/hotellit/rukahovi/"},
		{value: "HÄMEENLINNA", path: "/hotellit/aulanko/"},
		{value: "HYVINKÄÄ", path: "/hotellit/sveitsi/"}
	],
	
	preselectHotel: function(){
		var currentUrl = window.location.href;
		var selectVal = null;
		
		for(var i in Hotels.mapping){
			if(currentUrl.indexOf(Hotels.mapping[i].path) > -1)
				selectVal = Hotels.mapping[i].value;
		}
		
		if(selectVal != null){
			var dd = document.getElementById("cName");
			for(var i = 0; i < dd.options.length; i++){
				if(dd.options[i].value == selectVal)
					dd.options[i].selected = true;
				else
					dd.options[i].selected = false;
			}
		}
	}
}
