/* Path for this file: /content/dam/nissan/codepack/nissan/components/pages/layout/mainlayout.js/jcr:content/renditions/original */
// these were pulled from main JS file into mainlayout.js
/*
jQuery(document).ready(function() {
    if(jQuery("#frameBg").size()>0){
        //jQuery("#frameBg").height(jQuery("#frameContent").height()+20);
    }
    jQuery("#frameContent").click(function(){
        //jQuery("#frameContent").html(jQuery("#frameContent").html()+"<br /><br />");
        //resizeMe(jQuery("#frameContent").height());
    });    
});
function resizeMe(hgt){
    if(jQuery("#frameBg").size()>0){
        jQuery("#frameBg").height(hgt+20);
        if(jQuery("#frameContent").height() + 50 > jQuery("#pageBg").height()){
            //jQuery("#pageBg").height(jQuery("#pageBg").height()+20);
        }
    }
}
*/

jQuery(document).ready(function() {
    if(jQuery.browser.msie && parseInt(jQuery.browser.version) === 6) jQuery('#frameBg + #frameContent').addClass('frameContentHasBg');
 
    if(jQuery("#frameContent").height() + 50 > jQuery("#pageBg").height()){         
            jQuery("#pageBg").css("margin-bottom","50px");
        }
    
});


var xmlhttp;
var ImageToLoad = '';

function loadPageBgImage(url)
{
  xmlhttp=null;
  ImageToLoad = url;
  // code for Mozilla, etc.
  if (window.XMLHttpRequest)
  {
    xmlhttp=new XMLHttpRequest()
  }
  
  // code for IE
  else if (window.ActiveXObject)
  {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  if (xmlhttp!=null)
  {
    xmlhttp.onreadystatechange=loadPageBgStateChange
    xmlhttp.open("GET",url,true)
    xmlhttp.send(null)
  }
  else
  {
    //alert("Your browser does not support XMLHTTP.")
    if (document.getElementById("pageBg")) { 
      document.getElementById("pageBg").style.backgroundImage = "url('/img/bg/bg_gradient.jpg')";
    }
  }
}

function loadPageBgStateChange()
{
  var newUrl = '';
  
  // if xmlhttp shows "loaded"
  if (xmlhttp.readyState==4) {
    // if "OK" 
    if (xmlhttp.status==200) {
      if (document.getElementById("pageBg")) {
        newUrl = "url('" + ImageToLoad + "')";
        
        document.getElementById("pageBg").style.backgroundImage = newUrl;
      }
    } else {
      if (document.getElementById("pageBg")) {
        document.getElementById("pageBg").style.backgroundImage = "url('/img/bg/bg_gradient.jpg')";
      }
    }
  }
}


