
var ng_sp_session_id="";var ng_sp_session_date_time="";var ng_sp_instructions;var ng_sp_current_index=0;var block_changed_event=jQuery.Event("block_changed");var instruction_changed_event=jQuery.Event("instruction_changed");var play_completed_event=jQuery.Event("play_completed");ng_mode="";$(document).ready(function()
{ng_initialize();$.ajaxSetup({cache:false,timeout:8000,error:function(XMLHttpRequest,textStatus,errorThrown)
{switch(ng_mode)
{case"init":ng_initialize();break;case"system_sel":ng_load_system_selection();break;case"load_ins":ng_load_instructions();break;case"load_lang":ng_load_lang_selection();break;case"new_session":ng_new_session(ng_cf_selected_brand);break;case"mic_access":ng_show_microphone_access_dialog();break;case"mic_test":ng_show_microphone_test();break;case"mic_confirm":ng_load_microphone_test_confirm();break;case"convert_ins":ng_convert_instruction();break;case"rec_ui":ng_load_recording_ui();break;case"load_demo":ng_load_demo();break;case"load_descr":ng_load_descr();break;case"create_pay":ng_create_and_to_payment();break;case"gen_examples":ng_is_active=false;ng_generate_examples();break;}}});$("body").bind('instruction_changed',function(e){ng_instruction_changed_triggered(e);});$("body").bind('block_changed',function(e){ng_block_changed_triggered(e);});$("body").bind('play_completed',function(e){ng_play_completed_triggered(e);});});function ng_instruction_changed_triggered(e)
{if(ng_sp_instructions)
{if(ng_sp_current_index>-1&&ng_sp_instructions[ng_sp_current_index].recorded)
{ng_get_flashmovie("ng_media").stopPlayFileCallback();ng_get_flashmovie("ng_media").playFileCallback(ng_sp_instructions[ng_sp_current_index].play);}
ng_load_inspiration();}}
function ng_initialize()
{ng_mode="init";ng_loading(true);$('#ng_containercentreren').load(ng_cf_proxy+"http://partners.navigoat.com/PluginHandler.ashx?action=initialize&partner_id="+ng_cf_partner_id,function(response,status,xhr){ng_load_system_selection();});}
function ng_load_system_selection()
{ng_mode="system_sel";if(ng_cf_auto_brand>0)
{ng_cf_selected_brand="1";ng_load_instructions();return;}
$('#ng_containercentreren').load('templates/ng_system_selection.html',function(response,status,xhr){ng_loading(false);$('#ng_system_selection_tomtom').bind('click',function(){ng_loading(true);ng_cf_selected_brand="1";ng_load_instructions();});$('#ng_system_selection_garmin').bind('click',function(){ng_loading(true);ng_cf_selected_brand="4";ng_load_instructions();});});}
function ng_loading(bln)
{if(bln)
$('#ng_containercentreren').html("<div id=\"ng_loader\"></div>");}
function ng_load_lang_selection()
{ng_mode="load_lang";if(ng_cf_lang_selection)
{$('#ng_containercentreren').load('templates/ng_lang_selection.html');}
else
{ng_new_session(ng_cf_selected_brand);}}
function ng_load_microphone_test_confirm()
{ng_mode="mic_confirm";$('#ng_containercentreren').load('templates/ng_microphone_test_confirm.html',function(response,status,xhr){ng_loading(false);$('#ng_yes_button').bind('click',function(){ng_loading(true);ng_get_flashmovie("ng_media").stopPlayFileCallback();ng_load_recording_ui();});$('#ng_no_button').bind('click',function(){ng_loading(true);ng_get_flashmovie("ng_media").stopPlayFileCallback();ng_show_microphone_test();});});}
function ng_load_recording_ui()
{ng_mode="rec_ui";$('#ng_containercentreren').load('templates/ng_record.html',function(response,status,xhr){ng_set_block_css();ng_loading(false);ng_show_next_prev();ng_show_goto_demo_button(ng_sp_instructions[ng_sp_current_index].blockindex);$('#ng_record_button').bind('click',function(){ng_record_button_click();});$('#ng_stop_button').bind('click',function(){ng_stop_button_click();});$('#ng_next_button').bind('click',function(){ng_next_button_click();});$('#ng_prev_button').bind('click',function(){ng_prev_button_click();});$('#ng_record_retry_button').bind('click',function(){ng_record_retry_button_click();});$('#ng_play_button').bind('click',function(){ng_get_flashmovie("ng_media").playFileCallback(ng_sp_instructions[ng_sp_current_index].play);});if(block_changed_event.newindex==5)
{ng_load_block(4);ng_load_instruction(ng_sp_instructions.length);}
else
{ng_load_block(ng_sp_instructions[ng_sp_current_index+1].blockindex);ng_load_instruction(ng_sp_current_index+1);}});}
function ng_load_demo(blockindex)
{ng_mode="load_demo";$('#ng_containercentreren').load('templates/ng_examples_block'+blockindex+'.html',function(response,status,xhr){ng_load_block(blockindex);ng_set_block_css(blockindex);$('#ng_example_play_button').bind('click',function(){ng_examples_play_next();});$('#ng_example_stop_button').bind('click',function(){ng_get_flashmovie("ng_media").stopPlayFileCallback();});$('#ng_example_next_button').bind('click',function(){if(block_changed_event.newindex==5)
{ng_load_description();return;}
if(block_changed_event.oldindex>block_changed_event.newindex)
ng_sp_current_index++;ng_load_recording_ui();});$('#ng_example_prev_button').bind('click',function(){if(block_changed_event.oldindex<block_changed_event.newindex)
ng_sp_current_index--;ng_load_recording_ui();});ng_loading(false);});}
function ng_load_description()
{ng_mode="load_demo";ng_loading(true);$('#ng_containercentreren').load('templates/ng_description.html',function(response,status,xhr){ng_loading(false);$('#ng_next_button').bind('click',function(){ng_create_and_to_payment();});$('#ng_prev_button').bind('click',function(){ng_generate_examples();});});}
function ng_create_and_to_payment()
{ng_mode="create_pay";$.getJSON(ng_cf_proxy+"http://partners.navigoat.com/PluginHandler.ashx?action=create&"+ng_cf_parameters_to_string(),function(data){if(data.convert_result.respons=="True")
{var ng_url_split=ng_cf_payment_url.split("?");var ng_url=ng_cf_payment_url;if(ng_url_split.length>1)
ng_url=ng_url_split[0]+"?device="+ng_cf_selected_brand+"&session_id="+ng_sp_session_id+"&session_date_time="+ng_sp_session_date_time+"&"+ng_url_split[1];else
ng_url=ng_url+"?device="+ng_cf_selected_brand+"&session_id="+ng_sp_session_id+"&session_date_time="+ng_sp_session_date_time;location.href=ng_url;}
else
{alert("Error.");}});}
function ng_block_changed_triggered(e)
{ng_generate_examples();}
function ng_set_block_css()
{var ng_idx=ng_get_index_recorded();var ng_block_idx=ng_sp_instructions[ng_idx].blockindex;for(i=1;i<5;i++)
{$('#ng_block'+i).addClass("stappenrondjes rondjetodo");}
for(i=1;i<ng_block_idx;i++)
{$('#ng_block'+i).removeClass("stappenrondjes rondjetodo");$('#ng_block'+i).addClass("stappenrondjes rondjedone");}
$('#ng_block'+ng_block_idx).removeClass("stappenrondjes rondjetodo");$('#ng_block'+ng_block_idx).removeClass("stappenrondjes rondjedone");$('#ng_block'+ng_block_idx).addClass("stappenrondjes rondjeactive");}
function ng_play_completed_triggered(e)
{if(document.getElementById("ng_example_play_button")&&document.getElementById("ng_example_stop_button"))
{document.getElementById("ng_example_play_button").style.display="block";document.getElementById("ng_example_stop_button").style.display="none";}}
function ng_record_button_click()
{ng_recording_show_step("step2");ng_record_file();ng_autostop_record();}
function ng_stop_button_click()
{if(auto_stop_timeout)
{clearInterval(auto_stop_timeout);auto_stop_seconds=101;}
ng_recording_show_step("wait");ng_record_stop();ng_convert_instruction();}
function ng_record_retry_button_click()
{ng_recording_show_step("step2");ng_record_file();ng_autostop_record();}
var auto_stop_timeout;var auto_stop_seconds=101;function ng_autostop_record()
{if(auto_stop_seconds==101)
{auto_stop_seconds--;$('#ng_status').css("margin-right","0%");auto_stop_timeout=setInterval("ng_autostop_record()",50);}
else if(auto_stop_seconds==0)
{clearInterval(auto_stop_timeout);auto_stop_seconds=101;ng_stop_button_click();}
else
{$('#ng_status').css("margin-right",(100-auto_stop_seconds)+"%");auto_stop_seconds--;}}
function ng_record_succeeded_callback(filen)
{ng_get_flashmovie("ng_media").playFileCallback(filen);ng_sp_instructions[ng_sp_current_index].play=filen;ng_sp_instructions[ng_sp_current_index].recorded=true;ng_show_next_prev();ng_recording_show_step("step3");}
function ng_record_failed_callback()
{ng_alert_message("Recording failed. Please try again.");ng_show_next_prev();ng_recording_show_step("step1");}
function ng_recording_show_step(stepid)
{if(!document.getElementById("ng_record_button"))return;document.getElementById("ng_record_button").style.display="none";document.getElementById("ng_stop_button").style.display="none";document.getElementById("ng_play_button").style.display="none";document.getElementById("ng_next_button").style.display="none";document.getElementById("ng_prev_button").style.display="none";document.getElementById("ng_record_retry_button").style.display="none";document.getElementById("ng_record_button").style.display="none";document.getElementById("ng_recording_wait").style.display="none";document.getElementById("ng_statusbalk").style.visibility="hidden";switch(stepid)
{case"step1":document.getElementById("ng_record_button").style.display="inline";ng_show_next_prev();break;case"step2":document.getElementById("ng_stop_button").style.display="inline";document.getElementById("ng_statusbalk").style.visibility="visible";break;case"step3":document.getElementById("ng_record_retry_button").style.display="inline";document.getElementById("ng_play_button").style.display="inline";ng_show_next_prev();break;case"wait":document.getElementById("ng_recording_wait").style.display="inline";break;}}
function ng_next_button_click()
{ng_get_flashmovie("ng_media").stopPlayFileCallback();ng_sp_current_index++;if(ng_sp_current_index==ng_sp_instructions.length)
{block_changed_event.oldindex=4;block_changed_event.newindex=5;$("body").trigger(block_changed_event);ng_recording_show_step("wait");return;}
ng_load_instruction(ng_sp_current_index+1);ng_show_next_prev();if(eval(ng_sp_instructions[ng_sp_current_index].recorded)==true)
ng_recording_show_step("step3");else
ng_recording_show_step("step1");if(parseInt(ng_sp_instructions[ng_sp_current_index-1].blockindex)!=parseInt(ng_sp_instructions[ng_sp_current_index].blockindex))
{block_changed_event.oldindex=ng_sp_instructions[ng_sp_current_index-1].blockindex;block_changed_event.newindex=ng_sp_instructions[ng_sp_current_index].blockindex;$("body").trigger(block_changed_event);ng_recording_show_step("wait");}}
function ng_prev_button_click()
{ng_get_flashmovie("ng_media").stopPlayFileCallback();ng_sp_current_index--;ng_load_instruction(ng_sp_current_index+1);ng_show_next_prev();ng_recording_show_step("step3");if(parseInt(ng_sp_instructions[ng_sp_current_index+1].blockindex)!=parseInt(ng_sp_instructions[ng_sp_current_index].blockindex))
{block_changed_event.oldindex=ng_sp_instructions[ng_sp_current_index+1].blockindex;block_changed_event.newindex=ng_sp_instructions[ng_sp_current_index].blockindex;$("body").trigger(block_changed_event);}}
function ng_show_next_prev()
{ng_index=ng_get_index_recorded();document.getElementById("ng_prev_button").style.display=ng_sp_current_index>0?"inline":"none";document.getElementById("ng_next_button").style.display=eval(ng_sp_instructions[ng_sp_current_index].recorded)==true?"inline":"none";}
function ng_load_instruction(ng_index)
{ng_sp_current_index=ng_index-1;if(!document.getElementById("ng_instruction"))
{ng_load_recording_ui();return;}
if(eval(ng_sp_instructions[ng_sp_current_index].recorded))
ng_recording_show_step("step3");else
ng_recording_show_step("step1");document.getElementById("ng_instruction").innerHTML=ng_sp_instructions[ng_index-1].text;ng_load_block(ng_sp_instructions[ng_index-1].blockindex);ng_show_next_prev();instruction_changed_event.index=ng_sp_current_index;$("body").trigger(instruction_changed_event);}
function ng_show_goto_demo_button(blockidx)
{result=true;for(i=1;i<ng_sp_instructions.length;i++)
{if(parseInt(ng_sp_instructions[i].blockindex)==parseInt(blockidx)&&eval(ng_sp_instructions[i].recorded)==false)
{result=false;break;}}
var dp_value=result?"block":"none";$('#ng_end_of_block_button').css("display",dp_value);$('#ng_end_of_block_button').bind('click',function(){ng_sp_current_index=ng_get_first_idx_of_block((parseInt(blockidx)+1))+1;if(ng_sp_current_index>=ng_sp_instructions.length)
{block_changed_event.oldindex=4;block_changed_event.newindex=5;$("body").trigger(block_changed_event);ng_recording_show_step("wait");return;}
block_changed_event.oldindex=ng_sp_instructions[ng_sp_current_index-1].blockindex;block_changed_event.newindex=ng_sp_instructions[ng_sp_current_index].blockindex;$("body").trigger(block_changed_event);ng_recording_show_step("wait");});}
function ng_get_first_idx_of_block(blockidx)
{var first_of_block=-1;for(x=0;x<ng_sp_instructions.length;x++)
{if(parseInt(ng_sp_instructions[x].blockindex)==parseInt(blockidx))
{return x-1;}}
return ng_sp_instructions.length-1;}
function ng_get_index_recorded()
{for(i=1;i<ng_sp_instructions.length;i++)
{if(eval(ng_sp_instructions[i].recorded)==false)
{return i;break;}}
return(ng_sp_instructions.length-1);}
function ng_load_instructions()
{ng_mode="load_ins";$.getJSON(ng_cf_proxy+"http://partners.navigoat.com/PluginHandler.ashx?action=get_instructions&"+ng_cf_parameters_to_string(),function(data){ng_sp_instructions=data.instructions.items;ng_load_lang_selection();});}
function ng_load_block(blockidx)
{is_first=true;document.getElementById("ng_instructions").innerHTML="";for(i=0;i<ng_sp_instructions.length;i++)
{if(ng_sp_instructions[i].blockindex==blockidx)
{if(is_first)
document.getElementById("ng_instructions").start=(i+1);if(i==ng_sp_current_index)
document.getElementById("ng_instructions").innerHTML+="<li id='ng_list_item_'"+i+" class=\"menu_active\">"+ng_sp_instructions[i].text+"</li>";else if(eval(ng_sp_instructions[i].recorded))
document.getElementById("ng_instructions").innerHTML+="<li id='ng_list_item_'"+i+"><a href='javascript: ng_load_instruction("+(i+1)+");'>"+ng_sp_instructions[i].text+"</a></li>";else
document.getElementById("ng_instructions").innerHTML+="<li id='ng_list_item_'"+i+" class=\"menu_inactive\">"+ng_sp_instructions[i].text+"</li>";is_first=false;}}}
function ng_new_session(ng_cf_selected_brand)
{ng_mode="new_session";$.getJSON(ng_cf_proxy+"http://partners.navigoat.com/PluginHandler.ashx?action=new_session&"+ng_cf_parameters_to_string(),function(data){ng_sp_session_id=data.session.id;ng_sp_session_date_time=data.session.datetime;ng_create_cookie("ng_sp_session_id",ng_sp_session_id,30);ng_create_cookie("ng_sp_session_date_time",ng_sp_session_date_time,30);$('#ng_media_container').css('display','block');});}
function ng_proceed()
{ng_set_flash_parameters(ng_cf_partner_id,ng_sp_session_id,ng_sp_session_date_time);ng_show_microphone_access_dialog();}
var ng_convert_timeout;function ng_convert_instruction()
{ng_mode="convert_ins";$.getJSON(ng_cf_proxy+"http://partners.navigoat.com/PluginHandler.ashx?action=convert&"+ng_cf_parameters_to_string(),function(data){if(is_mic_test)
{ng_get_flashmovie("ng_media").playFileCallback(data.convert_result.respons);is_mic_test=false;ng_load_microphone_test_confirm();}
else
{if(data.convert_result.respons.length==0)
ng_record_failed_callback();else
ng_record_succeeded_callback(data.convert_result.respons);}});}
function ng_convert_fallback()
{ng_record_failed_callback();}
var ng_examples;var ng_examples_index=0;var ng_is_active=false;function ng_generate_examples()
{ng_mode="gen_examples";if(ng_is_active)return;ng_is_active=true;ng_loading(true);blockidx=block_changed_event.oldindex<block_changed_event.newindex?block_changed_event.oldindex:block_changed_event.newindex;$.getJSON(ng_cf_proxy+"http://partners.navigoat.com/PluginHandler.ashx?action=examples&"+ng_cf_parameters_to_string()+"&blockindex="+blockidx,function(data){ng_example_result=""+data.convert_result.respons;if(ng_example_result.length>0)
{ng_examples=ng_example_result.split(";");if(block_changed_event.oldindex<block_changed_event.newindex)
{ng_load_demo(block_changed_event.oldindex);}
else
{ng_load_demo(block_changed_event.newindex);}}
if(ng_sp_current_index<ng_sp_instructions.length)
ng_show_goto_demo_button(ng_sp_instructions[ng_sp_current_index].blockindex);ng_is_active=false;});}
function ng_examples_play_next()
{ng_examples_index++;if(ng_examples_index==ng_examples.length-1)
ng_examples_index=0;ng_get_flashmovie("ng_media").playFileCallback(ng_examples[ng_examples_index]);}
function ng_play_completed()
{$("body").trigger(play_completed_event);}
function ng_set_flash_parameters(partnerId,sessionId,dateTime)
{ng_get_flashmovie("ng_media").setConfigParametersCallback(partnerId,sessionId,dateTime);}
function ng_cf_parameters_to_string()
{ng_index=is_mic_test?0:(ng_sp_current_index+1);ng_descr=document.getElementById("txt_gps_voice_title")?document.getElementById("txt_gps_voice_title").value:"";ng_descr=ng_descr.split(" ").join("[NBSP]");ng_descr=ng_descr.split("&").join("[AMP]");return"lang="+ng_cf_lang_default+"&device="+ng_cf_selected_brand+"&partner_id="+ng_cf_partner_id+"&datetime="+ng_sp_session_date_time+"&sessionid="+ng_sp_session_id+"&instruction="+ng_index+"&description="+ng_descr;}
function ng_show_microphone_access_dialog()
{ng_mode="mic_access";$('#ng_containercentreren').load('templates/ng_header_microphone_access.html',function(){ng_loading(false);$('#ng_flash_container').css('display','block');});}
function ng_show_microphone_test()
{ng_mode="mic_test";ng_loading(true);$('#ng_containercentreren').load('templates/ng_microphone_test.html',function(){$('#ng_media_container').css("z-index","0");$('#ng_containercentreren').css("z-index","1");ng_loading(false);$('#ng_header_microphone_access_step1').bind('click',function(){ng_start_test_record();});});}
function ng_show_microphone_access_denied()
{ng_alert_message("Toestemming geven is noodzakelijk voor het gebruik van deze dienst.");ng_load_flashplugin();}
function ng_alert_message(smessage)
{alert(smessage);}
function ng_show_activitylevel(activitylevel)
{$('#ng_status').css("margin-right",100-activitylevel+"%");}
function ng_get_flashmovie(movieName){var isIE=navigator.appName.indexOf("Microsoft")!=-1;return(isIE)?window[movieName]:document.getElementById(movieName);}
var is_mic_test=false;var ng_countdown_counter;var ng_countdown_interval;function ng_start_test_record(){ng_countdown_counter=5;document.getElementById("ng_header_microphone_access_step1").style.display="none";document.getElementById("ng_header_microphone_access_step2").style.display="block";ng_get_flashmovie("ng_media").micTestStartCallback();document.getElementById("ng_countdown").innerHTML="...recording will last for "+ng_countdown_counter+" seconds...";ng_countdown_interval=setInterval("ng_countdown()",1000);}
function ng_countdown()
{ng_countdown_counter--;document.getElementById("ng_countdown").innerHTML="...recording will last for "+ng_countdown_counter+" seconds...";if(ng_countdown_counter==-1)
{clearInterval(ng_countdown_interval);ng_stop_test_record();}}
function ng_stop_test_record(){ng_loading(true);ng_get_flashmovie("ng_media").micTestStopCallback();ng_show_activitylevel(0);is_mic_test=true;ng_convert_instruction();}
function ng_record_file()
{ng_get_flashmovie("ng_media").recordStreamCallback(ng_sp_current_index+1);}
function ng_record_stop()
{ng_get_flashmovie("ng_media").recordStopCallback();}
function ng_load_inspiration()
{ng_system=ng_cf_selected_brand=="1"?"tomtom":"garmin";ng_examples=ng_cf_selected_brand=="1"?ng_cf_examples_tomtom:ng_cf_examples_garmin;if(ng_examples.length==0)
{$("#ng_player_container").css("display","none");return;}
var flashvars={};flashvars.height="200";flashvars.width="150";flashvars.autostart="false";flashvars.backcolor=ng_cf_player_backcolor;flashvars.frontcolor=ng_cf_player_frontcolor;flashvars.lightcolor=ng_cf_player_lightcolor;flashvars.skin="swf/simple.swf";flashvars.allowSciptAccess="always";flashvars.playlist="top";flashvars.file="inspiration.php?config="+ng_system+","+ng_examples+","+(ng_sp_current_index+1);var params={};params.play="true";params.loop="false";params.menu="false";params.quality="best";params.allowfullscreen="false";params.allowscriptaccess="always";params.wmode="opaque";var attributes={};attributes.id="inspiration_player";attributes.name="inspiration_player";if(swfobject.getObjectById("inspiration_player")){swfobject.getObjectById("inspiration_player").sendEvent("LOAD",flashvars.file);return;}
swfobject.embedSWF("swf/player.swf","ng_player","200","150","9.0.0",false,flashvars,params,attributes);}
function ng_create_cookie(name,value,days)
{if(days)
{var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}
else var expires="";document.cookie=name+"="+value+expires+"; path=/";}
function ng_read_cookie(name)
{var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++)
{var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}
return null;}
