var isTouch = Modernizr.touchevents,
isMobile = false,
mobile = false,
win_width = 0,
win_height = 0,
navItem = 0,
atH =72,
$menuBtn = jQuery('.menu-handler'),
pageH=atH,
pageNavNum=0,
scrollNav=0,
pageNH=0;
var pageInit = {
init: function () {
win_width = $(window).width();
win_height = $(window).height();
if (win_width <= 1024) {
isMobile = true;
atH =54;
pageH=atH;
} else if (win_width > 1024) {
isMobile = false;
atH =72;
pageH=atH;
if(jQuery(".pageNavBox").length>0){
pageH=atH+40;
}
menu.close();
};
if(jQuery(".pageNavBox").length>0){ scrollNav=jQuery(".pageNavBox").offset().top-pageH;}
},
setImgMax: function (img, imgW, imgH, tW, tH) {
var tWidth = tW || win_width;
var tHeight = tH || win_height;
var coe = imgH / imgW;
var coe2 = tHeight / tWidth;
if (coe < coe2) {
var imgWidth = tHeight / coe;
img.css({ height: tHeight, width: imgWidth, left: -(imgWidth - tWidth) / 2, top: 0 });
} else {
var imgHeight = tWidth * coe;
img.css({ height: imgHeight, width: tWidth, left: 0, top: -(imgHeight - tHeight) / 2 });
};
},
setScroll: function (anchorCur) {
if(jQuery(anchorCur).length>=1){
jQuery("html,body").animate({ scrollTop: jQuery(anchorCur).offset().top-pageH}, 0);
}
},
setErmbox:function (obj, title) {
obj.click(function () {
var str = '
';
$("body").append(str);
jQuery(".ermsblack").fadeIn();
jQuery(".ermSBox").animate({ marginTop: "-132" }, 400);
$(".ermSBox .close").click(function () {
$(".ermsblack").remove();
});
jQuery(".ermsblack").click(function () { $(".ermsblack").remove(); });
return false;
})
},
openbox:function(htmlAddress){
$.ajax({
url: htmlAddress,
dataType: "html",
success: function (data) {
if (data == "" || data == null) {
return;
}
else {
if(jQuery(".md-modal").length>=1){
jQuery('html').removeClass('md-show');
jQuery('.md-modal').remove();
};
$("body").append('');
$('.md-modal .vertical-inner').append(data);
setTimeout(function(){$("html").addClass("md-show");},50);
var tops = $(document).scrollTop();
$(document).bind("scroll",function (){ $(document).scrollTop(tops); });
jQuery('.form-box-close').bind('click',function(e){
jQuery('html').removeClass('md-show').addClass("md-hide");
setTimeout(function(){jQuery('.md-modal').remove();jQuery('html').removeClass('md-hide');},400);
$(document).unbind("scroll");
});
jQuery('.md-modal .vertical-inner').bind('click', function (e) {
if ($(e.target).hasClass('vertical-inner')) {
jQuery('html').removeClass('md-show').addClass("md-hide");
setTimeout(function(){jQuery('.md-modal').remove();jQuery('html').removeClass('md-hide');},400);
$(document).unbind("scroll");
}
});
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
jQuery('html').removeClass('md-show md-hide');
jQuery('.md-modal').remove();
$(document).unbind("scroll");
}
});
},
pbanner:function(){
if(jQuery('.pbanner').length>=1){
if (!isMobile) {
jQuery('.pageBanner').css("height", jQuery(".pageBanner .load-img").height());
jQuery('.aboutPbanner').css("height", win_height-pageH);
pageInit.setImgMax(jQuery(".aboutPbanner .load-img"),1920,900,win_width,win_height-pageH);
}else {
jQuery('.pbanner').css("height", "auto");
}
jQuery(window).scroll(function () {
var sTop = $(window).scrollTop();
if (sTop < win_height && !isMobile) {
jQuery('.pbanner .imgbox').css('transform', "translate(0px," + (sTop) / 2.5 + "px)");
}
});
}
}
},
nav={
init:function(){
jQuery(".pageNav a,.nav .subnav a").click(function(e){
var $this=jQuery(this);
var hash = $this.attr("href").split("#")[1];
if(hash && jQuery("#"+hash).length>=1){
e.preventDefault();
jQuery("html,body").animate({ scrollTop: jQuery("#"+hash).offset().top-pageH},800,'easeInOutExpo');
if(isMobile){
jQuery(this).parent().fadeOut();
}
}
});
}
},
menu={
init:function(){
jQuery(".menu-handler").click(function(){
if (navItem == 0) {
jQuery(this).addClass("active");
jQuery("html").addClass("menuOpen");
navItem = 1;
}else{
jQuery(this).removeClass("active");
jQuery("html").removeClass("menuOpen");
navItem = 0;
}
});
$(document).on("click", ".menuMoblie .nav-link", function (e) {
var mnavcur = $(this);
var mnavbox = $(this).parents("li");
if (mnavbox.find(".subnav").size() > 0) {
if (mnavcur.hasClass("cur")) {
mnavbox.find(".subnav").stop(false, false).slideUp();
mnavcur.removeClass("cur");
} else {
jQuery(".menuMoblie a.nav-link").removeClass("cur");
jQuery(".subnav").stop(false, false).slideUp();
mnavbox.find(".subnav").stop(false, false).slideDown();
mnavcur.addClass("cur");
e.preventDefault();
}
}
});
$(document).on("click", ".menuMoblie a", function (e) {
var $this=jQuery(this);
var hash = $this.attr("href").split("#")[1];
if(hash && jQuery("#"+hash).length>=1){
e.preventDefault();
jQuery("html,body").animate({ scrollTop: jQuery("#"+hash).offset().top-atH},0);
menu.close();
}
});
$(".pusher-black").click(function () {
if (navItem == 1 ) {
menu.close();
};
});
jQuery('.link-select-box').click(function(){
if($(this).hasClass('act')){
$(this).removeClass('act');
$(this).find('.mc').stop().slideUp(300);
}else{
$(this).addClass('act');
$(this).find('.mc').stop().slideDown(300);
}
}).mouseleave(function(){
$(this).removeClass('act');
$(this).find('.mc').stop().slideUp(300);
});
},
close:function(){
$menuBtn.removeClass("active");
jQuery("html").removeClass("menuOpen");
navItem = 0;
}
},
pbanner={
init:function(){
if(jQuery(".load-img").length>=1){
_PreLoadImg([
jQuery(".load-img").attr("src")
],function(){
setTimeout(function() {
jQuery(".pbanner").addClass("active");
}, 50);
pageInit.pbanner();
if(jQuery(".pageNavBox").length>0){ scrollNav=jQuery(".pageNavBox").offset().top-pageH;}
});
jQuery(window).resize(function () {
pageInit.pbanner();
});
}
}
},
pageNav={
init:function(){
jQuery(".cpnavbox a").click(function(e){
var $this=jQuery(this);
var hash = $this.attr("href").split("#")[1];
if(hash && jQuery("#"+hash).length>=1){
e.preventDefault();
jQuery("html,body").animate({ scrollTop: jQuery("#"+hash).offset().top-pageH},800,'easeInOutExpo');
if(isMobile){
jQuery(this).parent().fadeOut();
}
}
});
jQuery(".cpnav").bind("click",function(){
if(pageNavNum==0){
jQuery(this).next(".cpnavbox").stop(false,false).fadeIn();
pageNavNum=1;
}else{
jQuery(this).next(".cpnavbox").stop(false,false).fadeOut();
pageNavNum=0;
}
});
if( jQuery(".pagenav .cpnavbox").length>=1){
if(jQuery(".pagenav .cpnavbox a").length%2!=0){
jQuery(".cpnavbox").addClass("oddpanv");
}
}
}
};
jQuery(window).resize(function () {
pageInit.init();
});
pageInit.init();
$(document).ready(function () {
menu.init();
pbanner.init();
pageNav.init();
pageInit.setErmbox(jQuery('.ermItem'), "扫描此二维码关注澳门新葡");
jQuery(".btnScrollB").bind("click", function() {jQuery("html,body").animate({ scrollTop: jQuery("."+jQuery(".btnScrollB").attr("data-box")).offset().top-pageH},800,'easeInOutExpo');});
jQuery(".syitemB").bind("click", function() {jQuery("html,body").animate({ scrollTop: jQuery("#"+jQuery(".syitemB").attr("data-box")).offset().top-pageH},800,'easeInOutExpo');});
jQuery(".syitemNav a").click(function(e){
var $this=jQuery(this);
var hash = $this.attr("href").split("#")[1];
if(hash && jQuery("#"+hash).length>=1){
e.preventDefault();
jQuery("html,body").animate({ scrollTop: jQuery("#"+hash).offset().top-pageH},800,'easeInOutExpo');
}
});
jQuery(window).scroll(function () {
var windowTop = $(window).scrollTop();
if(windowTop>scrollNav && !isMobile){
jQuery(".pagenav").addClass("fixed");
}else{
jQuery(".pagenav").removeClass("fixed");
};
});
});
//视频弹出关闭
// jQuery(".vwrap .close,.vwrap .videobtg").click(function () {
// jQuery(".vwrap").hide();
// $('#videobox').html("");
// });
// window.onload = function () {
// var hash = location.href.split("#")[1];
// if (hash) {
// pageInit.setScroll("#" + hash);
// }
// }
// WOW
//if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
// new WOW().init();
//};