// JavaScript Document
 var xmlHttp; 
function Jerky(){

    var flash;
    var lang = "en";
	var initLang;
    var prepared = false;
//  screen size
    
//  initial content size
   
    
  
	
  	this.init = function(useFlash,slang){
    
    	var width = screen.width;
      var height = screen.height;
      var w = 1000;
      var h = 550;
      
      this.initLang = this.lang = slang;
      
      
    
		  if ( height < 768){ h=430;  w=782; }
		  else if ( height < 1024){ h=550; w=1000;}
		  else if ( height < 1200){ h=689; w=1250;}
		  else if ( height < 1536){ w=1562; h=860;}
		  else if ( height < 3000){ w=2000; h=1100;}
		  
		  var content = document.getElementById("contentConteiner");
		  var menu = document.getElementById("htmlMenuConteiner");
		  var menuContent = document.getElementById("htmlMenu");
          //content.style.width = w+"px";
          //menu.style.width = w-15+"px";
          
      
      if (useFlash){
        //  show swf
    		var so = new SWFObject("jerky.swf?update=3", "JERKY", "100%", h, "8", "#FF9900");
    		//so.addParam("scale", "noscale");
    		so.addParam("salign", "c");
    		//so.addVariable("scene","contact");
    		//so.useExpressInstall('expressinstall.swf');
    		//so.setAttribute('xiRedirectUrl', 'http://jerky.at/'); // must be the absolute URL to your site
    		so.addVariable("lang",this.lang);
    		so.write("content");
			
  		} else {
  		    this.showMenu();
  		    this.hideDummy();
  		    menu.style.width = "980px";
  		    document.getElementById("htmlMenu").style.padding = "0px";
  		   
  		    
  		}
  		
  	 if (this.getFlash() == undefined){
  	      this.changeLang(lang);
  		  this.hideDummy();
  		  this.showMenu();
  		  menu.style.width = "980px";
  		  document.getElementById("htmlMenu").style.padding = "0px";
  		  if (useFlash) this.showDownloadFlash();
  		    
      }
  		
  		
    }
    
    
  	this.hideMenu = function(){
  	
      var menu = this.getMenu();
     
      if (menu!=undefined){
        menu.style.visibility = "hidden";
        menu.style.display = "none";
      }
    }
    
    this.showMenu = function(){
      var menu = this.getMenu();
      if (!this.prepared){
		  this.prepared = true;
		  this.swfChangeLang(this.initLang);
	  }
	  else
      if (menu!=undefined){
        menu.style.visibility = "visible";
        menu.style.display = "block";
      }
    }
    this.changeLang = function(inLang){
    
      if (inLang!=undefined){
         this.hideMenu();
         this.lang = inLang;
         //document.getElementById("choosenLang").innerHTML = inLang;
         this.showMenu();
      }
    }
    
    this.showDownloadFlash = function(){
      if (xmlHttp == null) this.createXMLHttpRequest();
      xmlHttp.onreadystatechange = this.processShowDownloadFlash;
      xmlHttp.open("GET", "./data/texts/getFlash.xml", true);
      xmlHttp.send(null);
    }
    this.processShowDownloadFlash = function(){
      
      if (xmlHttp.readyState == 4){
      
        if (xmlHttp.status != 0){
            
          document.getElementById("downloadFlash").innerHTML = xmlHttp.responseText;
        }
      }
    }
    
    this.createXMLHttpRequest = function (){
      if (window.ActiveXObject){
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } else if (window.XMLHttpRequest){
        xmlHttp = new XMLHttpRequest();
      }
      
    }
    
    
    this.hideDummy = function (){
      var dummy = document.getElementById("dummy-menu");
      dummy.style.visibility = "hidden";
      dummy.style.display = "none";
    }
    
    this.getMenu = function(){
      return document.getElementById(this.lang+"-menu");
    }
	
	this.toggleSound = function (){
		var btn = document.getElementById("soundButton");
		if  (btn.className == "soundOn")
			btn.className = "soundOff";
		else
			btn.className = "soundOn";
			
		
		return this.swfExecuteCmd( "toggleSound" );
	}
    
    this.getFlash = function(){
      if (this.flash == null){
        	if(navigator.appName.indexOf("Microsoft") != -1) {
              this.flash = window.JERKY;
          }else {
              this.flash = window.document.JERKY;
          }
        }

        return this.flash;
    }
    
    this.swfChangeLang = function (slang){
		
      if ((this.flash!=null)&&(this.flash!=undefined)){
        this.getFlash().changeLanguage(slang);
        return false;
      }
      else {
        this.changeLang(slang);
        return true;
      }
    }
    
    this.swfExecuteCmd = function (cmdName){
      
      if ((this.flash!=null)&&(this.flash!=undefined)){
        this.getFlash().executeCmd(cmdName);
        return false;
      }
      else return true;
    }
    
   
    
   

}
