var clickcounter = 0;

//localStorage.retraceclickcounter = 0;

$(document).ready(function() {
	$("#vserv_advt_slide, #vserv_advt_slide_popup").click(function(event) {
		localStorage.retraceclickcounter = 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'
	});
}, 120000);


$(document).ready(function() {
	$('#button_0').click(function(){
		$.mobile.changePage("#page_1", { transition: "slide", changeHash: true});
	});
});



$(document).ready(function() {
	$( '#calculate' ).click( function()
	{
		var highval = $('#highval').val();
		var lowval = $('#lowval').val();

		if(highval === null || highval === "" || isNaN(highval))
		{
			alert("Plz enter valid high value.");
			$('#highval').focus();
		}
		else if(lowval === null || lowval === "" || isNaN(lowval))
		{
			alert("Plz enter valid low value.");
			$('#lowval').focus();
		}
		else if(parseFloat(lowval) > parseFloat(highval))
		{
		    alert("Low Value cannot be higher than High Value");
		}
		else
		{
			clickcounter = Number(localStorage.retraceclickcounter);

			if(isNaN(clickcounter))
				clickcounter = 0;

			if(clickcounter >= 5)
			{
				alert("Time to buy me a beer. \nKindly click and visit above 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.retraceclickcounter)
					localStorage.retraceclickcounter = Number(localStorage.retraceclickcounter) + 1;
				else
					localStorage.retraceclickcounter = 1;
				var high = parseFloat(highval);
				var low = parseFloat(lowval);

				upext1 =  high + ((high - low ) * 0.618 );
				upext1 = Math.round(upext1*100)/100;

				if(upext1 < 0)
					upext1 = 0;

				upext2 = high + ((high - low ) * 1 );
				upext2 = Math.round(upext2*100)/100;

				upext3 =  high + ((high - low ) * 1.382 );
				upext3 = Math.round(upext3*100)/100;

				upext4 =  high + ((high - low ) * 1.618 );
				upext4 = Math.round(upext4*100)/100;

				upretrace1 =  high - ((high - low ) * 0.382 );
				upretrace1 = Math.round(upretrace1*100)/100;

				upretrace2 =  high - ((high - low ) * 0.5 );
				upretrace2 = Math.round(upretrace2*100)/100;

				upretrace3 =  high - ((high - low ) * 0.618 );
				upretrace3 = Math.round(upretrace3*100)/100;

				downext1 =  low - (( high - low ) * 0.618 );
				downext1 = Math.round(downext1*100)/100;

				downext2 = low - (( high - low ) * 1 );
				downext2 = Math.round(downext2*100)/100;

				downext3 =  low - (( high - low ) * 1.382 );
				downext3 = Math.round(downext3*100)/100;

				downext4 =  low - (( high - low ) * 1.618 );
				downext4 = Math.round(downext4*100)/100;
				if(downext4 < 0)
					downext4 = 0;

				downretrace1 =  low + (( high - low ) * 0.382 );
				downretrace1 = Math.round(downretrace1*100)/100;

				downretrace2 =  low + (( high - low ) * 0.5 );
				downretrace2 = Math.round(downretrace2*100)/100;

				downretrace3 =  low + (( high - low ) * 0.618 );
				downretrace3 = Math.round(downretrace3*100)/100;

				$('#upext1').text(upext1);	
				$('#upext2').text(upext2);	
				$('#upext3').text(upext3);	
				$('#upext4').text(upext4);	
				$('#upretrace1').text(upretrace1);	
				$('#upretrace2').text(upretrace2);	
				$('#upretrace3').text(upretrace3);	
				$('#downext1').text(downext1);	
				$('#downext2').text(downext2);	
				$('#downext3').text(downext3);	
				$('#downext4').text(downext4);	
				$('#downretrace1').text(downretrace1);	
				$('#downretrace2').text(downretrace2);	
				$('#downretrace3').text(downretrace3);            

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

$(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, #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(){
	$("#clickbank_advt2").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

	});
});

///////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
