var domain_name = "";
var username = "";
var email = "";

var page = "";
var last_page = "";
var data_old = "";

String.prototype.startsWith = function(str){
	return (this.match("^"+str)==str)
}
/*
setInterval(function()
   {
 	 $.get("php/searches_served.php", function(data){
  		if (data != data_old) {
			if (data_old == '') {
				$('.txt_count').html(data);
			} else {
				$('.n_count').hide();

				$('.n_count').fadeIn('slow',function(){
					$('.txt_count').html(data);
				})
			}
			
			data_old = data;
		}
	});
	
   }, 3000);
*/
back = function() {
	if (last_page=="") {
		last_page="livesearch";
	}
	
	go_to(last_page);
}

get_url = function(){
	_url = parseUri(window.location.href);
	_url = 'http://' + _url.host;
	
	return _url;
}

go_to = function(name){

	filepath = get_url() + '/html/' + name.replace('#','') + '.html';
	$(".sikbox_results").hide();
	$("#loading_screen").show();
	
	$("#screen").fadeOut();
	last_page = page;
	
	if (parseUri(window.location.href).path != '') {
		if (name.startsWith('#')) {
			hash = name;
		}
		window.location.href = get_url() + hash;
	}
	
	$.get(filepath,function(data){ 
		$("#loading_screen").hide();
		
		html = "<div id='screen'>" + data + "</div>";
		$("#screen").remove(); ''
		$("#box_top .bg_bottom").before(html);

		if (name.startsWith('#')) {
			window.location.hash=name;
		}		
	});
}

$(function() { 
	
	$('#topsearch li a.link_stats').click(function(){
		go_to('#statistics');
	})

	$('.buy_cofee').click(function(){
		$('#paypal').submit();
	})
	

	$('#home_link').click(function(){
		window.location.hash='';
		location.replace('/');
	})

	
	$('#link_help').click(function(){
		go_to('#help');
	});

	$('#link_about').click(function(){
		go_to('#about');
	})
	
	$('#link_buzz').click(function(){
		go_to('#buzz');
	})
		

});

function show_page(){
	pathname = window.location.hash;
	querystring = window.location.search;

	if (pathname == "" && querystring != "") {
		pathname = querystring;
	}

	switch(pathname)
	{
		case "#registration":
			go_to('#registration');
			break;    
		case "#help":
			go_to('#help');
			break;
		case "#statistics":
			go_to('#statistics');
			break;
		case "#customization":
			go_to('#customization');
			break;
		case "#skin":
			go_to('#skin');
			break;
		case "#about":
			go_to('#about');
			break;
		case "#buzz":
			go_to('#buzz');
			break;
			
	}
}	