/**
* ALBERGO FIRENZE MAIN JS PAGE
*
* @author: Tosom s.r.l
* @version: 1.0.1
*
* 1.0 -> 1.0.1
* DATE:: 2014-09-25
* BUGFIX :: content panel opening /closing issue between resize and auto-open
*
*
*
*/
var CP = {
bgslider : false ,
pageData : {}
} ;
// DEBUG
function trace(m){if(window.console){window.console.log(m);}}
$(document).ready(function(){
// SETUP GLOBAL DATA
CP.pageData.menu = $("#left-menu") ;
CP.pageData.contentSel = false ;
CP.pageData.content = $("#content") ;
CP.pageData.contentStatus = false ;
CP.pageData.contentWidth = 675 ;
CP.pageData.bookingForm = document.forms["bookingevolution"] ;
CP.pageData.today = new Date() ;
CP.pageData.bookNow = $("#booknow") ;
CP.pageData.openContentSpeed = 400 ;
CP.pageData.UA = navigator.userAgent ;
CP.isSmartphone = false ;
// Setup needed local vars
var tmp = false ;
// CHECK SMARTPHONES
// Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini
//trace("• • • • • • • • • • • • • • • • • • • • • • • • • ");
//trace(navigator.userAgent)
if( /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(CP.pageData.UA) )
{
// Check for android smartphones
if( /Android/i.test(CP.pageData.UA) )
{
if( /Mobile/i.test(CP.pageData.UA ) )
{
CP.isSmartphone = true ;
}
}
else
{
CP.isSmartphone = true ;
}
}
//trace(CP.isSmartphone);
//trace("• • • • • • • • • • • • • • • • • • • • • • • • • ");
// NEXUS 7
// Mozilla/5.0 (Linux; Android 4.3; Nexus 7 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.72 Safari/537.36
// NEXUS s
// Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Nexus S Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
// HTC ONE EVO ...
// Mozilla/5.0 (Linux; Android 4.0.3; HTC One X Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19
/*
// USED FOR PAGE RESIZE => Dropped media queries are better
var menuItem = $(".menu-item") ;
var menuItemA = $(".menu-item a") ;
CP.pageData.menuCss = {
menuItem : menuItem ,
menuItemA : menuItemA ,
item : {
width : menuItem.css("width") ,
height : menuItem.css("height") ,
paddingTop : menuItem.css("paddingTop") ,
borderBottom : menuItem.css("borderBottom")
},
itemA :
{
width : menuItemA.css("width") ,
height : menuItemA.css("height") ,
margin : menuItemA.css("margin") ,
lineHeight : menuItemA.css("lineHeight") ,
textDecoration : menuItemA.css("textDecoration") ,
color : menuItemA.css("color") ,
fontSize : menuItemA.css("fontSize") ,
fontWeight : menuItemA.css("fontWeight")
}
}
//trace(CP.pageData.menuCss)*/
CP.pageData.triggers = {
contentClose : $("#trigger-content-close")
};
// SETUP MAIN PAGE SLIDER
if( CP.isSmartphone )
{
CP.bgslider = new bgslider({
sliderId : "bgslider" ,
timingsTransition : 500 ,
timingsSlide : 5000 ,
slides : SLIDES["mobile"]
});
}
else
{
CP.bgslider = new bgslider({
sliderId : "bgslider" ,
timingsTransition : 500 ,
timingsSlide : 5000 ,
slides : SLIDES["hotel"]
});
}
// SETUP FANCYBOX
$("a.fancybox").fancybox({
nextMethod : 'resizeIn',
nextSpeed : 250 ,
prevMethod : false ,
padding : 0 ,
empty:true
});
$("a#trigger-langsel").fancybox({
width : 310,
height : 300,
autoSize : false,
fitToView : false,
padding : 0 ,
empty:true
});
/*
// DATE PICKER => DROPPED
var maxDate = new Date();
maxDate.setMonth( maxDate.getMonth()+15 );
$( "#checkin" ).datepicker({
dateFormat : "yy-mm-dd" ,
altField : "#checkin",
altFormat : "yy-mm-dd" ,
minDate : 0 ,
maxDate : maxDate,
buttonImage : './images/calendar-alt-1.png',
buttonImageOnly : true,
//numberOfMonths : 2,
onSelect : function(date){ handleSelectedDate(date) },
/*changeMonth: true,
changeYear: true,* /
showOn: 'both',
beforeShow : function(input,inst){
setTimeout( function(){
trace("Datepicker position fix by js.");
var height = parseInt(window.innerHeight) ;
var left = -270 ;
height -= 280 ;
$("#ui-datepicker-div").css({/*top:height+"px", * /marginLeft:left+"px"}) ;
}, 10 );
},
empty:true
});
// Bind Events => DROPPED
// var selD = $("#be-datesel-d")[0] ;
$("#be-datesel-my").on("change",function(){handleSelectedDate()})
$("#be-datesel-d").on("change",function(){handleSelectedDate()})
handleSelectedDate()
*/
/*
//SETUP DATEPICKER
$(".datepicker").datepicker({
dateFormat :"DD, d MM, yy" ,
altField : "#checkin",
altFormat : "yy-mm-dd" ,
minDate : 0
});
//$(".datepicker").datepicker("show");
$(".datepicker").datepicker("setDate",+1);
*/
// BIND EVENTS & TRIGGERS
if( CP.isSmartphone )
{
}
else
{
// IF NOT SMARTPHONE
// Auto-resize calculations
$(window).resize(function(){ winResize(); });
// Bind triggers
$(".menu-item").on("click",function(){showContent( $(this).attr("data-id") );})
$("#trigger-book-now").on("click",function(){ CP.pageData.bookingForm["s"].click() }) ;
// General triggres and css fix
CP.pageData.triggers.contentClose.css({opacity:0});
CP.pageData.triggers.contentClose.on("click",function(){toggleContent();})
// Resize page
winResize();
}
// Launch needed stuff
hidegmap();
showMenu();
window.setTimeout( function(){showOverlayMain();} , 250 );
$("#overlay-main").on("click",function(){ hideOverlayMain() } );
//window.setTimeout( function(){showContent("location");} , 1000 )
//window.setTimeout( function(){openContent();} , 1000 )
});
function trace(m){ if(window.console){window.console.log(m);} }
function pageConsoleAdd(m,clear)
{
if(typeof m =="string")
{
var str = "" ;
if( typeof clear == "undefined" || clear===false )
{
if( $("#console pre").html()!="" )
{
str = $("#console pre").html()+"\n" ;
}
}
str+= '> '+m ;
$("#console pre").html(str)
}
}
function showOverlayMain()
{
var ol = $("#overlay-main");
ol.stop().fadeIn(500);
}
function hideOverlayMain()
{
var ol = $("#overlay-main");
ol.stop().fadeOut(250);
}
function winResize()
{
// GET WINDOW SIZE
if( !CP.pageData.winSize )
{ CP.pageData.winSize = [ $(window).width() , $(window).height() ] ; }
else
{
CP.pageData.winSize[0] = $(window).width() ;
CP.pageData.winSize[1] = $(window).height() ;
}
// Consider bottom reservation form
//var bh = parseInt( CP.pageData.bookNow.height() )
var bh = 0 ;
//bh = $("footer").height() ;
bh = 46;// Manual Footer height
// Reset menu height
CP.pageData.menu.css({height:CP.pageData.winSize[1]-bh } ) ;
if( CP.pageData.contentStatus )
{
// Check and eventually reset content
var newWidth = CP.pageData.contentWidth ;
var menuWidth = CP.pageData.menu.width() ;
var contentWidth = CP.pageData.content.width() ;
//trace("WR: "+contentWidth ) ;
//trace("WR: "+menuWidth+"+"+contentWidth+"("+( menuWidth+contentWidth )+") > "+CP.pageData.winSize[0]+"-"+"50 ("+(CP.pageData.winSize[0]-50 )+")" ) ;
if( menuWidth+contentWidth >= CP.pageData.winSize[0]-50 )
{
newWidth = CP.pageData.winSize[0]-menuWidth-50 ;
}
CP.pageData.content.stop();
CP.pageData.triggers.contentClose.stop();
CP.pageData.triggers.contentClose.css({left:newWidth+menuWidth+10})
CP.pageData.content.css( { width:newWidth , height:CP.pageData.winSize[1]-bh } )
//trace("RESIZE NW=>"+newWidth) ;
}
// RESET TOP IMAGES HEIGHT
// #content .inner-content table.top-images td .top-img-box .icon
//var topImageHeight = $("#content .inner-content table.top-images td .top-img-box img").height()+1 ;
var topImageHeight = 0 ;
if( CP.pageData.contentSel!==false )
{
topImageHeight = CP.pageData.contentSel.find("table.top-images td .top-img-box img").height() ;
$("#content .inner-content table.top-images td .top-img-box .caption" ).height( topImageHeight ) ;
$("#content .inner-content table.top-images td .top-img-box .icon" ).height( topImageHeight ) ;
}
/* // DISABLED !!! =>use media queries
// HANDLE LEFT MENU-ITEMS
var ratio = 1 ;
var newVal = 0 ;
var refVal = 1024 ;
var currHeight = CP.pageData.winSize[1]
// LIMIT HEIGHT MIN TO 768
if( currHeight < 768 ){ currHeight=768; }
// LIMIT HEIGHT MAX TO REF VAL
if( currHeight > refVal ){ currHeight=refVal; }
// MENU ITEM HEIGHT
//CP.pageData.menuCss.menuItem.css({backgroundColor:"red"})
ratio = parseInt( CP.pageData.menuCss.item.height.replace(/px/g,"") )/refVal ;
newVal = currHeight * ratio ;
CP.pageData.menuCss.menuItem.css({height:newVal+"px",lineHeight:newVal+"px"})
// APPLY %
newVal = newVal*70/100;
// MENU ITEM-A HEIGHT
//CP.pageData.menuCss.menuItemA.css({backgroundColor:"green"})
ratio = parseInt( CP.pageData.menuCss.itemA.height.replace(/px/g,"") )/refVal ;
newVal = currHeight * ratio ;
CP.pageData.menuCss.menuItemA.css({height:newVal+"px",lineHeight:newVal+"px"})
// APPLY %
newVal = newVal*70/100;
// HANDLE FONT SIZE
ratio = parseInt( CP.pageData.menuCss.itemA.fontSize.replace(/px/g,"") )/refVal ;
newVal = currHeight * ratio ;
// Apply 90%
newVal = newVal*90/100;
trace(newVal)
CP.pageData.menuCss.menuItemA.css({fontSize:newVal+"px"})
*/
/*f : 1024 = x : ws1
wsf/1024 = x/ws1
x = ws1 * (f/2014)*/
//trace(CP.pageData.winSize);
//trace("____________________________________________")
}
function showMenu()
{
CP.pageData.menu.stop();
CP.pageData.menu.css({ opacity:0, display:"block" }) ;
CP.pageData.menu.animate({opacity:1});
}
function showContent(id)
{
//trace("SHOW CONTENT => "+id)
// SPECIAL EVENT FOR RATES
if( id=="rates" )
{openbe2('hfirenze',CURR_LANG.be);return;}
var selId = false ;
if( CP.pageData.contentSel)
{
selId = CP.pageData.contentSel.attr("id");
selId = selId.split("-") ;
selId = selId[1] ;
}
if( CP.pageData.contentSel==false || selId!=id ) //CP.pageData.contentSel.attr(id)!=id )
{
//trace("CHANGE SLIDES")
CP.bgslider.slidesChange( SLIDES[id] )
//openContent();
if( CP.pageData.contentSel != false )
{
/*CP.pageData.contentSel.stop().animate({opacity:0},"fast",function(){
CP.pageData.contentSel.css({display:"none"});
CP.pageData.contentSel=false ;
$(".menu-item a").removeClass("sel");
CP.pageData.contentSel = $("#content-"+id) ;
CP.pageData.contentSel.css({opacity:0,display:"block"});
CP.pageData.contentSel.animate({opacity:1});
$("#menu-"+id+" a").addClass("sel");
if(id=="location")
{ showgmap(); }
else
{ hidegmap(); }
});*/
if( CP.pageData.contentStatus )
{
closeContent({
id : id ,
onComplete:function(id){
CP.pageData.contentSel.css({display:"none"});
CP.pageData.contentSel=false ;
$(".menu-item a").removeClass("sel");
CP.pageData.contentSel = $("#content-"+id) ;
CP.pageData.contentSel.css({opacity:0,display:"block"});
CP.pageData.contentSel.animate({opacity:1});
$("#menu-"+id+" a").addClass("sel");
if(id=="location")
{ showgmap(); }
else
{ hidegmap(); }
//openContent()
$("#content")[0].scrollTop = 0 ;
window.setTimeout( function(){ openContent() } , 500 );
}
});
}
else
{
// Content alraeady closed, show it then open !
CP.pageData.contentSel.css({display:"none"});
CP.pageData.contentSel=false ;
$(".menu-item a").removeClass("sel");
CP.pageData.contentSel = $("#content-"+id) ;
CP.pageData.contentSel.css({opacity:0,display:"block"});
CP.pageData.contentSel.animate({opacity:1});
$("#menu-"+id+" a").addClass("sel");
if(id=="location")
{ showgmap(); }
else
{ hidegmap(); }
//openContent()
$("#content")[0].scrollTop = 0 ;
window.setTimeout( function(){ openContent() } , 500 );
}
}
else
{
CP.pageData.contentSel = $("#content-"+id) ;
CP.pageData.contentSel.css({opacity:0,display:"block"});
CP.pageData.contentSel.animate({opacity:1});
$("#menu-"+id+" a").addClass("sel");
if(id=="location")
{ showgmap(); }
else
{ hidegmap(); }
openContent();
}
}
}
function showgmap()
{
var html = '' ;
var gmap = $("#gmap") ;
gmap.stop();
gmap.html(html);
gmap.slideDown(400,function(){ });
}
function hidegmap()
{
var gmap = $("#gmap") ;
gmap.stop().slideUp("fast",function(){
gmap.html("");
});
}
function toggleContent()
{
if( CP.pageData.contentStatus==true )
{closeContent();}
else
{openContent();}
}
function openContent()
{
if( CP.pageData.contentStatus )
{ return; }
//trace("OPEN CONTENT")
var newWidth = CP.pageData.contentWidth ;
var menuWidth = CP.pageData.menu.width();
//trace("OC: "+menuWidth+"+"+CP.pageData.contentWidth+" > "+CP.pageData.winSize[0]+"-"+"50" ) ;
if( menuWidth+CP.pageData.contentWidth > CP.pageData.winSize[0]-50 )
{
newWidth = CP.pageData.winSize[0]-menuWidth-50 ;
}
CP.pageData.content.stop();
CP.pageData.content.css({
width : 0 ,
height : CP.pageData.winSize[1],
borderRight:"20px solid #fff",
overflow:"hidden"
});
CP.pageData.triggers.contentClose.stop();
CP.pageData.triggers.contentClose.css({left:menuWidth,opacity:1})
CP.pageData.triggers.contentClose.animate({left:newWidth+menuWidth+10,opacity:1},CP.pageData.openContentSpeed)
CP.pageData.content.animate(
{width : newWidth },
CP.pageData.openContentSpeed ,
function(){
CP.pageData.contentStatus=true ;
CP.pageData.content.css({overflow:"auto"});
CP.pageData.triggers.contentClose.removeClass("closed");
winResize();
}
);
}
function closeContent(opts)
{
if( !CP.pageData.contentStatus )
{ return; }
var menuWidth = CP.pageData.menu.width();
CP.pageData.content.stop();
CP.pageData.content.css({
overflow:"hidden"
});
CP.pageData.triggers.contentClose.stop();
CP.pageData.triggers.contentClose.removeClass("closed");
CP.pageData.triggers.contentClose.animate({left:menuWidth-10},"fast",function(){ /*CP.pageData.triggers.contentClose.css({opacity:0})*/
CP.pageData.triggers.contentClose.addClass("closed");
});
CP.pageData.content.animate({
width : 0
},"fast",
function(){
CP.pageData.contentStatus=false ;
CP.pageData.content.css({borderRight:0})
if( typeof opts =="object" )
{
if( typeof opts.onComplete == "function" ){ opts.onComplete(opts.id); }
}
}
);
}
/*
function handleSelectedDate(date)
{
var dt = false
var selD = $("#be-datesel-d")[0] ;
var selMY = $("#be-datesel-my")[0] ;
var chkin = $("#checkin")[0] ;
if( typeof date == "undefined" )
{
var tmp = selMY[ selMY.selectedIndex ].value ;
tmp = tmp.split("-") ;
date = tmp[1]+"-"+tmp[0]+"-" ;
date += selD[selD.selectedIndex].value ;
}
dt = date.split("-") ;
for( var i=0 ; i= maxDays )
{ selD.selectedIndex = maxDays-1; }
// Reset select days
for( var i=0 ; imaxDays )
{disable=true}* /
if( disable )
{ selD[i].setAttribute("disabled","deisabled"); }
}* /
}
*/