function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
  	if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
	obj.display=v; }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

var d = document;
function showpic(pic) {
	if (d.images) {
		d.images['bigpic'].src = "themes/cit/images/hotels/"+pic;
		}
}

function OpenWin(u,n,w,h,s)
{
	var l = (screen.width)  ? (screen.width  - w)/2 : 0;
	var t = (screen.height) ? (screen.height - h)/2 : 0;
	var p = window.open(u,n,'width='+w+',height='+h+',scrollbars='+s+',left='+l+',top='+t+',resizable');
	p.focus();
}

function showWaiting() {
  MM_showHideLayers('container-content','','hide');
  MM_showHideLayers('menu_main_long','','show');
  MM_showHideLayers('waiting','','show');
}

function checkCheckBox(f){
if (f.acceptErrata.checked == false )
{
alert('Please confirm that you have read and agree\n to the information shown.');
return false;
}else
return true;
}

function doSubmit(formName,nextPage) {

	var formObject = MM_findObj(formName);

	if (formObject != null)
	{
		if (formObject.nextPage != null)
			formObject.nextPage.value = nextPage;

		formObject.submit();

		return false;
	}

	return true;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function spin(obj)
{
  var spinner = document.getElementById(obj);
  var spinner_content = document.getElementById(obj+"_body" );
  if ( spinner_content.style.visibility == 'visible' )
  {
    //spinner.innerHTML = 'open';
    spinner_content.style.visibility = 'hidden';
	spinner_content.style.display = 'none';
    spinner_content.style.height = '0px';
    spinner_content.style.margin = '0px';
  }
  else
  {
    //spinner.innerHTML = 'close';
    spinner_content.style.visibility = 'visible';
	spinner_content.style.display = 'block';
    spinner_content.style.height = 'auto';
    //spinner_content.style.margin = '5px 0px 20px 20px';
  }
}
function hoteDetails() {
	//alert ("This is hoteDetails")
	//window.location = "#top";
	window.scrollTo(0,0);
	MM_showHideLayers('container-content','','hide','popBook','','hide','booking_tabs','','hide','booking_details_div','','hide','hotel_details_div','','hide','searchresults','','hide','breadcrumbs','','hide','extra_details_div_left_col','','show');
    MM_showHideLayers('menu_main_long','','show');
	MM_showHideLayers('waiting','','show');
	MM_showHideLayers('resAccesCol','','show');
}
function qGetElementById(id)
{
	var elements = document.getElementsByName(id);

	for (var i = 0; i < elements.length; i++)
	{
		if (elements[i].name == elements[i].id)
		    return elements[i];
	}

	return MM_findObj(id);
}

function qDumpObject(object)
{
	var debugWindow = window.open('','debug','scrollbars,status,resizable,location,width=900,height=500');

	debugWindow.document.writeln("<html><head><title>Quatro Debug</title></head>");
	debugWindow.document.writeln("<body><pre>");

	debugWindow.document.writeln(object);

	for (var property in object)
		debugWindow.document.writeln(property + " = " + object[property]);

	debugWindow.document.writeln("</pre></body></html>");
	debugWindow.document.close();
	debugWindow.focus();
}

function validateform(form){
	if(form.fnm.value == "" || form.lnm.value == "" || form.uemail.value == "" || form.confirmEmail.value == "")
	{
		alert("Please supply all required information");
		return false;
	}
	else
	{
		if(form.uemail.value == form.confirmEmail.value)
		{
			var newwindow;
			newwindow = window.open('','NewsletterPopUp','width=400,height=150');
			form.submit();
			document.location.href = "viewPage.vm?viewName=generalConfirmation";
			return true;
		}
		else
		{
		alert("Email Address and Confirmation Email Address are not the same");
		return false;
		}
	}
}

var selected = false;
function changeSelect(select){
	if (!selected){
		var changeSelect = document.getElementById('lowCost');
		changeSelect.style.color = "#B53A59";

		selected = true;
	}else{
		var changeSelect = document.getElementById('lowCost');
		changeSelect.style.color = "#5b5b5b";
		selected = false;
	}
}

var accomSelected = false;
function changeAccomSelect(){

	if (!accomSelected){
		var changeSelect = document.getElementById('checkBoxThisAccom');
		changeSelect.style.color = "#B53A59";
		accomSelected = true;
	}else{
		var changeSelect = document.getElementById('checkBoxThisAccom');
		changeSelect.style.color = "#5b5b5b";
		accomSelected = false;
	}
}

function checkValueBoxAccom(){

		var checkBoxAccom = document.getElementById('checkBoxThisAccomCheck');
		if (checkBoxAccom.checked == true){
			accomSelected = true;
    		var changeSelect = document.getElementById('checkBoxThisAccom');
    		changeSelect.style.color = "#B53A59";

		}
}

var firstTime = true;

function checkValueBox(){
	var checkBoxCheck = document.getElementById('lowCostCheckBox');
	if (checkBoxCheck && checkBoxCheck.checked == true){
		selected = true;
		var changeSelect = document.getElementById('lowCost');
		changeSelect.style.color = "#B53A59";
	}
}

function checkFirstTime(){
	if (firstTime){
		var checkBoxCheck = document.getElementById('lowCostCheckBox');

		if (checkBoxCheck) {
    		checkBoxCheck.checked = true;
    		selected = true;
    		var changeSelect = document.getElementById('lowCost');
    		changeSelect.style.color = "#B53A59";
		}
	}
}

//IMAGE PAGINATION
function imgPaging(n){
	var count = document.getElementById("count");
	count.innerHTML = "Picture <strong>"+n+"</strong> of <strong>"+imgs.length+"</strong>";
}

function imgNext(){

	var match;
	targ = document.getElementById("hotelImage");

	if(targ){
		s = targ.src;
		for(i=0;i<imgs.length;i++){
			if(s.indexOf(imgs[i])!=-1){match=i;}
		}
		nextImg = match+1;
		next = nextImg+1;
		if(nextImg<imgs.length){
			targ.src = imgs[nextImg];imgPaging(next);}else{targ.src = imgs[0];imgPaging(1);}
	}
	return false;
}

function imgPrev(){
	var match;
	targ = document.getElementById("hotelImage");

	if(targ){
		s = targ.src;
		for(i=0;i<imgs.length;i++){
			if(s.indexOf(imgs[i])!=-1){match=i;}
		}
		prevImg = match-1;
		if (prevImg < 0){
			prevImg = imgs.length-1;
		}
		prev = prevImg+1;


		if(prevImg>=0){targ.src = imgs[prevImg];imgPaging(prev);}


	}
	return false;
}

function swapMapAdriaticRiviera() { document.italyMap.src="themes/cit/images/maps/adriaticRiverieraMap.jpg"; }
function swapMapBasilicata() { document.italyMap.src="themes/cit/images/maps/basilicataMap.jpg"; }
function swapMapCalabria() { document.italyMap.src="themes/cit/images/maps/calabriaMap.jpg"; }
function swapMapItalianCities() { document.italyMap.src="themes/cit/images/maps/italianCitiesMap.jpg"; }
function swapMapItalianLakes() { document.italyMap.src="themes/cit/images/maps/italianLakesMap.jpg"; }
function swapMapLazio() { document.italyMap.src="themes/cit/images/maps/lazioMap.jpg"; }
function swapMapLiguria() { document.italyMap.src="themes/cit/images/maps/liguriaMap.jpg"; }
function swapMapNeapolitanRiviera() { document.italyMap.src="themes/cit/images/maps/neapolitanRivieraMap.jpg"; }
function swapMapPuglia() { document.italyMap.src="themes/cit/images/maps/pugliaMap.jpg"; }
function swapMapSardinia() { document.italyMap.src="themes/cit/images/maps/sardiniaMap.jpg"; }
function swapMapSicily() { document.italyMap.src="themes/cit/images/maps/sicilyMap.jpg"; }
function swapMapTuscany() { document.italyMap.src="themes/cit/images/maps/tuscanyMap.jpg"; }
function swapMapUmbria() { document.italyMap.src="themes/cit/images/maps/umbriaMap.jpg"; }
function restoreMap() { document.italyMap.src="themes/cit/images/maps/italyMap.jpg"; }

function hotelToOptions(){
	window.scrollTo(0,0);
	MM_showHideLayers('waiting','','show');
	MM_showHideLayers('container-content','','hide');
}
function matchHeights() {
	$('.heightmatch').each(function() {
		var maxHeight = 0;
		$(this).children('.cell').each(function() {
			$(this).css('height', 'auto');
			if ($(this).height() > maxHeight)
				maxHeight = $(this).height();
		});
		$(this).children('.cell').css('height', maxHeight);
	});
}
function popuponclick(hotelID) {
	my_window = window.open(Global.url+"tripAdvisor.vm?hotelID="+hotelID, "mywindow","status=1,width=800,height=600,scrollbars=yes");
}

function onChangeSortSearchResults(select) {
	sortBy = select.options[select.selectedIndex].value;
	if (sortBy != 'choose') {
		location.href=sortBy;
	}
}

var facts = ["Established in 1870 L'Antica Pizzeria da Michele is the oldest pizzeria in Naples, the city that invented pizza.",
             "Audrey Hepburn side-saddled Gregory Peck's Vespa for a ride through Rome in the 1952 film Roman Holiday. The flick resulted in more than 100,000 sales of the iconic Italian scooter.",
             "Approximately 3,000 euro coins are thrown into the Trevi Fountain every day.",
             "The Bellini was invented in 1948 by Giuseppe Cipriani at Harry's Bar in Venice, using the local white peaches.",
             "At approximately 109 acres, with a population of around 800, the Vatican in Rome is the smallest independent state in the world.",
             "Citalia sell tickets for the Verona opera from as little as &pound;25.",
             "All Citalia city hotels are centrally located with 90% offering an early booking discount or free night offers.",
             "You can pre-book an excursion such as the Amalfi Coast drive from as little as &pound;24."];
var index = 0;
function getFact() {
	$('#facts p').html(facts[index]).animate({top: '0'}, 500);
	setTimeout(function() {
		$('#facts p').fadeOut(1000, function() {
			$(this).css({'top':'100px','display':'block'}).empty();
			index++;
			if(index == facts.length) {
				index=0;
			}
			getFact();
		});
	}, 5000);
}

$(document).ready(function(){

	$('#globalnav .hasSubMenu a').hover( function() {
		$(this).next('.subMenu').show();
	}, function() {
		$(this).next('.subMenu').hide();
	});

	$('#globalnav .subMenu').hover( function() {
		$(this).show();
	}, function() {
		$(this).hide();
	});

	$(".filterThis img,#destinationWrapper img").fadeTo("fast", 1.0); // This sets the opacity of the thumbs to fade down to 60% when the page loads
	$(".filterThis img,#destinationWrapper img").hover(function(){
	$(this).fadeTo("fast", 0.4); // This should set the opacity to 100% on hover
},function(){
	$(this).fadeTo("fast", 1.0); // This should set the opacity back to 60% on mouseout
});

	$("#collectionsMenu li img.collectionsMenuImage").fadeTo("fast", 1.0);
	$("#collectionsMenu li img.collectionsMenuImage").hover(function(){
	$(this).fadeTo("fast", 0.4);
},function(){
	$(this).fadeTo("fast", 1.0);
});

		$("a.popup").fancybox({
			'overlayOpacity'	: 0.8,
			'overlayColor'		: '#000',
	        'autoScale'     	: false,
			'type'				: 'iframe',
			'titleShow'			: false
		});

		$("a.popup_large").fancybox({
			'overlayOpacity'	: 0.8,
			'overlayColor'		: '#000',
	        'autoScale'     	: false,
			'type'				: 'iframe',
			'titleShow'			: false,
			'width'				: 740,
			'height'			: 500
		});

		$("a.popup_tripAdvisor").fancybox({
			'overlayOpacity'	: 0.8,
			'overlayColor'		: '#000',
	        'autoScale'     	: false,
			'type'				: 'iframe',
			'titleShow'			: false,
			'width'				: 785,
			'height'			: 500
		});

		$("a.popup_video").fancybox({
			'overlayOpacity'	: 0.8,
			'overlayColor'		: '#000',
	        'autoScale'     	: false,
			'type'				: 'iframe',
			'titleShow'			: false,
			'width'				: 504,
			'height'			: 491
		});

		$("a.popup_360").fancybox({
			'overlayOpacity'	: 0.8,
			'overlayColor'		: '#000',
	        'autoScale'     	: false,
			'type'				: 'iframe',
			'titleShow'			: false,
			'width'				: 570,
			'height'			: 330
		});

        $("a.fancybox-large").fancybox({
    		'overlayOpacity'	: 0.8,
    		'overlayColor'		: '#000',
    		'centerOnScroll'	: true,
            'autoScale'     	: false,
    		'titleShow'			: false,
    		'width'				: 785,
			'height'			: 500,
			'autoDimensions'	: false
        });
});
