var sessvar = "";
sessvar2="";
var openclosed="closed";
$(function() {
	
	var currentTime = new Date();
  var hours = currentTime.getHours();
  var minutes = currentTime.getMinutes();
	var seconds = currentTime.getSeconds();
	$("#newstab").css( {'display':'none'} );
	if(hours >= 12) {
		med = "PM";
	}else{
		med = "AM";
	}
	
	if(hours == 0) {
		hours=12;
	}else if(hours > 0 && hours >12) {
		hours-=12;
	}

  if (minutes < 10){
	  minutes = "0" + minutes;
	}

  if (seconds < 10){
	  seconds = "0" + seconds;
	}
	
	$("#popupContact").css( {'border':'4px solid #9BBAFD'} );
	
  var machineTime = hours + ":" + minutes + ":" +seconds+ " "+med;
		dataString = 'machineTime='+machineTime+'&currentMachineTime='+currentTime;
		 $.ajax({
			type:'POST',
			url: 'GeoLocationFiles/myGeoLocation.php',
			data: 'machineTime='+machineTime+'&currentMachineTime='+currentTime,
			success: function(data) {
				//alert(data);
				var mydata = $.trim(data);
				var spldata = mydata.split('##');
				var comparstring = "none";
				var sessvar = spldata[1];
				if(sessvar == 'false') {
					if(spldata[0] == comparstring) {
						// do nothing yet
					}else{
						var tO = setTimeout(function runGeoLocationStuff() {
							$("#popupContact").css( {'border':'4px solid #9BBAFD'} );
							$("#popupContact,#newstab").show("slide", { direction: "up" }, 1000);
							openclosed = 'open';
						},6000);
						
						var setTO = setTimeout(function setTheTimeout() {
							$("#popupContact").hide("slide", { direction: "left" }, 500);
							openclosed = 'closed'; }, 16000);
					}
				}else{
					$("#newstab").css( {'display':'block'} );
				}
			}
		});

	$("#newstab").click(function () {
		popupclicks('tabs');
		if(openclosed == 'open') {
			$("#popupContact").hide("slide", { direction: "left" }, 500);
			openclosed = 'closed';
		}else if(openclosed == 'closed') {
			$("#popupContact").css( {'border':'4px solid #9BBAFD'} );
			$("#popupContact").show("slide", { direction: "left" }, 500);
			openclosed = 'open';			
		}
	});

	$("#link").click(function () {
		popupclicks('link');
	});
	
	$("#toplink").click(function () {
		popupclicks('toplink');
	});

	function popupclicks(passeddata) {
		var dataString = 'clickfield='+passeddata;
		$.ajax({
			
			type: 'POST',
			url: 'GeoLocationFiles/click_count.php',
			data: dataString,
			success: function(data) {
				//alert(data);	
			}
			
		});
	}
	
	$(".closex").click(function() {
		popupclicks('close');
		$("#popupContact").hide("slide", { direction: "left" }, 500);
		openclosed = 'closed';
	});
	
	$("#popupContact, #newstab").css({'display':'none'}); 
	$("#popupContact").corner("bottom");	

});
