// js for flash menu

function setRequestParamValue(param, newVal) {
	var q = document.location.search || document.location.hash;
	if(q) {
		/*var pairs = q.substring(1).split("&");
		for (var i=0; i < pairs.length; i++) {
			if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
				//return pairs[i].substring((pairs[i].indexOf("=")+1));
			}
		}*/
		var headend = Math.max(location.href.indexOf(location.search), location.href.indexOf(location.hash));
		var head = (location.href.substring(0, headend + 1));
		var pairs = q.substring(1).split("&");
		var tail = "";
		for (var i=0; i < pairs.length; i++) {
			if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
				pairs[i] = param + "=" + newVal;
			}
			tail += pairs[i] + "&";
		}
		tail = tail.substring(0, tail.length - 1);
		return head + tail;
	} else {
		return location.href + '#' + param + '='+newVal;
	}
}

/**
The flash docs is unclear about naming of xxx_DoFSCommand but xxx should match id of flashfile
which in this example is 'flashfile'.
*/
function flashfile_DoFSCommand(command, args) {
	if (command == "messagebox") {
		alert(args);
	} else if (command == "swfSection") {
		location.href = setRequestParamValue('section', args);
	} else if (command == "clickCount") {
		fs(args);
	}
}
function fs(uriToLog) {
	var i=new Image(1,1);
	i.src=uriToLog;
	i.onload=function() {dovoid();}
}
function dovoid() { return; }


var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

// end flash menu js


function showLayer(id){
	if (document.layers)
	{
		current = (document.layers[id].display = 'block');
		document.layers[id].display = current;
	}
	else if (document.all)
	{
		current = (document.all[id].style.display = 'block');
		document.all[id].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(id).style.display = 'block');
		document.getElementById(id).style.display = vista;
	}
}

function hideLayer(id){
	if (document.layers)
	{
		current = (document.layers[id].display = 'none');
		document.layers[id].display = current;
	}
	else if (document.all)
	{
		current = (document.all[id].style.display = 'none');
		document.all[id].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(id).style.display = 'none');
		document.getElementById(id).style.display = vista;
	}
}

function hideAllMusic(){
	try
	{
		hideLayer('rmTrack1');
		hideLayer('rmTrack2');
		hideLayer('rmTrack3');
		hideLayer('rmTrack4');
		hideLayer('rmTrack5');
		hideLayer('rmTrack6');
		hideLayer('rmTrack7');
		hideLayer('rmTrack8');
		hideLayer('rmTrack9');
		hideLayer('rmTrack10');
		hideLayer('rmTrack11');
	}
	catch(err){
	}
}

// spec for javascript to talk to flash

//var movie = window.document.campaignFlash

//movie.SetVariable("soundOnOff", false);



var movieName = "campaignFlash";

function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  }	else {
    return document[movieName]
  }
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
  if (typeof(theMovie) != "undefined") {
    return theMovie.PercentLoaded() == 100;
  } else {
    return false;
  }
}


function soundOn() {
  if (movieIsLoaded(thisMovie(movieName))) {
    thisMovie(movieName).SetVariable("soundOnOff", "on");
  }
}

function soundOff() {
  if (movieIsLoaded(thisMovie(movieName))) {
    thisMovie(movieName).SetVariable("soundOnOff", "off");
  }
}

// Cookie spec

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, days, path, domain, secure) {

  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));

  var curCookie = name + "=" + escape(value) +
      ((days) ? "; expires=" + date.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
      //alert("Kakan är satt!");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/


function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
    //alert("Kakan är tagen!");
  return unescape(dc.substring(begin + prefix.length, end));
}


function chkCookie() {
	if (getCookie('vblogg1') == null)
		showLayer('layerBg');
}

function setC() {
	setCookie('vblogg1','true', 10);
}

