var mia_url="";
var mia_title="";
var about_title="北美麦唐娜国际学院";
var about_url="about.html";

jQuery(window).load(function(){
jQuery('#mobile-trigger1').on("click", function() {
   //alert(path);
    window.location.href = path;

});
jQuery('.home article.hentry').on("click", function() {
    if(jQuery(this).find("a").length==0)return;
    window.location.href = jQuery(this).find("a").attr("href");

});
jQuery('.home article.hentry a').on("click", function(e) {
    e.preventDefault();

});

jQuery('.category article.hentry').on("click", function() {
    if(jQuery(this).find("a").length==0)return;
    window.location.href = jQuery(this).find("a").attr("href");

});
jQuery('.category article.hentry a').on("click", function(e) {
    e.preventDefault();

});

jQuery('div[data-role="navbar"] li.link').on("click", function() {
    window.location.href = jQuery(this).find("a").attr("href");

});

jQuery('div[data-role="navbar"] li a').on("click", function(e) {
   e.preventDefault();
});

jQuery('div[data-role="navbar"] li.home').on("click", function(e) {
   window.location.href=path;
});
jQuery('div[data-role="navbar"] li.back').on("click", function(e) {
   //window.history.back();
    window.location.href = jQuery(this).find("a").attr("href");

});
jQuery('article.mia').unbind();
jQuery('article.mia').on("click", function() {
    storage.setItem("page_mia",1);
    openUrl(jQuery(this).find("a").attr("href"));
    return false;
});

jQuery('article.mia a').on("click", function(e) {
     e.preventDefault();
});

jQuery('a.mia').on("click", function(e) {
    e.preventDefault();
    openUrl(jQuery(this).attr("href"));
    return false;
});

//no media to play
handlewipe();
var language = window.navigator.userLanguage || window.navigator.language;
console.log(language);
if(language=="zh-TW"||language=="zh-HK") translateBody();
else translateBody();
if(jQuery("#post-505").length>0&&1==2){
  mia_url=jQuery("#post-505 h2.entry-title a").attr("href");
  mia_title=jQuery("#post-505 h2.entry-title a").text(); 
  setInterval(adrotate, 3000);
}


});

function handlewipe(){
    var ol = document.getElementById('content');

    ol.addEventListener('slip:beforeswipe', function(e){
        
        swipe=e.detail.directionX;
        if(swipe=="left"&&next=="#")e.preventDefault();
        if(swipe=="right"&&prev=="#")e.preventDefault();
         // alert(e.detail.directionX);
         //   e.preventDefault();
        
    }, false);

    ol.addEventListener('slip:afterswipe', function(e){
       //alert(swipe);
        //console.log(e);
         if(swipe=="left")window.location=next;
         else window.location=prev; 
    }, false);
   ol.addEventListener('slip:cancelswipe', function(e){
       //alert(swipe);
        //console.log(e);
         if(swipe=="left")window.location=next;
         else window.location=prev; 
    }, false);

    new Slip(ol);
}

function openUrl(url){
  window.open(url, '_blank', 'location=yes,closebuttoncaption=返回,hardwareback=no');
}

function adrotate(){
  var dom= jQuery("#post-505 h2.entry-title a")
  var lt=dom.attr("href");
 // alert(lt+":"+about_url);
  if(lt==about_url){
     dom.text(mia_title);
     dom.attr("href",mia_url);
     dom.on("click", function(e) {
       e.preventDefault();
       openUrl(jQuery(this).attr("href"));
       storage.setItem("page27",1)
       return false;
     });
  }
  else{
    dom.text(about_title);
    dom.attr("href",about_url);
    jQuery("#post-505").removeClass("mia")
    dom.unbind();
  }
}
