// stateNav.js
// v 0.9.0
// 2005-10-07
// leo@blixtsystems.com
// Part of statemanagement system for flash
// Full package available at:
// http://www.blixtsystems.com/index.html#page=download&pid=14&ss=pid
// Licensed under GNU GPL, see license.txt included with package for details
//
// browser detection
var ua = navigator.userAgent.toLowerCase();
var is_pc_ie  = ( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ) );
var is_ff =( (ua.indexOf('gecko') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('safari') == -1 ));
var is_opera=(ua.indexOf('opera') != -1);
function setFlashVariables(movieid, flashquery){
	var i,values;
	var chunk = flashquery.split("&");
	for(i in chunk){
		values = chunk[i].split("=");
		if(is_pc_ie){
			document[movieid].SetVariable(values[0],values[1]);
		}
		if(values[0]=="page"){
		var page=values[1];

		}
	}
	document.title = siteName + " " + page;
	if(!is_pc_ie){

		var flashProxy = new FlashProxy(uid, "myMovie", '../jsi/JavaScriptFlashGateway.swf');
		flashProxy.call('setVars', chunk);
	} else {
		putHref(flashquery, page);
	}
 }
// function for parsing state string to an object
function getParams(){
	var o = new Object();
	var stateStr = new String(document.location.search.substr(1) || document.location.href.split("#")[1]);
	var states = stateStr.split("&");
	var len = states.length;
	for (var i=0; i<len; i++) {
		var p = states[i].split("=");
		o[p[0]] = p[1];
	}
	return o;
}
// at least FF  need this function to return to the page after address bar been updating
function getState() {
//alert('getState');
	var params = new String(window.document.location.hash.split("#")[1]);
	setFlashVariables('myMovie', params);
}
// non IE browser use this javascript to update hash and title
function putHref(stateStr, page) {
	var str=new String(stateStr);
	str=str.replace(/,/g, "&");
	window.document.location.hash=str;
	var i,values;
	var chunk = str.split("&");
	for(i in chunk){
		values = chunk[i].split("=");
		if(values[0]=="page"){
			var pageTitle=values[1];

		}
	}
	window.document.title = siteName + " " + pageTitle;
}
function obj2String(o){
	var str="";
	for (var prop in o) {
		str += prop+"="+o[prop]+"&";
	}
	//str = substring(str, 0, str.length-1);
	return str;
}
