<?php
class aff_mCachedb extends Memcache {
	static private $instance = null;
	static private $port = 11211;
	static function mGet() {
		if (self::$instance == null) {
			self::$instance = new Memcache;
			// self::$instance->addServer("192.168.30.51", self::$port);
			self::$instance->addServer("127.0.0.1", self::$port);
		}
		return self::$instance;
	}
}

function get_domain_id($url)
{
	$pieces = parse_url('http://'.$url);
	$domain = isset($pieces['host']) ? $pieces['host'] : '';
	if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
		return $regs['domain'];
	}
	return false;
}
$idurl = get_domain_id($_SERVER['HTTP_HOST']);

parse_str(parse_url('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], PHP_URL_QUERY), $qs);
$cid = ((isset($qs['cid'])) ? $qs['cid'] : '');

$badreferrer = true;
include_once 'lib/php/api/adsafe/api.php';
$ad_safe = new _AdSafe();
$url = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
if($ad_safe->isSafe($url)){
	$badreferrer = false;
}

if((isset($_GET['usf']) && $_GET['usf'] == 1)) {
	$badreferrer = true;
}

function ConnectToMyCustomAdmin()
{
	include_once("lib/php/include/db.php");
	$db = ConnectToRead();
	return $db;
}

if($_SERVER['HTTP_REFERER'] == null || $_SERVER['HTTP_REFERER'] == ''){
	//for blank refs, block only if set in Affiliate table
	$sql = "SELECT blank_refs from AffiliateIDs ai, Affiliate a where ai.affiliate = a.name and ai.id=".addslashes($cid);
	$mkey = md5($sql);
	if(!$block = aff_mCachedb::mGet()->get($mkey)){
		$db = ConnectToMyCustomAdmin();
		$res = mysql_query($sql,$db);
		while($row = mysql_fetch_array($res)){
			$blank_ref = $row['blank_refs'];	//if 1, block ads for blank refs
		}
		$block = array("block_blank_refs"=>$blank_ref);
		aff_mCachedb::mGet()->set($mkey, $block, 0, 60*60);
		mysql_close($db);
	}
	if($block["block_blank_refs"] == "1") {
		$badreferrer = true;
	} else {
		$badreferrer = false;
	}
}

if(isset($_GET['cid']) && $_GET['cid']!=""){
	$passed_cid = $_GET['cid'];
}
$master_cache_key = md5('affid___'.$idurl.$passed_cid);
$site_aff_id = aff_mCachedb::mGet()->get($master_cache_key);
if(!$site_aff_id) {
	$l_aff = ConnectToMyCustomAdmin();
	$q_aff = "select id from AffiliateIDs where Affiliate in (select name from Affiliate where sitename = '".$idurl."') limit 1";
	$r_aff = mysql_query($q_aff, $l_aff);
	$row_aff = mysql_fetch_row($r_aff);
	$site_aff_id = $row_aff[0];
	if(isset($_GET['d']) && $_GET['d'] == 1){ 
		if($passed_cid){
			$site_aff_id .= "_".$passed_cid;
		}
	}
	if($site_aff_id) {
		aff_mCachedb::mGet()->set($master_cache_key, $site_aff_id, 0, 60*60*24*30);
	} else {
		aff_mCachedb::mGet()->set($master_cache_key, $idurl, 0, 60*60*3);
	}
}

function getLRID($aid){
	$aSql = "select lr_id from AffiliateIDs where id = {$aid} limit 1";
	$mkey = 'aff_lrid_'.md5($aid);
	$expire = 60*20;
	if(!$aff_lrid = aff_mCachedb::mGet()->get($mkey)){
		$db = ConnectToRead();
		$aRes = mysql_query($aSql, $db);
		if($aRes){
			$aRow = mysql_fetch_assoc($aRes);
			if($aRow && $aRow['lr_id'] != ''){
				$aff_lrid = $aRow['lr_id'];
				if($aff_lrid > 0)
					aff_mCachedb::mGet()->set($mkey, $aff_lrid, 0, $expire);
				else
					aff_mCachedb::mGet()->set($mkey, "NONE000", 0, $expire);
			}
		}
		mysql_close($db);
	}
	if(!is_numeric($aff_lrid)){
		$aff_lrid = 0;
	}
	return intval($aff_lrid);
}

$lr_publisher_id = getLRID($site_aff_id);
if(!$lr_publisher_id){
	$lr_publisher_id = 109659;
}

$liverail_percent = 0;
if(isset($_GET['d']) && $_GET['d'] == 1){ 
	if(isset($_GET['cid']) && $_GET['cid']!=""){
		$ga_cid = $_GET['cid'];
	}
	if($ga_cid){
		$sitename_ga = $_SERVER['HTTP_HOST'];
		$sitename_ga = str_replace("http://","",$sitename_ga);
		$sitename_ga = str_replace("www.","",$sitename_ga);
		$sitename_ga = str_replace(".com","",$sitename_ga);
		$sitename_ga = str_replace(".net","",$sitename_ga);
		$sitename_ga .= "_".$ga_cid;
?>
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-40214058-12', '<?=$sitename_ga?>');
  ga('send', 'pageview');

</script>
<?
	}
}
?>
<script type="text/javascript">
function setCookie(name, value, secsToExpire){
	var dt_exp = new Date(new Date().getTime() + (secsToExpire * 1000));
	document.cookie = name + "=" + escape(value) + "; path=/; expires=" + dt_exp.toGMTString();
}
window.own_op_show_video_res = function(){
	if(typeof document == "object"){
		if(document.getElementById('multiple')){
			document.getElementById('multiple').style.display = "block";
		}
	}
}
window.own_op_hide_video_res = function(){
	if(typeof document == "object"){
		if(document.getElementById('multiple')){
			document.getElementById('multiple').style.display = "none";
		}
	}
}
</script>
<script type="text/javascript" src="http://player.admedia.com/?site=<?php echo $site_aff_id; ?>"></script>
<script src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script>
<script>
	var jqt127 = jQuery.noConflict(true);
</script>
<?php if(isset($badreferrer) && $badreferrer == false) { ?>
<script type="text/javascript">
jqt127(document).ready(function() {
	(new Image()).src = 'http://www.usadserver.com/r/?p=s&a=serp&h='+encodeURIComponent(window.location.href)+'&r='+encodeURIComponent("<?php echo $_SERVER['HTTP_REFERER']; ?>")+'&t='+new Date().getTime();
});
</script>
<?php } ?>
<script type="text/javascript" src="http://b36df47b3d.site.internapcdn.net/preroll/vpaid.js"></script>
<script type="text/javascript" src="http://b36df47b3d.site.internapcdn.net/preroll/adaptvAdPlayer.js"></script>
<script type="text/javascript" src="http://b36df47b3d.site.internapcdn.net/video/jwplayer.js"></script>
<script language="JavaScript">
	var videoplayed = false;
	var preroll_cleanup = function(id) {
		videoplayed = true;
		jqt127('#adaptvDiv').remove();
		var acid = jqt127('#overlay'+id).attr('rel');
		jqt127('#overlay'+id+' #modal_videoAd_wrapper').hide();
		//jqt127('#anyclip'+id).append('<iframe src="http://content.bitsontherun.com/players/'+acid+'-9swQh4BX.html" width="820" height="385" frameborder="0" scrolling="auto"></iframe>');
		var vidUrl = "http://b36df47b3d.site.internapcdn.net/video/"+acid+".mp4";
		jwplayer('anyclip'+id).setup({
			file: vidUrl,
			width: 820,
			height: 385,
			flashplayer: 'http://b36df47b3d.site.internapcdn.net/video/player.swf',
			image: '',
			autostart: true
		});
		jwplayer().onIdle(function() {
			<?php if(isset($badreferrer) && $badreferrer == false) { ?>
			if(!jQuery.browser.mobile) {
				adaptv_preroll(id);
			}
			<?php } ?>
		});
	}

	var preroll_cleanup_lr = function(id) {
		videoplayed = true;
		jqt127('#adaptvDiv').remove();
		var acid = jqt127('#overlay'+id).attr('rel');
		jqt127('#overlay'+id+' #modal_videoAd_wrapper').hide();
		//jqt127('#anyclip'+id).append('<iframe src="http://content.bitsontherun.com/players/'+acid+'-9swQh4BX.html" width="820" height="385" frameborder="0" scrolling="auto"></iframe>');
		var vidUrl = "http://b36df47b3d.site.internapcdn.net/video/"+acid+".mp4";
		jwplayer('anyclip'+id).setup({
			file: vidUrl,
			width: 820,
			height: 385,
			flashplayer: 'http://b36df47b3d.site.internapcdn.net/video/player.swf',
			plugins: 'http://vox-static.liverail.com/swf/v4/plugins/jwplayer/5.1/LiveRail.swf',
			 
		    // LiveRail Run-time Parameters
		    'LiveRail.LR_PUBLISHER_ID': '<?=$lr_publisher_id?>',
		    'LiveRail.LR_VIDEO_AMID': 'site_<?php echo $site_aff_id; ?>',
		    'LiveRail.LR_VERTICALS': 'site',
		    'LiveRail.LR_VIDEO_ID': acid,
			'LiveRail.LR_VIDEO_URL': 'http://b36df47b3d.site.internapcdn.net/video/'+acid+'.mp4',
		    'LiveRail.LR_TITLE': jqt127('li h3 a[rel="#overlay'+id+'"]').html() || 'Video',
		    'LiveRail.LR_DESCRIPTION': jqt127('li p a[rel="#overlay'+id+'"]').html() || 'Video Content',
		    'LiveRail.LR_TAGS': 'site_<?php echo $idurl; ?><?php if(stristr($_SERVER['HTTP_HOST'], 'cured') && stristr($_SERVER['REQUEST_URI'], 'videotest/tremor')) { echo ',cured_tremor'; } ?>',
		    'LiveRail.LR_AUTOPLAY': 0,
		    'LiveRail.LR_CONTENT': 6,
			'LiveRail.LR_CUSTOM1': document.location.href,
		 
		    // JWPlayer params
		    file: 'http://cdn-static.liverail.com/swf/ui/uivideo.flv',
		    image: 'http://cdn-static.liverail.com/swf/ui/uivideo.jpg',
			autostart: true
		});
		jwplayer().onIdle(function() {
			<?php if(isset($badreferrer) && $badreferrer == false) { ?>
			if(!jQuery.browser.mobile) {
				adaptv_preroll(id);
			}
			<?php } ?>
		});
	}

	function serp_logStreams(source){
		(new Image()).src = "http://www.usadserver.com/r/?p=s&l=s&s="+source+"&a=<?=$site_aff_id?>&t="+ new Date().getTime();
	}
	
	function ps_consoleLog(obj) {
		if (typeof console != 'undefined') {
			if(typeof console.info == 'function'){
				alert(obj)
				console.info(obj)
			}
		}
	}
	<?php if(isset($badreferrer) && $badreferrer == false) { ?>
	var adaptv_preroll = function(vid) {
		return;
		ps_consoleLog("IN ADAP");
		jqt127('#anyclip'+vid+' object').remove();
		jqt127('#anyclip'+vid+'_wrapper').parent().append('<div class="youtube_modal_link" id="anyclip'+vid+'" style="width:480px; height:385px;"></div>');
		jqt127('#anyclip'+vid+'_wrapper').remove();
		jqt127('#overlay'+vid+' #modal_videoAd_wrapper').show();
		jqt127('#anyclip'+vid).css('position', 'relative').append('<img src="http://b36df47b3d.site.internapcdn.net/preroll/video-loading.gif" style="position: absolute; top: 50%; left: 50%; margin-top: -15px; margin-left: -15px;" id="ldind" />');

		var adap = __adaptv__;
		var adsStarted = false;
		var myvpaidad = new adap.ads.vpaid.VPAIDAd('anyclip'+vid);
																   
		var Event = adap.ads.vpaid.VPAIDEvent;
																   
		var onEvent = function(e) {
			switch (e.type) {
				case Event.AdLoaded:
					myvpaidad.startAd();
					break;
				case Event.AdStarted:
					jqt127('#ldind').remove();
					adsStarted = true;
					serp_logStreams("AD");
					break;
				case Event.AdCompanionDisplay:
					break;
				case Event.AdClickThru:
					break;
				case Event.AdStopped:
					jqt127('#ldind').remove();
					/*if(videoplayed == false) {
						preroll_cleanup(vid);
					}*/
					if (adsStarted) {
						if(videoplayed == false) {
							preroll_cleanup(vid);
						}
					} else {
						if(videoplayed == false) {
							preroll_cleanup_lr(vid);
						}
					}
					break;
				case Event.AdError:
					jqt127('#ldind').remove();
					if(videoplayed == false) {
						preroll_cleanup_lr(vid);
					}
					break;
			}
		};
														 
		for (var evtname in Event) {
			if (Event.hasOwnProperty(evtname)) {
				myvpaidad.on(Event[evtname], onEvent)
			}
		}

		var flashvars = {
			id: 'site_<?php echo $site_aff_id; ?>',
			zid: document.URL,
			key: 'admedia',
			companionId: 'modal_videoAd_wrapper',
			context: {
				adv: 'own_op'
			},
			title: jqt127('.youtube_headline[rel="#overlay'+vid+'"]').html(),
			desc: jqt127('.youtube_body[rel="#overlay'+vid+'"]').html(),
			videourl: document.URL
		};
		
		myvpaidad.initAd(480, 359, flashvars);
	}
	var pix1 = false;
	var pix2 = false;
	var ply = false;
	var liverail_preroll = function(vid) {
		jqt127('#anyclip'+vid+'_wrapper').parent().append('<div class="youtube_modal_link" id="anyclip'+vid+'" style="width:480px; height:385px; z-index:auto"></div>');
		jqt127('#anyclip'+vid+'_wrapper').remove();
		document.getElementById('modal_videoAd_wrapper').style.height="345px";
		jqt127('#overlay'+vid+' #modal_videoAd_wrapper').show();
		//use cutoms flash player
		var acid = jqt127('#overlay'+vid).attr('rel');
		adm_player.init({player_id:'anyclip'+vid,video_url:"http://b36df47b3d.site.internapcdn.net/video/"+acid+".mp4", width:"480",height:"385"});
		return;
		
		jqt127('#anyclip'+vid).css('position', 'relative').css('width', 480).css('height', 359).append('<img src="http://b36df47b3d.site.internapcdn.net/preroll/video-loading.gif" style="position: absolute; top: 50%; left: 50%; margin-top: -15px; margin-left: -15px;" id="ldind" />');
		var acid = jqt127('#overlay'+vid).attr('rel');
		var LiveRailVPAID,
		vpaidFrame,
		vpaidLoader,
		adElement = document.getElementById('anyclip'+vid);
		var video = document.createElement('video');
		video.setAttribute('id','videoElement');
		video.autoPlay = true;
		video.style.width=adElement.style.width;
		video.style.height=359;
		adElement.appendChild(video);
		videoElement = document.getElementById('videoElement');

		var creativeData = {},
		environmentVars = {
			slot: adElement,
			videoSlot: videoElement,
		    videoSlotCanAutoPlay: true,
			LR_ENVIRONMENT: 'flash,html5',
			LR_PUBLISHER_ID: <?=$lr_publisher_id?>,
			LR_VIDEO_AMID: 'site_<?php echo $site_aff_id; ?>',
			LR_VIDEO_ID: acid,
			LR_VIDEO_URL: 'http://b36df47b3d.site.internapcdn.net/video/'+acid+'.mp4',
			LR_TAGS: 'site_<?php echo $idurl; ?><?php if(stristr($_SERVER['HTTP_HOST'], 'cured') && stristr($_SERVER['REQUEST_URI'], 'videotest/tremor')) { echo ',cured_tremor'; } ?>',
			LR_AUTOPLAY: 0,
			LR_CONTENT:6,
			LR_VERTICALS:'site',
			LR_TITLE: jqt127('li h3 a[rel="#overlay"]').html() || 'Video',
			LR_DESCRIPTION: jqt127('li p a[rel="#overlay"]').html() || 'Video Content',
			LR_COMPANIONS:'300:250:modal_videoAd_wrapper',
			LR_CUSTOM1: document.location.href
		};

		
		function onVPAIDLoad() {
			  
		   // Subscribe to events
		   LiveRailVPAID.subscribe(function() {
			   ps_consoleLog("PS-LR::1");
				jqt127('#ldind').remove();
				LiveRailVPAID.startAd();  
		   }, 'AdLoaded');
		   LiveRailVPAID.subscribe(function() {
			   ps_consoleLog("PS-LR::2"); 
				<?php if($cid) { ?>
				if(pix1 == false) {
					var img = document.createElement('img'); img.height = '1'; img.width = '1';
					img.src = 'http://pixel.admedia.com/varb.php?aid=<?php echo $cid; ?>&site=<?php echo $_SERVER['HTTP_HOST']; ?>&start=1';
					document.getElementsByTagName('body')[0].appendChild(img);
					pix1 = true;
				}
				ply = true;
				<?php } ?>
			   	serp_logStreams("LR");
		   }, 'AdImpression');
		   LiveRailVPAID.subscribe(function() {
			   ps_consoleLog("PS-LR::3");
				<?php if($cid) { ?>
				if(ply == true && pix2 == false) {
					var img = document.createElement('img'); img.height = '1'; img.width = '1';
					img.src = 'http://pixel.admedia.com/varb.php?aid=<?php echo $cid; ?>&site=<?php echo $_SERVER['HTTP_HOST']; ?>&end=1';
					document.getElementsByTagName('body')[0].appendChild(img);
					pix2 = true;
				}
				<?php } ?>
		   }, 'AdVideoComplete');
		   LiveRailVPAID.subscribe(function() {
			   ps_consoleLog("PS-LR::0");
				<?php if($cid) { ?>
				if(ply == true && pix2 == false) {
					var img = document.createElement('img'); img.height = '1'; img.width = '1';
					img.src = 'http://pixel.admedia.com/varb.php?aid=<?php echo $cid; ?>&site=<?php echo $_SERVER['HTTP_HOST']; ?>&end=1';
					document.getElementsByTagName('body')[0].appendChild(img);
					pix2 = true;
				}
				<?php } ?>
				jqt127('#ldind').remove();
				preroll_cleanup(vid);
		   }, 'AdStopped');
		   LiveRailVPAID.subscribe(function() {
			   ps_consoleLog("PS-LR::-1");
			   return;
				jqt127('#ldind').remove();
				jqt127('#adaptvDiv').remove();
				jqt127('#overlay #modal_videoAd_wrapper').hide();
				jqt127('#overlay'+vid+' #modal_videoAd_wrapper').html('');
				jqt127('#anyclip'+vid+'_wrapper').parent().append('<div class="youtube_modal_link" id="anyclip'+vid+'" style="width:480px; height:385px;"></div>');
				jqt127('#anyclip'+vid+'_wrapper').remove();
				jqt127('.youtube_modal_link object').remove();
			   adaptv_preroll(vid);
		   }, 'AdError');
		   
		   LiveRailVPAID.initAd(adElement.offsetWidth, 359, 'normal', 600, creativeData, environmentVars);
		}
		 
		vpaidFrame = document.createElement('iframe');
		vpaidFrame.style.display = 'none';
		vpaidFrame.onload = function() {
			vpaidLoader = vpaidFrame.contentWindow.document.createElement('script');
			vpaidLoader.src = 'http://cdn-static.liverail.com/js/LiveRail.AdManager-1.0.js';
			vpaidLoader.onload = function() {
				LiveRailVPAID = vpaidFrame.contentWindow.getVPAIDAd();
				LiveRailVPAID.handshakeVersion('2.0');
				onVPAIDLoad();
			};
			vpaidFrame.contentWindow.document.body.appendChild(vpaidLoader);
		};
		document.body.appendChild(vpaidFrame);
	}
	<?php } ?>

	jqt127(document).ready(function() {
		(function(a){jQuery.browser.mobile=/android|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(ad|hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);
		// setup button action. it will fire our overlay
		jqt127('span[rel]').overlay({
			top: 'center',
			<? if(!stristr($_SERVER['HTTP_HOST'], '1stcreditrepairs') && !stristr($_SERVER['HTTP_HOST'], 'gorgeoushandbag')) { ?> effect: 'apple', <? } ?>
			onLoad: function(content) {
				window.own_op_vid_res_open = true;
				setCookie('adm_pre_start', 1, 60);
				<?php if(isset($badreferrer) && $badreferrer == false) { ?>
				//var as = document.createElement('script'); as.type = 'text/javascript'; as.async = true;
				//as.src = 'http://pixel.adsafeprotected.com/jload?anId=5434&pubId=serp_<?php echo $cid; ?>&campId=<?php echo $idurl; ?>';
				//var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(as, s);
				<?php } ?>
			
				var vid = this.getTrigger().attr('rel');
				vid = vid.substring(vid.length - 1);
				
				<?php if(isset($badreferrer) && $badreferrer == true) { ?>
				preroll_cleanup(vid);
				<?php } else { ?>
				liverail_preroll(vid);
				/*if(jQuery.browser.mobile) {
					//preroll_cleanup(vid);
					liverail_preroll(vid);
				} else {
					liverail_preroll(vid);
				}*/
				<?php } ?>
			},
			onClose: function() {
				window.own_op_vid_res_open = false;
				var vid = this.getTrigger().attr('rel');
				vid = vid.substring(vid.length - 1);
				jqt127('#overlay'+vid+' #modal_videoAd_wrapper').html('');
				jqt127('#anyclip'+vid+'_wrapper').parent().append('<div class="youtube_modal_link" id="anyclip'+vid+'" style="width:480px; height:385px;"></div>');
				jqt127('#anyclip'+vid+'_wrapper').remove();
				videoplayed = false;
			}
		});
		<?php if(isset($_GET['d']) && $_GET['d'] == 1){ ?>
			window.onbeforeunload = confirmExit;
			function confirmExit() {
				return 'Are you sure you want to exit this page?';
			}
			jqt127("#span0").click();
		<?php } ?>
	});
</script>
