function openNewWindow(URLtoOpen, windowName, windowFeatures) { newWindow=window.open(URLtoOpen, windowName, windowFeatures); }

function addBookmark(title,url) { 
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) { 
		window.external.AddFavorite( url, title); 
	} else if( window.opera && window.print ) { 
		return true; 
	} 
}

function new_freecap()
{
	// loads new freeCap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload freeCap image\nSubmit the form and a new freeCap will be loaded");
	}
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}

$(document).ready(function(){
	 $("div#iframecontent").append('<iframe marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="http://meteo.suedtirolerland.it/?lang=it&amp;css_file=http://www.muehlenerhof.com/styles/meteo/meteo_brown.css" name="meteo" id="meteo"></iframe>');
	 $("div#RoutePlannercontent").append('<iframe marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="http://www.map24.com/?q=m24cpnlFR7MvZGle53R1hcTB9orDBrpbo5cnigIH8B3Q8cHBM2VBdYxjjQRn5lC0l8hszU4ZLwjBqwnFbb9iWfZZ8LV7lnP_FvAIPrbUGn/F_c78qrG_nAYz7XQJd4tKwLkTXxbBrDqdMWTr8JRinXKuGML2F/_SIa9neDqGE1m_R6wzs4F5aM/2_kDGglFQAG7qqGoFtQmg" name="RoutePlanner" id="RoutePlanner"></iframe>');
});

function replace_image(src, f){
	$("#theimage").fadeIn('slow');
	$("#theimage").src(src);
}

function SetupCalendars()
{
	var objEarlyDate = new Date();
	objEarlyDate.setMonth(objEarlyDate.getMonth());
	var objLateDate = new Date();
	objLateDate.setMonth(objLateDate.getMonth() + 24);

	var objDateChooserEx1 = new DateChooser();
	objDateChooserEx1.setEarliestDate(objEarlyDate);
	objDateChooserEx1.setLatestDate(objLateDate);
	objDateChooserEx1.setUpdateField({'arrivalmonth':'n', 'arrivalday':'j', 'arrivalyear':'Y'});
	objDateChooserEx1.setIcon("http://www.muehlenerhof.com//js/datechooser/cal.gif", "arrivalyear");
	objDateChooserEx1.setXOffset(-150);
	objDateChooserEx1.setYOffset(-10);

	var objDateChooserEx2 = new DateChooser();
	objDateChooserEx2.setEarliestDate(objEarlyDate);
	objDateChooserEx2.setLatestDate(objLateDate);
	objDateChooserEx2.setUpdateField({'departuremonth':'n', 'departureday':'j', 'departureyear':'Y'});
	objDateChooserEx2.setIcon("http://www.muehlenerhof.com//js/datechooser/cal.gif", "departureyear");
	objDateChooserEx2.setXOffset(-150);
	objDateChooserEx2.setYOffset(-10);

	return true;
}

function SetupContactCalendars()
{
	var objEarlyDate = new Date();
	objEarlyDate.setMonth(objEarlyDate.getMonth());
	var objLateDate = new Date();
	objLateDate.setMonth(objLateDate.getMonth() + 24);

	var objDateChooserEx1 = new DateChooser();
	objDateChooserEx1.setEarliestDate(objEarlyDate);
	objDateChooserEx1.setLatestDate(objLateDate);
	objDateChooserEx1.setUpdateField({'thearrivalmonth':'n', 'thearrivalday':'j', 'thearrivalyear':'Y'});
	objDateChooserEx1.setIcon("http://www.muehlenerhof.com//js/datechooser/cal.gif", "thearrivalyear");
	objDateChooserEx1.setXOffset(-10);
	objDateChooserEx1.setYOffset(-10);

	var objDateChooserEx2 = new DateChooser();
	objDateChooserEx2.setEarliestDate(objEarlyDate);
	objDateChooserEx2.setLatestDate(objLateDate);
	objDateChooserEx2.setUpdateField({'thedeparturemonth':'n', 'thedepartureday':'j', 'thedepartureyear':'Y'});
	objDateChooserEx2.setIcon("http://www.muehlenerhof.com//js/datechooser/cal.gif", "thedepartureyear");
	objDateChooserEx2.setXOffset(-10);
	objDateChooserEx2.setYOffset(-10);

	return true;
}

function UpdateCalendars()
{
	var objStartDateEx1 = new Date();
	objStartDateEx1.setMonth(-1);
	objStartDateEx1.setDate();
	objStartDateEx1.setYear();

	var objStartDateEx2 = new Date();
	objStartDateEx2.setMonth(-1);
	objStartDateEx2.setDate();
	objStartDateEx2.setYear();

	var objDateChooserEx1 = new DateChooser();
	objDateChooserEx1.setStartDate(objStartDateEx1);
	objDateChooserEx1.setUpdateField({'arrivalmonth':'n', 'arrivalday':'j', 'arrivalyear':'Y'});
	objDateChooserEx1.setIcon("http://www.muehlenerhof.com//js/datechooser/cal.gif", "arrivalyear");
	objDateChooserEx1.setUpdateField({'thearrivalmonth':'n', 'thearrivalday':'j', 'thearrivalyear':'Y'});
	objDateChooserEx1.setIcon("http://www.muehlenerhof.com//js/datechooser/cal.gif", "thearrivalyear");
	objDateChooserEx1.setXOffset(-10);
	objDateChooserEx1.setYOffset(-10);

	var objDateChooserEx2 = new DateChooser();
	objDateChooserEx2.setStartDate(objStartDateEx2);
	objDateChooserEx2.setUpdateField({'departuremonth':'n', 'departureday':'j', 'departureyear':'Y'});
	objDateChooserEx2.setIcon("http://www.muehlenerhof.com//js/datechooser/cal.gif", "departureyear");
	objDateChooserEx2.setUpdateField({'thedeparturemonth':'n', 'thedepartureday':'j', 'thedepartureyear':'Y'});
	objDateChooserEx2.setIcon("http://www.muehlenerhof.com//js/datechooser/cal.gif", "thedepartureyear");
	objDateChooserEx2.setXOffset(-10);
	objDateChooserEx2.setYOffset(-10);

	return true;
}

function loadItemHandler(carousel, start, last, available) {
	if (!available) {
		for (var i = start; i <= last; i++) {
			if (i > itemList.length) {
				break;
			}
			carousel.add(i, getItemHTML(itemList[i - 1]));
		}
	}
	carousel.loaded();
}

function getItemHTML(url)
{
    return '<img src="' + url + '" width="' + 479 + '" height="' + 324 + '" alt="" />';
}
