function init() {
$(document.getElementById("loadergif")).fadeOut(500);
$(document.getElementById("loader")).fadeOut(1000);
$("#logo").css('left', document.body.offsetWidth/2-350+'px');
$("#logo_stripe").css('left', document.body.offsetWidth/2-350+'px');
$("#main").css('margin-left', document.body.offsetWidth/2-1650+'px');
$('#free').animate({rotate: '-=90deg'}, 0);
$('#buy').animate({rotate: '+=180deg'}, 0);
$('#search').animate({rotate: '+=90deg'}, 0);
$("#left").css('width', document.body.offsetWidth/2-352+'px');
$("#right").css('width', document.body.offsetWidth/2-352+'px');
$('#load_imgs').load('load_imgs.php');
$("#commentForm").validate();
// KWICKS
$('.free').kwicks({
						min : 54,
						spacing : 10,
						isVertical : true
					});
$('.buy').kwicks({
						min : 54,
						spacing : 10,
						isVertical : true
					});
$('.home').kwicks({
						min : 54,
						spacing : 10,
						isVertical : true
					});

}
function getLocationHash()
    {
		if (window.location.hash=='#freefonts') {go_90()}
		if (window.location.hash=='#buyfonts') {go_180()}
		if (window.location.hash=='#searchfonts') {go_270(),searchfonts()}
		if (window.location.hash=='') {}
		else {last=window.location.hash.lastIndexOf('#');
str=window.location.hash.substr(0,last);
num=window.location.hash.substr(last+1,window.location.hash.length);
//alert(num);
ANIMATION(num);
if (window.location.hash=='#freefonts_'+num) {go_90()}
if (window.location.hash=='#buyfonts_'+num) {go_180()}
}
}


function go_90(){
$('#main').animate({rotate: '+=90deg'}, 1000);
}
function go_180(){
$('#main').animate({rotate: '+=180deg'}, 1000);
}
function go_270(){
$('#main').animate({rotate: '-=90deg'}, 1000);
}
function homefonts(){
window.location.href = "#homefonts";
}
function freefonts(){
window.location.href = "#freefonts";
}
function buyfonts(){
window.location.href = "#buyfonts";
}
function searchfonts(){
window.location.href = "#searchfonts";
$('#motor').load('search.php');
}

function ANIMATION(arg)
{
last=arg.lastIndexOf('_');
str=arg.substr(0,last);
num=arg.substr(last+1,arg.length);
	switch(str)
	{
		case 'freefonts':
		anime_free(num);
		break;
		case 'buyfonts':
		anime_buy(num);
		break;
		case 'results':
		anime_results(num);
		break;
		case 'hits':
		anime_hits(num);
		break;
		default:
//		alert("ANIMATION - ID "+arg+" not valid");
	}
}
function anime_free(i){
$(".free").fadeOut(500);
$("#free_"+i).fadeIn(1000);
$(".free_index").removeClass('open');
$("#free_index_"+i).addClass('open');
$("#free_index2_"+i).addClass('open');
window.location.href = "#freefonts_"+i;
}
function anime_buy(i){
$(".buy").fadeOut(500);
$("#buy_"+i).fadeIn(1000);
$(".buy_index").removeClass('open');
$("#buy_index_"+i).addClass('open');
$("#buy_index2_"+i).addClass('open');
window.location.href = "#buyfonts_"+i;
}
function anime_results(i){
$(".results").fadeOut(500);
$("#results_"+i).fadeIn(1000);
}
function form_over(){
$('#form').load('form.php');
$("#form").animate({ height: "210px",
  }, 400 );
}
function form_out(){
$("#form").animate({ height: "0px",
  }, 300 );
}

// hits
function ajaxFunction(i)
{
  var xmlhttp;
  if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  } else return;

  xmlhttp.open('GET','hits.php?id='+i,true);
  xmlhttp.send(null);
}

function anime_hits(i)
{
	ajaxFunction(i);
}
