var isReverse = true;

var hypcounter;

//localStorage.hypclickcounter = 0;


$(document).ready(function() {
	$("#vserv_advt_slide, #vserv_advt_slide_popup").click(function(event) {
		localStorage.hypclickcounter = 0;
	});
});


$(document).ready(function() {
	var height = parseInt(($(document).innerHeight() * 2)/3);

	ad_height = parseInt($(document).innerHeight() * 0.6);
	
	$("#vserv_advt_slide li").each(function(){
		$(this).find("img").css("width","100%");
		$(this).find("img").css("height",height-50);
	});

	$("#vserv_advt_slide_popup li").each(function(){
		$(this).find("img").css("width","100%");
		$(this).find("img").css("height",height-50);
	});
	
	$("#clickbank_advt_popup li").each(function(){
		$(this).find("img").css("width","100%");
		$(this).find("img").css("height",ad_height);
	});
});

var advttimer = setInterval(function(){
	$.mobile.changePage('#popup_advt_page', {
		transition : 'pop',
			     role       : 'dialog'
	});
}, 180000);


$(document).on("pageshow", "#home" ,function() {
	$("#spiral").destroy();
});

$(document).on("pageshow", "#spiralpage" ,function() {
	$("#spiral").destroy();
	$('#spiral').sprite({fps: 30, no_of_frames: 14}).activeOnClick().active();
});


$(document).ready(function() {
	$("#button_0").click(function() {
		hypcounter = Number(localStorage.hypclickcounter);

		if(isNaN(hypcounter))
			hypcounter = 0;

		if(hypcounter >= 5)
		{
			alert("Time to buy me a beer. \nKindly click and visit offers. \nYou will get 5 chances.\n(If advt. not shown...plz check your internet connection and reload apps.)");
			$.mobile.changePage("#advt_page", { transition: "slide", changeHash: true});
		}
		else
		{
			if(localStorage.hypclickcounter)
				localStorage.hypclickcounter = Number(localStorage.hypclickcounter) + 1;
			else
				localStorage.hypclickcounter = 1;

			$.mobile.changePage("#spiralpage", { transition: "slide", changeHash: true});

			$('#spiral').sprite({fps: 30, no_of_frames: 14}).activeOnClick().active();
		}
    });
});



$(document).ready(function() {
                $("#reverse").click(function() {
                    if(isReverse == false)
                    {
                        isReverse = true;
                        document.getElementById('spiral').style.background = "transparent url(img/fullspiralreverse.jpg) 0 100% no-repeat";
                        document.getElementById('spiral').style.width = "240px";
                        document.getElementById('spiral').style.height = "240px";
                    }
                    else
                    {
                        isReverse = false;
                        document.getElementById('spiral').style.background = "transparent url(img/fullspiral.jpg) 0 100% no-repeat";
                        document.getElementById('spiral').style.width = "240px";
                        document.getElementById('spiral').style.height = "240px";
                    }
		});
});


$(window).load(function(){
	$("#vserv_advt_slide").responsiveSlides({
		"auto": true,
		"pause": false,
		"pauseControls": false,
		"namespace": "rslides",
		"nav": true,
		"maxwidth": 300,
		"maxheight": 300,
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button
	});	
});

$(window).load(function(){
	$("#vserv_advt_slide_popup").responsiveSlides({
		"auto": true,
		"pause": false,
		"pauseControls": false,
		"namespace": "rslides",
		"nav": true,
		"maxwidth": 250,
		"maxheight": 250,
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button
	});	
});

$(window).load(function(){
	$("#clickbank_advt_popup").responsiveSlides({
		"auto": true,
		"pause": false,
		"pauseControls": false,
		"namespace": "rslides",
		"nav": true,
		"maxwidth": 250,
		"maxheight": 250,
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button
	});	
});

$(window).load(function(){
	$("#clickbank_advt1").responsiveSlides({
		"auto": true,
		"pause": false,
		"pauseControls": false,
		"namespace": "rslides",
		"nav": true,
		"maxwidth": 300,
		"maxheight": 300,
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button
		
	});
});

$(window).load(function(){
	$("#vserv_advt_slide_extra").responsiveSlides({
		"auto": true,
		"pause": false,
		"pauseControls": false,
		"namespace": "rslides",
		"nav": true,
		"maxwidth": 300,
		"maxheight": 300,
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button
	});	
});

