(function() {
    var startingTime = new Date().getTime();
	var scpopup = false;
	if (!document.getElementById('sccss'))
	{
		var link  = document.createElement('link');
		link.id   = 'sccss';
		link.rel  = 'stylesheet';
		link.type = 'text/css';
		link.href = '//videocontest.io/a/css/popup.css';
		link.media = 'all';
		document.getElementsByTagName("head")[0].appendChild(link);
	}
	if (!document.getElementById('scjquery'))
	{
		var script = document.createElement("SCRIPT");
		script.src = '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
		script.type = 'text/javascript';
		script.id = 'scjquery';
		document.getElementsByTagName("head")[0].appendChild(script);
	}
		if(!document.getElementById('sm_main_div'))
	{
		var scdiv = document.createElement("div");
		scdiv.id = 'sm_main_div_';
		document.getElementsByTagName("body")[0].appendChild(scdiv);
	}
	
    var checkReady = function(callback) {
        if (window.jQuery) {
            callback(jQuery);
        }
        else {
            window.setTimeout(function() { checkReady(callback); }, 20);
        }
    };

    checkReady(function($) {
        $(function() 
		{
			var sm_cid = "";
			var formobile='';
			if(!sm_type)var sm_type="";
				for (var sckey in sctype)
				{
					sm_type += sckey + ",";
				}
			
			var item = 0;
			if(document.getElementById('sm_root_' + sm_cid))
				var sm_maindiv = document.getElementById('sm_root_' + sm_cid);
			if(sm_maindiv.hasAttribute("sm-height"))
				var sm_height = sm_maindiv.getAttribute('sm-height');
			if(sm_maindiv.hasAttribute("sm-width"))
				var sm_width = sm_maindiv.getAttribute('sm-width');
			if(sm_maindiv.hasAttribute("sm-timedelay"))
				var sm_timedelay = sm_maindiv.getAttribute('sm-timedelay');
			
			if(sm_maindiv.hasAttribute("sm-scrollTo"))
				var sm_scrollheight = sm_maindiv.getAttribute('sm-scrollTo');
			if(sm_maindiv.hasAttribute("sm-theme"))	
				var sm_theme = sm_maindiv.getAttribute('sm-theme');
			if(sm_maindiv.hasAttribute("sm-animation"))
				var sm_animation =sm_maindiv.getAttribute('sm-animation');
			
			
				var sm_cookie = 600;
								

			var sm_sid = 0;
			
			var sm_margin_lft=parseInt(sm_width.split("px",1))/2;
			var sm_margin_top=parseInt(sm_height.split("px",1))/2;
			
			
			var valid_url = "'"+window.location+"'";
			var Kvisibility;
			var bgset;
//			sm_template =parseInt(sm_template);
//			var mclass="mobiframe_" + sm_template;
//			if(sm_template > 600)
//			{
//				Kvisibility = "visibility:hidden;";
//				bgset = "background:none;";
//			}else
//			{
			   Kvisibility  = "visibility:visible;";
			   bgset = "";
//			}


		if(!document.getElementById('sm_csize_'+sm_cid))
		{
                     var getUrl=encodeURIComponent(window.location.href);
			scdiv.innerHTML = '<div class="sm_container" style="'+bgset+'" id="sm_csize_'+sm_cid+'" ><div id="sm_inner_container_'+sm_cid+'" class="pp_div '+sm_animation+' animated" style="display: block;width:'+sm_width+';height:'+sm_height+';margin-left:-'+sm_margin_lft+'px;margin-top:-'+sm_margin_top+'px;"><a class="cls_pp" style="'+Kvisibility+'" href="javascript:void(0);" onClick="setCookie(\'' + sm_type+sm_cid+'\','+sm_cid+','+sm_cookie+');"><img class="sm_close_'+sm_cid+'" src="//leadmonster.io/a/x.png" alt=""/></a><iframe class="container1"  id="container1_'+sm_cid+'" style="width:'+sm_width+';height:'+sm_height+';" src="" frameborder="0" allowfullscreen></iframe></div></div>';
			document.getElementById("container1_"+sm_cid).src = '//videocontest.io/frontend/index.php?cid='+sm_cid+'&getotherUrl='+getUrl;
		}
			var valuetype = readCookie('cookie_valtype'+sm_cid);
			var uagent = navigator.userAgent.toLowerCase();
			if (uagent.match(/(iphone|ipod|ipad|android|blackberry|webos|windows phone|zunewp7|iemobile|bada|nokia|windows mobile|opera mini|opera mobile|kindle|windows phone|PSP|avantGo|atomic web browser|blazer|chrome mobile|dolphin|dolfin|doris|go browser|jasmine|microb|mobile firefox|mobile safari|mobile silk|motorola internet browser|netfront|ninesky|nokia web browser|obigo|openwave mobile browser|palm pre web browser|polaris|ps vita browser|puffin|qqbrowser|semc browser|skyfire|tear|teashark|uc browser|uzard web|wosbrowser|yandex.browser mobile)/)) {
				if(document.getElementById('formobile')){
					formobile = document.getElementById('formobile').value;
				}
				if(formobile != ''){
				
				   sm_type=sm_cid+'_'+formobile;
				
				}
			}	
	
			var chktype=sm_type+sm_cid;
			
			$(document).ready(function()
			{
				if(!valid_url.match('scpop'))
				{
					if(sm_type.match(sm_cid + '_onload'))
					{	
						setTimeout(function()
						{
						    if(valuetype!=chktype){
						     	sm_showmypopup();
							}	
						}, sm_timedelay);
					}					
				}else
				{
					$('.cls_pp').click();
				}
				
				if(sm_type.match(sm_cid + '_onclick'))
				{
					$(".sm_clickme_"+sm_cid).click(function()
					{
						if(valuetype!=chktype)
						{
							sm_showmypopup();														
						}					
					});
				}
                                if(sm_type.match(sm_cid + '_exitpopup'))
					{	
						var triggered = false;
						window.onbeforeunload = function () {

						   if(!triggered){
							   triggered=true;
							   if(document.getElementById('redir_msg')){
							   
							      redir_msg = document.getElementById('redir_msg').value;
							   
							   }else{
							   							   
							   redir_msg = 'Are you sure wanna to leave this page?';
							   }
								setTimeout(function()
								{
									if(valuetype!=chktype){                                                                          
										if(document.getElementById('sm_fixedframe'))
										{
											var sciframe = document.getElementById('sm_fixedframe');
											sciframe.src = '';
											document.getElementsByTagName("body")[0].style.overflow="hidden";
											document.getElementById('sm_fixedframe').style.display = "block";
										}
																				sm_showmypopup();
																			}
								}, sm_timedelay);
								
								
							   return redir_msg;
						   }
						};
						
					}
					
					if(sm_type.match(sm_cid + '_intent'))
					{	var triggered = false;
						$(document).mousemove(function(e)
						{	
							if(e.clientY > 10){triggered = true;}
							if((e.clientY < 10) && triggered == true)
							{	
							    if (!document.getElementById('exitintent_lm'))
								{
										var link  = document.createElement('INPUT');
										link.id   = 'exitintent_lm';
										link.type = 'hidden';
										link.value = '0';
										document.getElementsByTagName("body")[0].appendChild(link);
								}
								if(document.getElementById('exitintent_lm')){
								
										var exitintent_lm = document.getElementById('exitintent_lm').value;
								
								}
								
								if(valuetype!=chktype && exitintent_lm == 0){
								    
						         	sm_showmypopup();
									if(document.getElementById('exitintent_lm')){
								
										document.getElementById('exitintent_lm').value = 1;
								
									}
							    }
								triggered = false;
							}
						});
						
					}
					
				$(".sm_close_"+sm_cid).click(function()
				{
					$("#sm_csize_"+sm_cid).hide( );
					//window.location.reload();
					scpopup = false;
				});
				$("#sm_csize_"+sm_cid).click(function()
				{
					//$("#sm_csize_"+sm_cid).hide();
					
				});
			});
			function sm_showmypopup()
			{
				$(".sm_container").hide();
				document.getElementById('sm_csize_'+sm_cid).style.display="block";
				if(scpopup == false)
				{
					scpopup = true;	
				}
			}
		});
		
    });
})();
function setCookie(value,id,cookie)
{
	var key="cookie_valtype"+id;
	var expires = new Date();
	expires.setTime(expires.getTime() + (cookie * 1000));
	document.cookie = key + '=' + value +';path=/'+ ';expires=' + expires.toUTCString();
	console.log = 'document.cookie = ' + key + '=' + value;
}
function readCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
