$(document).ready(function() {
	//FOR MENU
	var url = window.location;
	$("#content ul.navbar-nav a").each(function(){
		if($(this).prop("href")==url){
			$(this).parent().addClass("active");
			$(this).append($('<span class="sr-only">').text('(current)'))
		}
	});

	//$("#marquee ul").liScroll();

	/* MODAL */
	$('#myModal').on('show.bs.modal', function (event) {
	  var button = $(event.relatedTarget) // Button that triggered the modal
	  var recipient = button.data('title') // Extract info from data-* attributes
	  var targetUrl = button.data('url') // Extract info from data-* attributes
	  // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
	  // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
	  var modal = $(this)
	  modal.find('.modal-title').text(recipient)
	  modal.find('.modal-body').append($('<iframe class="iframe">').prop("src", targetUrl));
	}).on('hidden.bs.modal', function (event){
	  var modal = $(this);
	  $(".loading").show();
	  modal.find('.modal-body .iframe').remove();
	});

	/* Promotions banner slidedown */
	$(document).on("click", ".aimg", function(){
		$(this).closest(".abox").find(".acon").slideToggle(300);
	});

	// Request by pragmatic

	// let el = $('.game-items:visible div[action="slot-pm"]').clone();

	// el.find('.box-item').html(`
	// 	${$('#showD').is(':visible') ? '<span><button>Main</button></span>' : ''}
	// 	<picture>
	// 		<source srcset="/common/assets/images/home/pp-request/gates.webp" type="image/webp">
	// 		<img src="/common/assets/images/home/pp-request/gates.jpg" width="200" height="200" alt="Pintu Olympus" loading="lazy">
	// 	</picture>
	// `);
	// el.find('> span').text("Gates of Olympus");
	// $('.game-items a[href*="sg=pm"]').remove();
	// $('.game-items a[href*="sg=lv2"]').after(el);
	//

	let hot = $('.games .home-games:first-child .game-items, .featured .home-games:first-child .game-items');

	hot.find('[action="slot-pm"]').remove();
	hot.prepend(`
		<a class="box" href="/secure/slots-provider" rel="nofollow">
			<div class="box-item">
				${$('#showD').is(':visible') ? '<span><button>Main</button></span>' : ''}
				<picture>
					<source srcset="/common/assets/images/home/pp-request/vs20olympgate.webp" type="image/webp">
					<img src="/common/assets/images/home/pp-request/vs20olympgate.png" width="200" height="200" alt="Gates of Olympus" loading="lazy">
				</picture>
			</div>
			<span>Gates of Olympus</span>
		</a>
		<a class="box" href="/secure/slots-provider" rel="nofollow">
			<div class="box-item">
				${$('#showD').is(':visible') ? '<span><button>Main</button></span>' : ''}
				<picture>
					<source srcset="/common/assets/images/home/pp-request/vswaysmahwblck.webp" type="image/webp">
					<img src="/common/assets/images/home/pp-request/vswaysmahwblck.png" width="200" height="200" alt="Mahjong Wins 3 - Black Scatter" loading="lazy">
				</picture>
			</div>
			<span>Mahjong Wins 3</span>
		</a>
	`);

	// $('.games .home-games:first-child .game-items [gc="vs20olympgate"], .featured .home-games:first-child .game-items [gc="vs20olympgate"]').after(`
	// 	<a class="box" href="/secure/shr/launchGamesVS.html?a=slot-pm&b=vs5aztecgems" rel="nofollow">
	// 		<div class="box-item">
	// 			${$('#showD').is(':visible') ? '<span><button>Main</button></span>' : ''}
	// 			<picture>
	// 				<source srcset="/common/assets/images/home/pp-request/vs5aztecgems.webp" type="image/webp">
	// 				<img src="/common/imgs/pragmatic-classic/vs5aztecgems.png" width="200" height="200" alt="Aztec Gems" loading="lazy">
	// 			</picture>
	// 		</div>
	// 		<span>Aztec Gems</span>
	// 	</a>
	// `);
	let poplar = $('.games .home-games:eq(1) .game-items, .featured .home-games:eq(1) .game-items');

	poplar.find('[action="pm-suit"], [href*="sg=pm"]').remove();
	poplar.prepend(`
		<a class="box" href="/secure/slots-provider" rel="nofollow">
			<div class="box-item">
				${$('#showD').is(':visible') ? '<span><button>Main</button></span>' : ''}
				<picture>
					<source srcset="/common/assets/images/home/pp-request/vs20starlight.webp" type="image/webp">
					<img src="/common/assets/images/home/pp-request/vs20starlight.png" width="200" height="200" alt="Starlight Princess" loading="lazy">
				</picture>
			</div>
			<span style="font-size: 12px;">Starlight Princess</span>
		</a>
		<a class="box" href="/secure/slots-provider" rel="nofollow">
			<div class="box-item">
				${$('#showD').is(':visible') ? '<span><button>Main</button></span>' : ''}
				<picture>
					<source srcset="/common/assets/images/home/pp-request/vs5triple8gold.webp" type="image/webp">
					<img src="/common/assets/images/home/pp-request/vs5triple8gold.png" width="200" height="200" alt="888 Gold" loading="lazy">
				</picture>
			</div>
			<span>888 Gold</span>
		</a>
	`);

	// End request by pragmatic
});

function resetForm(formId){
	$(formId)[0].reset();
	$(formId).find('.form-control').removeClass('valid');
	$(formId).find('.form-control').removeClass('error');
	$(formId).find('label.error').text("").hide();
}

function sessionLogout(){
	alertMsg(messages.sessionLogout);
	delete_cookie('logged');
	setTimeout(function(){
		ajaxCaller('get', logout_link, '', function(){});
	}, 2000);
	//setTimeout( function() {  window.location = logout_link}, 2000 );
}

function iframeLoad(title){
	$(".loading").fadeOut();
	if(typeof title != 'undefined'){
		$('#myModal').find('.modal-title').text(title)
	}
}

function setCookie(cname, cvalue) {
	var d = new Date();
	d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
	var expires = "expires="+d.toUTCString();
	document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
	var name = cname + "=";
	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);
		}
		if (c.indexOf(name) == 0) {
		return c.substring(name.length, c.length);
		}
	}
	return "";
}
