/**
 * @author mryan
 * 
 * This code is used to create the "DHTML Slider" popup on RxPop.com
 * 
 * It reveals a hidden div layer which animates across the screen using the interval function.
 * 
 * 
 */

var foo = document.getElementById('dhtmlslider'); // object

var windowwidth;
var sliderwidth;
var moveto;

function doMove() {
	if (parseInt(foo.style.left) >= parseInt(moveto))
	{		
		var currDate = new Date();
        var newDate = new Date(currDate.getFullYear(), currDate.getMonth() + 6, currDate.getDate(), currDate.getHours(), currDate.getMinutes(), currDate.getSeconds())
        //alert(newDate.toGMTString());
        document.cookie = "ScrollerCookie=true;expires=" + newDate.toGMTString();		
	} 
	else
	{
		//alert(moveto);
		foo.style.left = parseInt(foo.style.left)+10+'px';
		//alert(foo.style.left);
		setTimeout(doMove,20); // call doMove in 20msec		
	}
  	
}

function init() {
	//alert(window.innerWidth);
	//alert(document.body.offsetWidth);	
	
  foo = document.getElementById('dhtmlslider1'); // get the "foo" object
  
  windowwidth = document.body.offsetWidth;
  sliderwidth = foo.style.width;
  
  //alert(windowwidth);
  //alert(sliderwidth);
  
  moveto = (parseInt(windowwidth)/2) - (parseInt(sliderwidth)/2);
  
  //alert(parseInt(moveto));
  
  foo.style.left = '-470px'; // set its initial position to 0px
  setTimeout(doMove,60000); // start animating
  //setTimeout(doMove,0); // start animating
}

function closeModal(div)
{
	document.getElementById(div).style.display = 'none';
};

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

if (get_cookie("ScrollerCookie") != "true")
{
    window.onload = init;
}
