/**
 * @author mt
 */

website = {};

// Global setup
website.importfile = "/js/website/website.import.js";
website.loaded = false;
website.instanciated = false;
website.imported = false;

website.init = function()
{
	  $(document).pngFix();
		
	  Cufon.now();
    Cufon.set('fontFamily', 'Lithos Pro');
    Cufon.replace("h1 .english");
		
		Cufon.set('fontFamily', 'MS Mincho');
    Cufon.replace("h1 .japanese, #enter .japanese");
		
		// Auto-instanciate
		if(!website.instanciated) website.autoinstanciate();
    
    $.ajaxSetup({
      dataType:"xml"
    });
	  
		website.loaded = true;
		
};$(document).ready(website.init);

website.autoimport = function()
{
	$.getScript(website.importfile, function(a,b){
		
		website.imported = website.file_import.length > 0 ? false : true;
		
		$.each(website.file_import, function(i, e){
	    $.getScript(e, function(){
				if (i == website.file_import.length - 1)
		    {
		      website.imported = true;
		    }
			});
	  });
	});
};website.autoimport(); // Start file import as soon as this file is loaded

website.autoinstanciate = function()
{
  if (website.imported) {
  	count = 0;
  	$.each(website, function(name, data){
  		
			if (typeof(data.init) == "function") {
  			if (typeof(data.runOn) == "string") 
  				$(data.runOn).each(data.init);
  			else 
  				if (typeof(data.runIf) == "string") 
  					if (eval(data.runIf)) 
  						data.init();
  		}
			
  		if (count == website.length)
			{
				website.instanciated = true;
			}
  	});
  }
  else setTimeout("website.autoinstanciate()",100);
};

