var active = 0;
var notblink = 0;
$(document).ready(function() {
		
		var height = 0;
		if((window.innerWidth / 100 * 75) / 4 * 3 > window.innerHeight){
			height = window.innerHeight - 10;
		} else{
			height = (window.innerWidth / 100 * 75) / 4 * 3  - 10;
		}
		$('.tabs a').click(function(){
			switch_tabs($(this));
		});
	 
		switch_tabs($('.defaulttab'));

		//$("#wrapper").css("width",(window.innerWidth / 100 * 24));
		//$("#runescape-win").css("height",height - 90).css("width",(window.innerWidth / 100 * 74.5));
		//$("#iframe").css("width",(window.innerWidth / 100 * 74.5)).css("height",height - 30);
		//$("#stats-win").css("height",height-90);
		//$(".tab-content").css("height",height-90);
		//$(".heightmeasure").css("height",height-400)
		//$(".heightmeasure-item").css("height",height-400)
		
		$("#look-up-player").click(function(){
			$("#status-balk").html("Loading User...");
			$.ajax({
				url: "ajax.php?action=getUser&user="+$("#player-name").val(),
				success: function(data){
					if(data == 0){
						$("#status-balk").html("User not found");
						$(".heightmeasure tbody").html("");
					} else {
						$(".heightmeasure tbody").html(data);
						$("#status-balk").html("found user ' " + $("#player-name").val() + " '");
					}
				}
			});
			
		});
		$("#look-up-item").click(function(){
			$("#status-balk-item").html("Loading Item...");
			$.ajax({
				url: "ajax.php?action=getItem&naam="+$("#item-name").val(),
				success: function(data){
					if(data == 0){
						$("#status-balk-item").html("Item not found");
						$(".heightmeasure-item tbody").html("");
					} else {
						$(".heightmeasure-item tbody").html(data);
						$("#status-balk-item").html("found item ' " + $("#item-name").val() + " '");
					}
				}
			});
			
		});
		$("#save-notepad").click(function(){
			
			var note = $("#notepad-text").val();
			note = note.replace(/\n/g,"<br />\n");
			
			if(note != ""){
				$("#save-notepad").attr("disabled","disabled");
				$("#note-status").html("Saving note...")
				$.ajax({
					url: "ajax.php?action=savenote&text="+note,
					success: function(data){
						if(data == 1){
							$("#note-status").html("Note saved")
						} else {
							$("#note-status").html("Cannot save cookie");
						}
						setTimeout(function(){
							$("#note-status").html("<span style='font-size:9px;font-weight:normal'>* cookies must be enabled for this to work</span>");
						},2500);
						$("#save-notepad").attr("disabled","");
					}
				});
				
			}
		});
		$("#reset-time").attr("disabled","disabled");
		$("#antifire").click(function(){
			active = 1;
			notblink = 0;
			display(350);
			$("#antifire").attr("disabled","disabled");
			$("#super-antifire").attr("disabled","disabled");
			$("#reset-time").attr("disabled","");
		});
		$("#super-antifire").click(function(){
			active = 1;
			notblink = 0;
			display(290);
			$("#antifire").attr("disabled","disabled");
			$("#super-antifire").attr("disabled","disabled");
			$("#reset-time").attr("disabled","");
		});
		$("#reset-time").click(function(){
			active = 0;
			notblink = 0;
			$("#reset-time").val("Resetting...");
			setTimeout(function(){
				$("#reset-time").attr("disabled","disabled");
				$("#antifire").attr("disabled","");
				$("#super-antifire").attr("disabled","");
				$("#timerinh").html("&nbsp;");
				$("#reset-time").val("Reset");
			},1000);
		});
	});
	Number.prototype.toMinutesAndSeconds = function() {
		var nbr = Math.floor(this / 60);
		return (nbr+":")+(((nbr=(this-(nbr*60)))<10)?"0"+nbr:nbr);
	}
	function display(seconds) {
		if(seconds > 0 && active > 0) {
			$("#timerinh").html((--seconds).toMinutesAndSeconds());
			setTimeout(function(){
				if(seconds > 0 && active > 0){
					display(seconds);
				}
			}, 1000);
		} else {
			$("#antifire").attr("disabled","");
			$("#super-antifire").attr("disabled","");
			if(seconds == 0){
				notblink = 1;
				DoBlink(seconds);
			}
		}
	}
	function DoBlink(seconds){
		$("#timerinh").animate({"color":"red"},300,function(){
				$("#timerinh").animate({"color":"black"},300,function(){
					if(active > 0 && notblink > 0 && seconds < 30){
						DoBlink();
					}
				});
		});
	}
	function switch_tabs(obj)
	{
		$('.tab-content').hide();
		$('.tabs a').removeClass("selected");
		var id = obj.attr("rel");
	 
		$('#'+id).show();
		obj.addClass("selected");
	}
