var jsReady = false;
var url_title ="";
var module ="";
$(document).ready(function(){   
        initHistoryLinks();   
        var anchor = window.location.hash.replace(/^.*#/, '').split("/");
        if(anchor[0]=="gallery"){module="gallery"}else{module="robot"}
        loadFlashHeader();     	
        pageInit(); 
});
function pageInit() {
	jsReady = true;          
}	
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
function pageload(hash) {	
	if(hash) {initHash(hash);} else {showIndexContent();}                      
}	
function initHash(hash){
	if(hash=="over"){showOverContent(false);}else{
            if(hash=="index")
             {showIndexContent();}else{
		var urlData = hash.split("/");
		if(urlData[1]!=undefined){    
                         url_title =urlData[1];
                         showGalleryItem(url_title,false);                    
		}else{showGalleryIndex(false);}  
            }                   
	}              	
}
function loadFlashHeader(){ 
	var params = {};
        var flashvars= {};
	params.wmode = "transparent";
	params.allowScriptAccess="*";
	swfobject.embedSWF("/header.swf", "flash-header", "969", "412", "9.0.0","swf/expressInstall.swf",flashvars,  params);
}
function flashMenuCommand (module){
	switch(module) {
             case ("gallery"):
                  showGalleryIndex(true);                   
             break;
             case ("atelier"):
                  window.location = "/index.php?/atelier";
                  $("#content").html("");   
             break;
             case ("journaal"):
                  window.location = "/index.php?/nieuws";
                  $("#content").html("");   
             break;
             case ("about"):  
                   showOverContent(true);
             break;
    }
}
function getModule(){return module};
function flashGalleryCommand(url){
        url_title = url;
	showGalleryItem(url_title,true);
}  
function responseToonzaalContent(responseText, statusText){$("#content").html(responseText);}
function showIndexContent(){if(jsReady){thisMovie("flash-header").goToRobot("1");} 
	var loadPath='/index.php?/'+'site/index_content';
	$.ajax({url:loadPath,type: 'GET',success:responseIndexContent});
}        
function responseIndexContent(responseText, statusText){
	$("#content").html(responseText);            
	$("#toonzaalLink").click(function(){			
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');			
		$.historyLoad(hash);
		return false;
	});
}
function showGalleryIndex(fromFlash){         
	if(fromFlash){
	       var hash = "#gallery";
	       hash = hash.replace(/^.*#/, '');
	       $.historyLoad(hash);
        }else{if(jsReady){thisMovie("flash-header").goToGallery("1","http://en.mymachine.be/index.php?/atelier/gallery/");}    
	       var loadPath='/index.php?/'+'site/toonzaal_index_content';
	       $.ajax({url:loadPath,type: 'GET',success:responseToonzaalIndexContent}); 
        }    
}       
function responseToonzaalIndexContent(responseText, statusText){$("#content").html(responseText);}
function showGalleryItem(url,fromFlash){
	if(fromFlash){ 
     	       var hash ="#gallery/"+url;  
	       hash = hash.replace(/^.*#/, '');
	       $.historyLoad(hash);          
      }else{
               	var loadPath='/index.php?/'+'site/toonzaal_content/'+url;
	        $.ajax({url:loadPath,type: 'GET',success:responseToonzaalContent});  
               if(jsReady){thisMovie("flash-header").goToGallery("1","/index.php?/atelier/gallery/");}         
        }    
}     
function showOverContent(fromFlash){       
        if(fromFlash){               
	       var hash = "#over";
	       hash = hash.replace(/^.*#/, '');
	       $.historyLoad(hash);
        }else{
	       var loadPath='/index.php?/'+'site/over_content';
	       $.ajax({url:loadPath,type: 'GET',success:responseOverContent}); 
	       if(jsReady){thisMovie("flash-header").goToRobot("1");} 
        }
}    
function getGalleryXML()
{
       return "/index.php?/atelier/gallery/";
}    
function responseOverContent(responseText, statusText){$("#content").html(responseText);}
function initHistoryLinks(){       
	$.historyInit(pageload);                
	$("a[@rel='history']").click(function(){			
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');			
		$.historyLoad(hash);			
		return false;
	});
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////// menu////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function initMenu(current)
{
     $("#menu > ul > li").each(
                function() 
                {
                    if(current==jQuery(this).attr("class"))
                    {jQuery(this).addClass("current");}else{jQuery(this).removeClass("current");}    
                }
        )
}	