var RandomProduct = new function() { this.handle = null; this.m_elmnt1 = null; this.m_elmnt2 = null; this.Init = function() { var elmnt = document.getElementById("randomProduct"); elmnt.innerHTML = "
"; this.m_elmnt1 = document.getElementById("randomProductOne"); this.m_elmnt2 = document.getElementById("randomProductTwo"); this.m_elmnt2.style.left = "200px"; this.handle = window.setInterval(RandomProduct.Reload, 10000); } this.Reload = function() { $.get("randomProduct.inc.php", function(data) { RandomProduct.m_elmnt2.innerHTML = data; $(RandomProduct.m_elmnt2).animate({left: "0px"}, 1000); $(RandomProduct.m_elmnt1).animate({left: "-200px"}, 1000, null, RandomProduct.MovementFinished); }); } this.MovementFinished = function() { RandomProduct.m_elmnt1.style.left = "200px"; var temp = RandomProduct.m_elmnt1; RandomProduct.m_elmnt1 = RandomProduct.m_elmnt2; RandomProduct.m_elmnt2 = temp; } this.Pause = function() { window.clearInterval(this.handle); } this.Resume = function() { this.handle = window.setInterval(RandomProduct.Reload, 10000); } }