// JavaScript Document

function pop_event(sid, action)
{
	try {
		ntptAddPair("id", sid);
		ntptAddPair("action", escape(action));
		ntptEventTag("ev=popup");
	} catch (e){}
}
function close_nonpop()
{
	$('#'+npops[popname].id).hide();
	$.dimScreenStop();
	pop_event(npops[popname].keycode, 'close');
}
function follow_nonpop()
{
	$('#'+npops[popname].id).hide();
	$.dimScreenStop();
	pop_event(npops[popname].keycode, 'follow');
}
// function show( id, state ) {
//	var what = document.getElementById( id );
//	what.style.visibility = (state)?'visible':'hidden';
//	what.style.display = (state)?'block':'none';
// }
function getyoffset()
{
	var y_offset = 0;
	if (self.pageYOffset) // all except Explorer
		{ y = self.pageYOffset; }
	else if (document.documentElement.scrollTop) // Explorer 6 Strict
		{ y = document.documentElement.scrollTop; }
	else if (document.body) // all other Explorers
		{ y = document.body.scrollTop; }
	return y;
}
function show_nonpop()
{
	var now = new Date().getTime();
	// When did we see it last?
	if( (crumbs.data['$'+npops[popname].keycode+'_LastTime']===undefined) || ( now > (crumbs.data['$'+npops[popname].keycode+'_LastTime']+npops[popname].show_next) ) )
	{
		// ...but no more than show_max times ever.
		if( !crumbs.data['$'+npops[popname].keycode+'_Count'] || (crumbs.data['$'+npops[popname].keycode+'_Count'] < npops[popname].show_max) )
		{
			++crumbs.data['$'+npops[popname].keycode+'_Count'];
			crumbs.data['$'+npops[popname].keycode+'_LastTime'] = now;
			crumbs.store('ads');
			$.dimScreen(1000, 0.5, function() {});
			lpos = (document.body.offsetWidth-npops[popname].w)/2;
			npops[popname].hid = document.getElementById(npops[popname].id);
			npops[popname].hid.style.top = (parseInt(getyoffset()+npops[popname].y, 10)+'px');
			npops[popname].hid.style.left = (parseInt(lpos, 10)+'px');
			$('#'+npops[popname].id).show();
			pop_event(npops[popname].keycode, 'open');
			if(npops[popname].init){ npops[popname].init(); }
			nonpop_scroll();
		}
	}
}
function scrollad()
{
	cypos += parseInt(dypos, 10);
	if(dypos>0)	{ if(cypos>nypos){ cypos = nypos; } }
	else				{ if(cypos<nypos){ cypos = nypos; } }
	npops[popname].hid.style.top = (parseInt(cypos, 10)+'px');
	if(cypos==nypos){ clearInterval(npops[popname].tid); }
}
function nonpop_load()
{
	crumb = crumbs.fetch('ads');
	if((crumbs.data.hasLogin===true)||document.cookie.match('PubUser'))
	{
		if(!crumbs.data.hasLogin)
		{
			crumbs.data.hasLogin = true;
			crumbs.store('ads');
		}
	}
	var bshownonpop = ((npops[popname].show_auth===false)&&(crumbs.data.hasLogin===true)) ? false : true;
	if( bshownonpop ){ npops[popname].tid = setTimeout( show_nonpop, npops[popname].delay ); }
}
function nonpop_resize()
{
	if(npops[popname].hid)
	{
		lpos = (document.body.offsetWidth-npops[popname].w)/2;
		npops[popname].hid.style.top = (parseInt(getyoffset()+npops[popname].y, 10)+'px');
		npops[popname].hid.style.left = (parseInt(lpos, 10)+'px');
	}
}
function nonpop_scroll()
{
	if(npops[popname].hid)
	{
		npops[popname].tid = clearInterval(npops[popname].tid);
		cypos = parseInt(npops[popname].hid.style.top, 10);
		nypos = parseInt(getyoffset()+npops[popname].y, 10);
		dypos = (nypos - cypos)/40;
		if(dypos>0)	{ dypos = (dypos<1)?1:dypos; }
		else				{ dypos = (dypos>-1)?-1:dypos; }
		npops[popname].tid = setInterval(scrollad, 25);
	}
}
// addEvent(window, 'load', nonpop_load);
// addEvent(window, 'resize', nonpop_resize);
// addEvent(window, 'scroll', nonpop_scroll);
$(document).ready(nonpop_load);
$(document).scroll(nonpop_scroll);
$(document).resize(nonpop_resize);

