// URLparse

/** 
* @projectDescription 	Poly9's polyvalent URLParser class
*
* @author	Denis Laprise - denis@poly9.com - http://poly9.com
* @version	0.1 
* @namespace	Poly9
*
* Usage: var p = new Poly9.URLParser('http://user:password@poly9.com/pathname?arguments=1#fragment');
* p.getHost() == 'poly9.com';
* p.getProtocol() == 'http';
* p.getPathname() == '/pathname';
* p.getQuerystring() == 'arguments=1';
* p.getFragment() == 'fragment';
* p.getUsername() == 'user';
* p.getPassword() == 'password';
*
* See the unit test file for more examples.
* URLParser is freely distributable under the terms of an MIT-style license.
*/

if (typeof Poly9 == 'undefined')
 var Poly9 = {};

/**
 * Creates an URLParser instance
 *
 * @classDescription	Creates an URLParser instance
 * @return {Object}	return an URLParser object
 * @param {String} url	The url to parse
 * @constructor
 * @exception {String}  Throws an exception if the specified url is invalid
 */
Poly9.URLParser = function(url) {
 this._fields = {'Username' : 4, 'Password' : 5, 'Port' : 7, 'Protocol' : 2, 'Host' : 6, 'Pathname' : 8, 'URL' : 0, 'Querystring' : 9, 'Fragment' : 10};
 this._values = {};
 this._regex = null;
 this.version = 0.1;
 this._regex = /^((\w+):\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/;
 for(var f in this._fields)
  this['get' + f] = this._makeGetter(f);
 if (typeof url != 'undefined')
  this._parse(url);
}
 
/**
 * @method 
 * @param {String} url	The url to parse
 * @exception {String} 	Throws an exception if the specified url is invalid
 */
Poly9.URLParser.prototype.setURL = function(url) {
  this._parse(url);
}

Poly9.URLParser.prototype._initValues = function() {
   for(var f in this._fields)
   this._values[f] = '';
}

Poly9.URLParser.prototype._parse = function(url) {
  this._initValues();
  var r = this._regex.exec(url);
  if (!r) throw "DPURLParser::_parse -> Invalid URL"
  for(var f in this._fields) if (typeof r[this._fields[f]] != 'undefined')
   this._values[f] = r[this._fields[f]];
}

Poly9.URLParser.prototype._makeGetter = function(field) {
 return function() {
  return this._values[field];
 }
}

//-----------------------------------------------------------------------------------------------------------------------------------------
//extra
function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return new Array(myWidth,myHeight);
}

//var gb_visible = false;
var gb_opened = "";
var gbwidth = 810;
function togglegb(gbId){
	if(gbId != gb_opened && gb_opened != ""){
		document.getElementById(gb_opened).style.visibility = "hidden";
		gb_opened = "";
	}
	var thesize = getSize();
	var gb_obj = document.getElementById(gbId);
	var gb_left = (thesize[0]/2) - (gbwidth/2);
	gb_obj.style.left = gb_left+"px"
	gb_obj.style.visibility = (gb_obj.style.visibility == "visible" ? "hidden" : "visible");
	if(gb_obj.style.visibility == "visible"){
		gb_opened = gbId;
	}
	if(gb_obj.style.visibility == "hidden"){
		gb_opened = "";
	}
	//gb_visible = !gb_visible;
}
/*
function togglegb(gbId){
	var gb_obj = document.getElementById(gbId);
	var fb_obj = document.getElementById("flashbox");
	var gb_left = fb_obj.offsetLeft + (fb_obj.clientWidth/2) - (gb_obj.clientWidth/2);
	gb_obj.style.left = gb_left+"px";
	gb_obj.style.visibility = (gb_visible ? "hidden" : "visible");
	gb_visible = !gb_visible;
}
*/
var opendelbuttons = new Array();

function getBaseURL(){
	//var thesitebase = "http://localhost";
	var thesitebase = "http://www.aquarena.hu";
	//var thesitebase = "http://www.gear.hu/demos/aquarena";
	return thesitebase;
}
function showdelbutton(imageboxdiv){
	opendelbuttons.push(imageboxdiv);
	imageboxdiv.firstChild.style.visibility='visible';
}

function hidedelbuttons(){	
	while(opendelbuttons.length > 0){	
		var imageboxdiv = opendelbuttons.pop();
		imageboxdiv.firstChild.style.visibility='hidden';
	}
	
}

function whereiam(inflash){
	var url = new Poly9.URLParser(location.href);
    var urlpart = url.getPathname();
	var menu = null;
	if(url.getHost().match(/gear.hu$/)){
		menu = urlpart.match(/^\/demos\/aquarena\/(\w+)\/\w+\.html$/)[1];		
	} else {	
		menu = urlpart.match(/^\/(\w+)\/\w+\.html$/)[1];
	}
	if(inflash == menu){
		return true;
	}
	return false;
}

//---------------------------------------------------------------------------------------------------------------------------------------

// Globals
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// -----------------------------------------------------------------------------
// -->

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//popUp

function NewWindow(theURL,winName,w,h,scroll,res){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+ res +''
win = window.open(theURL,winName,settings)
}