	/**
	 * Javascript Handler
	 * This file will load all necessary javascript files
	 * 
	 * @author Akbar Khrisna
	 * @author Daniel Ockeloen
	 * @copyright Copyright: Noterik B.V. 2009
	 * @access private
	 * @name /js/handler.js
	 * @version $Id: /js/handler.js,v 1.95 2009-05-19 12:33:26 khris Exp $ 
	 */
	 
	var firsttime = "true";
	
	/**
	 * Initialize application
	 * This function will initialize application and load the appropriate javascript modules.
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function initialize()
	{
		// switch based on the type
		switch(loadscript) {
			case "collection":
				include('js/modules/collection/collection.js');
				break;
			case "presentation":
				include('js/modules/presentation/presentation.js');
				break;
			case "user":
				include('js/modules/user/user.js');
				break;
			case "collectiondata":
				include('js/modules/collection/collection.js');
				include('js/modules/presentation/presentation.js');
				break;
		}
		
		// load swf
		load_swf();
	}
	
	/**
	 * Includes function
	 * This function will include the javascript file.
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @param file the javascript to be included (full path required).
	 * @return ingest the javascript file to the document
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function include(file)
	{
		// create element
		var script = document.createElement('script');
		script.src = file;
		script.type = 'text/javascript';
	
		// append to head
		$(script).appendTo("head")
	}
	
	/**
	 * Load swf function
	 * This function will check if swf proxy has been loaded, if not it will load swf inside the page.
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @return ingest the swf file to the document
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function load_swf()
	{
		// check if exist
		if(!$("#playerwrap").length > 0)
		{
		    // create holder and append
		    $("<div id='playerwrap'><div class='playerwrap'><div id='player'></div></div></div>").appendTo("body")
		    	    
	    	// build flash params and create embed
	    	var flashvars = { playerXML :"xml/player.xml" };
	    	var params = { AllowScriptAccess : "always", allowFullScreen : "true" };
	    	swfobject.embedSWF("swf/krusty2.swf", "player", "100%", "100%", "9.0.0","swf/expressInstall.swf", flashvars, params);
	    }
	}
	
	/**
	 * Load presentation
	 * This function will load presentation after \finish loading collection.
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @return ingest the swf file to the document
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function loadcollectionpresentation()
 	{
 		// restart data
		type = "presentation";
		target = "browser/chapters/presentation";
		start = 0;
		limit = 6;
		page = 1;
		numpages = 1;
		contentid = "presentations";
		sort = "presentationtitle";
		query = "collection:"+chosencollection;
		sortorder = "";
		
		// get presentation
		getpresentations(uri,limit,1,query,target,sort,sortorder);
		page = 1;
 	}
 	
 	/**
	 * Select collection
	 * function to select collection and show the appropriate presentations
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @return ingest the swf file to the document
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function selectcollection(collectionuri)
 	{
		// set
		chosencollection = collectionuri;
		query = "collection:"+chosencollection;
		
		// get presentation
		getpresentations(uri,limit,1,query,target,sort,sortorder);
		page = 1;
		
		// set highlight
		highlightcollection();
 	}
 	
 	/**
	 * Highlight collection
	 * This function will highlight selected collection
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @return ingest the swf file to the document
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
 	function highlightcollection() 
 	{
 		var uriparts = chosencollection.split("/");
		$('.collectionlistchosen').attr('class','collectionlist');
		$('#col_'+uriparts[6]).attr('class',"collectionlistchosen");
 	}
 	
	/**
	 * Initial function to load the page
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function loadpage() 
	{
		// retreive the asset
		var query = get_searchquery();
		if(type == "collection") {
			getcollections(uri,limit,1,query,target,sort,sortorder);
			page = 1;
		} else if(type == "presentation") {
			getpresentations(uri,limit,1,query,target,sort,sortorder);
			page = 1;
		} else if(type == "user") {
			getusers(uri,limit,1,target);
			page = 1;
		}
	}
	
	
	/**
	 * Function to return the movie object from html
	 *
	 * @author Daniel Ockeloen
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @return ingest the swf file to the document
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function the_movie(movieName) 
	{
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
    }
	
	/**
	 * Function to parse xml and return the object
	 *
	 * @author Daniel Ockeloen
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @return doc the object
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
 	function stringToXML(text)
 	{
		// if internet explorer
		if (window.ActiveXObject) {
	       var doc = new ActiveXObject('Microsoft.XMLDOM');
	       doc.async = 'false';
	       doc.loadXML(text);
	    } else {
	       // mozilla based
	       var parser = new DOMParser();
	       var doc = parser.parseFromString(text,'text/xml');
	    }
	    
	    // return
	    return doc;
	}
	
	/**
	 * Function to return the javascript status
	 *
	 * @author Daniel Ockeloen
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @return js_ready Javascript status
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function isReady() 
	{
        js_ready = true;
        return js_ready;
    }
    
    /**
	 * Function to return the search query
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @return js_ready Javascript status
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function get_searchquery() 
	{
       return ''; 
    }
    
    /**
	 * Function to clear the search
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @return js_ready Javascript status
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function remove_searchquery() 
	{
        $('#key').attr('value','');
        $('#search_right').attr('class','search_right');
 		loadpage();
    }
    
    /**
	 * Function to select the search box
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function searchselect(label,field) {
		$('#selected'+field).html(label);
		$('#'+field+'list .close_button').css('display','block');
		loadpage();
	}
	
	 /**
	 * Function to restart the search field
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @todo Add a search action or filter when the user is select something
	 * @access private
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function restartsearch(field) {
		var label;
		switch(field) {
			case "keyword":
				label = "Trefwoord";
				break;
			case "person":
				label = "Persoon";
				break;
			case "location":
				label = "Locatie";
				break;
			case "year":
				label = "Jaar";
				break;
		}
		$('#'+field+'list .close_button').css('display','none');
		$('#selected'+field).html(label);
		loadpage();
	}
    
    /**
	 * Function to call the search each time the enter key pressed on the advanced filter box
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @params e Event
	 * @return js_ready Javascript status
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function enter_searchquery(e) 
	{
 		var characterCode;
		if(e && e.which) { 
			e = e;
			characterCode = e.which;
		} else {
			e = event;
			characterCode = e.keyCode;
		}
		if(characterCode == 13) {
			loadpage();
			return false;
		} else {
			return true;
		}
    }
    
    /**
	 * Function to call the search each time the enter key pressed on the main searchbox
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @params e Event
	 * @return js_ready Javascript status
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
	function enter_mainsearchquery(e) 
	{
 		var characterCode;
		if(e && e.which) { 
			e = e;
			characterCode = e.which;
		} else {
			e = event;
			characterCode = e.keyCode;
		}
		if(realtimefilter) {
			loadpage();
		} else {
			if(characterCode == 13) {
				var keyquery = $('#key').attr('value'); 
				if(keyquery != '') {
		    		$('#search_right').attr('class','search_right_active');
					loadpage();
					return false;
		    	}
			} else {
				return true;
			}
		}
    }
    
    /**
	 * Function to clear search query
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @params type
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
    function clear_searchquery(type)
    {
    	// build the id
    	var element = 'selected'+type;
    	$('#'+element).attr('value','');
    	loadpage();
    }
    
     /**
	 * Function to filter the result using the button
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @params type
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
    function filterresult()
    {
    	var keyquery = $('#key').attr('value');
    	$('#search_right').attr('class','search_right_active');
		loadpage();
    }
    
    /**
	 * Function to set the keyword using the shortcut buttons
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @params type
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
    function filterkeyword(key,ids)
    {
    	var barid = "filter_"+ids;
    	$('#selectedkeyword').attr('value',key);
    	$('.keywordbuttonchosen').attr('class','keywordbutton');
    	$('#'+barid).attr('class','keywordbuttonchosen');
    	$('#resetfilter').css('display','block');
    	$('#keyword').html(key);
    	loadpage();
    }
    
    /**
	 * Function to clear search query
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @params type
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
    function clearfilterkeyword()
    {
    	$('#selectedkeyword').attr('value','');
    	$('.keywordbuttonchosen').attr('class','keywordbutton');
    	$('#resetfilter').css('display','none');
    	$('#keyword').html('');
    	loadpage();
    }
    
     /**
	 * Function to show and hide the filter options
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @params e Event
	 * @return js_ready Javascript status
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
    function togglesearch()
    {
    	$('#advancedfiltering').slideToggle('slow');
    	
    	// activate keyword
		activatekeyword('keyword');
    }
    
    
    /**
	 * Function to activate the suggestion box
	 *
	 * @author Akbar Khrisna
	 * @copyright Copyright: Noterik B.V. 2008
	 * @access private
	 * @params e Event
	 * @return js_ready Javascript status
	 * @version $Id: handler.js,v 1.431 2009-06-02 12:14:32 khris Exp $
	 */
    var keywordstatus = false;
    var locationstatus = false;
    var personstatus = false;
    var datestatus = false;
    function activatekeyword(type)
    {
    	if(type == "keyword") {
    		if(keywordstatus == false) {
    			getPresentationKeywords('keyword', '');
    			keywordstatus = true;
    		}
    	} else if(type == "location") {
    		if(locationstatus == false) {
    			getPresentationKeywords('location', '');
    			locationstatus = true;
    		}
    	} else if(type == "date") {
    		if(datestatus == false) {
    			getPresentationKeywords('date', '');
    			datestatus = true;
    		}
    	} else if(type == "person") {
    		if(personstatus == false) {
    			getPresentationKeywords('person', '');
    			personstatus = true;
    		}
    	}
    }