//flash disabling /enabling script 

// used with swfObject flash ebedding script 

//author: Sakari Laaksonen, Naviatech / Satama Interactive

// Requires changes in the implementation routine of swfobject scripts.

//each new swbobject must be conditionalised according to noflashObj.noflash attribute





//OBJECT CONSTRUCTOR



function flashTogglerObj(css) {



//parameters: default value for showing flash: 0 = show flas, 1 = don't show

//css defines the path to the stylesheet that contains styles for enable/disable button

//if css is not false | 0 | null, it will add a <link> tag that will import the stylesheet defined by 'css'

//see set_button_style() for details



//attributes / vars



this.defaultVal = '0';

this.noflash;

this.cookieName = 'viewNokiaFlash';



// methods / functions

this.SetCookie = create_cookie; 

this.ReadCookie = read_cookie;

this.ToggleFlash = toggle_flash;

this.SetButton = set_button;

this.SetButtonStyle = set_button_style;



//run inner functions

//if cookie is not found, make it. 

this.noflash = this.ReadCookie(this.cookieName);

if (this.noflash === null) {



  this.SetCookie(this.cookieName, this.defaultVal);

  this.noflash = this.ReadCookie();

}





// import button styles if css path is given

if(css) {this.SetButtonStyle(css);}

//Make the toggler button

this.SetButton();



}



//INNER FUNCTIONS



//cookie functions from  Nokia survey scripts

function create_cookie(name, value, days) {

 if(days) {

    var date = new Date();

    var expirationTime = 24*60*60*1000*180;  

    date.setTime(date.getTime() + expirationTime) //(days*60*60*1000)); *24*60*60*1000

    var expires = "; expires="+date.toGMTString();

 } else {

    expires = "";

 }

 document.cookie = name+"="+value+expires+"; path=/";

 //alert(document.cookie);



}



function 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;

}







  function set_button_style(css) {

//if css path is set, import the given css  



  var headNode = document.getElementsByTagName('head')[0];

  

   if(IE()) {

  //IE does not properly support createElement & setAttribute functions

   var linkTag = '<link href="'+css+'" rel="stylesheet" type="text/css"/>';

   linkNode = document.createElement(linkTag);

   } 

   else {

   var linkNode = document.createElement('link');

   linkNode.setAttribute('href',css);

   linkNode.setAttribute('rel' , 'stylesheet');

   linkNode.setAttribute('type','text/css');

   

   }

  headNode.appendChild(linkNode);

  return;

  }

  



  function toggle_flash() {

  //if cookie value = '0', set it to '1' and vice versa

     this.noflash !== '1' ? this.SetCookie(this.cookieName,'1') : this.SetCookie(this.cookieName,'0');

    

    //reload the page    

     window.location.reload();

  }

  



  function set_button() {



    var text = '';

    this.noflash !== '1' ? text = ' 關閉 flash 動畫 ' : text = ' 開啟 flash 動畫 ';

    //place the button inside  <div id="flashbuttoncontainer" />

    document.getElementById('flashbuttoncontainer').innerHTML = '<span id="flashbutton" onclick="FlashToggler.ToggleFlash();">'+text+'</span>';

     

  }





function IE() {

var browser = navigator.appName;

//var version = navigator.appVersion;

return browser == "Microsoft Internet Explorer" //? r = true: r = false;

//return r;

}

// JavaScript Document

