function backdown(){
	var refreshId1 = setInterval(function() {
	var optcss = parseFloat($('#popMask').css('opacity'))-0.1;
	$('#popMask').css('opacity', optcss);
	if ( parseFloat(optcss) < 0.2 ){
		backup(); 
		clearInterval(refreshId1);
	}
   }, 150);
}
function backup(){
	var refreshId2 = setInterval(function() {
	var optcss2 = parseFloat($('#popMask').css('opacity'))+0.1;
	$('#popMask').css('opacity', optcss2);
	if ( parseFloat(optcss2) > 1 ){
		backdown();
		clearInterval(refreshId2);
	}
   }, 100);
}

function allmove(){
	var refreshId1 = setInterval(function() {								  
		var movcss1 = parseInt($('#pop').css('left'))-30;
		$('#pop').css('left', movcss1);
		
		var refreshId2 = setInterval(function() {								  
			var movcss2 = parseInt($('#pop').css('left'))+60;
			$('#pop').css('left', movcss2);
			
			var refreshId3 = setInterval(function() {
				var movcss3 = parseInt($('#pop').css('left'))-60;
				$('#pop').css('left', movcss3);
						var refreshId4 = setInterval(function() {
							var movcss4 = parseInt($('#pop').css('left'))+30;
							$('#pop').css('left', movcss4);
							clearInterval(refreshId4);
						}, 300);
				clearInterval(refreshId3);
			}, 300);
			clearInterval(refreshId2);
		}, 300);
		clearInterval(refreshId1);
	}, 300);
	var refreshId5 = setInterval(function() {								  
		var movcss5 = parseInt($('#pop').css('top'))-10;
		$('#pop').css('top', movcss5);
		
		var refreshId6 = setInterval(function() {								  
			var movcss6 = parseInt($('#pop').css('top'))+20;
			$('#pop').css('top', movcss6);
			
			var refreshId7 = setInterval(function() {
				var movcss7 = parseInt($('#pop').css('top'))-20;
				$('#pop').css('top', movcss7);
						var refreshId8 = setInterval(function() {
							var movcss8 = parseInt($('#pop').css('top'))+10;
							$('#pop').css('top', movcss8);
							clearInterval(refreshId8);
						}, 250);
				clearInterval(refreshId7);
			}, 250);
			clearInterval(refreshId6);
		}, 250);
		clearInterval(refreshId5);
	}, 250);
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exhours)
{
var now = new Date();
var time = now.getTime();
var exdays = 0;
time += 3600 * 1000 * exhours;
now.setTime(time);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+ now.toGMTString() );
document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
	var asn_poll_id=getCookie("asn_poll_id");
	if ((asn_poll_id!=null) && (asn_poll_id!=""))
	{
		return true;
	}
	else 
	{
	  return false;
	}
}

$(document).ready(function() 
{
	if (!(checkCookie()))
	{
		popBox.show("#pop");
		$('#pop').show();
		
		$('#pop_nfl').click(function() {
		  window.location.href = "http://www.asn.tv/nfl.php";
		});
	
		$('#pop_close').click(function() {
			popBox.remove("#pop");
			setCookie("asn_poll_id","3",3);
		});
		backdown();
	}
	/*
	var refreshall = setInterval(function() {
		allmove();
	}, 1200);
	$('#pop').mouseover(function() {
		clearInterval(refreshall);
	});
	$('#pop').mouseout(function() {
		refreshall = setInterval(function() {
			allmove();
		}, 1200);
	});
	*/
});
