/*function detect_font(){
	var detective = new Detector();
	if (!detective.test('Estrangelo Edessa')){
		changeStyle('/style/style_moz_alt.css');
	}
}

function changeStyle(url){ 
	document.getElementById('stylesheet').href=url;
	var _head = document.getElementsByTagName('head')[0];  
	var _link = document.createElement('link');
	_link.type = 'text/css';
	_link.href = url;
	_link.rel = 'stylesheet';
	_head.appendChild(_link);
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}
*/

function geen_toegang(){
	alert('Deze bewerking mag alleen uitgevoerd worden door Ingrid.');
}
function nieuwsbrief_stats(lokatie){
	statswindow=window.open("/includes/nieuwsbrief/stats2.php?lokatie="+lokatie, 'statistieken','left=14,top=4,width=715,height=450,menubar=0,resizable=0,toolbar=0,status=0,location=0');
	if (window.focus) {statswindow.focus()}
	return false;
}
function adressen_export(lokatie){
	statswindow=window.open("/includes/export_email.php?lokatie="+lokatie, 'exporteer_adressen','left=14,top=4,width=715,height=450,menubar=0,resizable=1,scrollbars=1,toolbar=0,status=0,location=0');
	if (window.focus) {statswindow.focus()}
	return false;
}

function nwbr_onderhoud(lokatie){
	statswindow=window.open("/includes/nieuwsbrief/aanmaken/create_nwbr.php?lokatie="+lokatie, 'nieuwsbrief_onderhoud','left=14,top=4,width=533,height=405,menubar=0,resizable=1,scrollbars=1,toolbar=0,status=0,location=0');
	if (window.focus) {statswindow.focus()}
	return false;
}

function nieuwsbrief_abonnees(lokatie){
	abonneewindow=window.open("/includes/nb_adressen.php?lokatie="+lokatie, 'abonnees','left=14,top=4,width=825,height=450,menubar=0,resizable=0,toolbar=0,status=0,location=0');
	if (window.focus) {abonneewindow.focus()}
	return false;
}

function wijzig_banner_upload(lokatie){
	fotowindow=window.open("/includes/select_image.php?type=banner&lokatie="+lokatie+"&map=.", 'foto_selectie', 'left=14,top=4,width=620,height=535,menubar=0,resizable=0,toolbar=0,status=0,location=0');
	if (window.focus) {fotowindow.focus()}
	return false;
}

function rotation_upload(lokatie){
	fotowindow=window.open("/includes/select_image.php?type=rotation&lokatie="+lokatie+"&map=.", 'foto_selectie', 'left=14,top=4,width=620,height=335,menubar=0,resizable=0,toolbar=0,status=0,location=0');
	if (window.focus) {fotowindow.focus()}
	return false;
}

function wijzig_banner_status(lokatie,status){
	var verwijder=0;
/*	if (status=="uit"){
		agree=confirm('Wilt u de banner-bestanden verwijderen?');
		if(agree){
			var verwijder=1;
		}

	}
*/	new Ajax.Request('/includes/set_banner_status.php?verwijder='+verwijder+'&status='+status+'&lokatie='+lokatie+'&zomaar='+Math.random(), {
		method: 'get',
		onSuccess: function(transport) {
			document.getElementById('banner_status').innerHTML='&nbsp;Banner staat '+status+'&nbsp;';
//			document.getElementById('banner_status_img').onclick='wijzig_banner_status(\''+lokatie+'\',\''+status+'\');';
//			document.getElementById('banner_status_img').title='Banner '+status_oud+'zetten';
//			document.getElementById('banner_status_img').src='/images/icon_banner_'+status_oud+'1.png';
			if(status=='uit'){
				document.getElementById('banner_status_img_aan').style.display='block';
				document.getElementById('banner_status_img_uit').style.display='none';
			}else{
				document.getElementById('banner_status_img_aan').style.display='none';
				document.getElementById('banner_status_img_uit').style.display='block';
			}
			if(verwijder==1){
				window.location=window.location;
			}
		}
	});
}

function diabalk_wijzigen(lokatie){
	newwindow=window.open("/includes/diabalk_wijzig.php?lokatie="+lokatie, 'diabalk_wijzig', 'left=14,top=4,width=843,height=635,menubar=0,resizable=0,toolbar=0,status=0,location=0');
	if (window.focus) {newwindow.focus()}
	return false;
}

function item_toevoegen(type,id){
	newwindow1=window.open("/includes/eigenschappen_wijzig.php?id="+id+"&type="+type, 'eigenschap', "left=14,top=4,width=533,height=335,menu=0,menubar=0,resizable=0,toolbar=0,status=0,location=0");
	if (window.focus) {newwindow1.focus()}
	return false;
}

function pagina_wijzigen(id){
	newwindow=window.open("/includes/pagina_wijzig.php?id="+id, 'wijzig', 'left=14,top=4,width=843,height=635,menubar=0,resizable=0,toolbar=0,status=0,location=0');
	if (window.focus) {newwindow.focus()}
	return false;
}

function eigenschappen_wijzigen(id){
	newwindow1=window.open("/includes/eigenschappen_wijzig.php?id="+id, 'eigenschap', "left=14,top=4,width=533,height=335,menu=0,menubar=0,resizable=0,toolbar=0,status=0,location=0");
	if (window.focus) {newwindow1.focus()}
	return false;
}

function preview(lokatie,pagina){
	new Ajax.Request('/includes/set_preview.php?zomaar='+Math.random(), {
		method: 'get',
		onSuccess: function(transport) {
			if(transport.responseText=="aan"){
				document.getElementById('img_preview').src='/images/icon_preview1.png';
				document.getElementById('preview-modus').style.display='block';
				document.getElementById('pagina_publishen').style.display='block';
			}else{
				document.getElementById('img_preview').src='/images/icon_no_preview1.png';
				document.getElementById('preview-modus').style.display='none';
				document.getElementById('pagina_publishen').style.display='none';
			}
			laden(lokatie,pagina);
		}
	});
}

function pagina_publishen(id){
	agree=confirm('Weet u zeker dat u de huidige preview wilt publiceren?');
	if(agree){
		new Ajax.Request('/includes/pagina_publish.php?id='+id+'&zomaar='+Math.random(), {
			method: 'get',
			onSuccess: function(transport) {
				alert(transport.responseText);	
			}
		});
	}
}

function pagina_verwijderen(id){
	agree=confirm('Weet u zeker dat u de huidige item wilt verwijderen?');
	if(agree){
		new Ajax.Request('/includes/pagina_wijzig.php?actie=verwijderen&id='+id+'&zomaar='+Math.random(), {
			method: 'get',
			onSuccess: function(transport) {
				alert(transport.responseText);	
				window.location=window.location;
			}
		});
	}
}

function uitloggen(){
	new Ajax.Request('/includes/set_login.php?uitloggen=1&zomaar='+Math.random(), {
		method: 'get',
		onSuccess: function(transport) {
			window.location=window.location;
		}
	});
}


function dbgrid_hoogte(moz4){
	var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;	
	if(moz4<=0){
		document.getElementById('body').style.height=windowHeight;
	}
}

function geef_melding(melding){
	setTimeout("alert('"+melding+"');",1000);
}

function laden(lokatie,pagina){
	new Ajax.Request('/includes/header.php?lokatie='+lokatie+'&pagina='+pagina, {
		method: 'get',
		onSuccess: function(transport) {
			document.title=transport.responseText;
		}
	});
	new Ajax.Request('/includes/hoofdmenu.php?lokatie='+lokatie+'&pagina='+pagina, {
		method: 'get',
		onSuccess: function(transport) {
			document.getElementById('hoofdmenu').innerHTML=transport.responseText;
		}
	});
	new Ajax.Request('/includes/lessenmenu.php?lokatie='+lokatie+'&pagina='+pagina, {
		method: 'get',
		onSuccess: function(transport) {
			document.getElementById('lessenmenu').innerHTML=transport.responseText;
		}
	});
	new Ajax.Request('/includes/pagina.php?direct=1&lokatie='+lokatie+'&pagina='+pagina, {
		method: 'get',
		onSuccess: function(transport) {
			var response=transport.responseText.split('||');
			var response2=response[1].split('|');
			document.getElementById('content').innerHTML=response[0];
/*			alert(document.getElementById('po_content_tmpl_'+response2[0]).clientHeight);*/
			if(document.getElementById('po_content_tmpl_'+response2[0]) != 'undefined' && document.getElementById('po_content_tmpl_'+response2[0]) != null){
				document.getElementById('po_content_tmpl_'+response2[0]).style.height=response2[1];
			}
/*			alert(document.getElementById('po_content_tmpl_'+response2[0]).clientHeight);*/
/*			setTimeout(run_ecrir+';', 0);*/
		}
	});
}

function domail(lokatie){
	window.location='mailto:'+lokatie+'@ladysports.nu';
}

function show_mail(lokatie){
	document.write( "<span>"+lokatie+"</span>" + "@" + "<span>ladysports.nu</span>");
}


function fclick(element){
	var lijst="";
	var list=document.getElementById('radiobuttons').getElementsByTagName('div');
	      for ( var i = 1; i < list.length; i++ ) {
				if(list[i].id.indexOf("_img")>0){
					if(list[i].id==element.id+'_img'){
						document.getElementById(list[i].id).className="radio-button-sel";
						document.getElementById('nba_via').value=document.getElementById(element.id).value;
						if(document.getElementById('nba_via').value == 'undefined'){
							document.getElementById('nba_via').value=document.getElementById(element.id+'x').value;
						}
					}else{
						document.getElementById(list[i].id).className="radio-button";
					}
				}
		  }
	if(document.getElementById('nba_via').value=='Anders'){
		document.getElementById('nba_via_anders').disabled=false;
	}else{
		document.getElementById('nba_via_anders').disabled=true;
	}
}

function fclick_interesse(element){
	var lijst="";
	var list=document.getElementById('radiobuttons_interesse').getElementsByTagName('div');
	      for ( var i = 1; i < list.length; i++ ) {
				if(list[i].id.indexOf("_img")>0){
					if(list[i].id==element.id+'_img'){
						document.getElementById(list[i].id).className="radio-button-sel";
						document.getElementById('int_contacttijdstip').value=document.getElementById(element.id).value;
						if(document.getElementById('int_contacttijdstip').value == 'undefined'){
							document.getElementById('int_contacttijdstip').value=document.getElementById(element.id+'x').value;
						}
					}else{
						document.getElementById(list[i].id).className="radio-button";
					}
				}
		  }
}

var doorgaan;

function check_captcha(code){
	alert('check_captcha '+code);
	new Ajax.Request('/includes/check_code.php?code='+code, {
		method: 'get',
		onSuccess: function(transport) {
			alert('uitslag: '+transport.responseText);
			doorgaan=transport.responseText;
		}
	});
}

function interesse_opslaan(){
	var url='/includes/opslaan_interesse.php?tabel=interesse';
	var avelden=new Array();
	var awaarden=new Array();
	if(!controle('int_voornaam') || !controle('int_contacttijdstip') || !controle('int_naam') || !controle('int_woonplaats') || !controle('int_telefoon') || !controle('int_email') || !controle('int_geboortedatum')){
		alert('U dient alle verplichte velden in te vullen.');
	}else{
		new Ajax.Request('/includes/check_code.php?code='+document.getElementById('captcha_code').value, {
			method: 'get',
			onSuccess: function(transport) {
				if(transport.responseText=="OK"){
					do_opslaan(url,'interesse');
				}else{
					document.getElementById('captcha').src = '/captcha/securimage_show.php?' + Math.random();
					alert('De beveiligingscode is niet correct.');
					document.getElementById('captcha_code').value = '';
				}
			}
		});
	}
}

function proefweek_opslaan(){
	var url='/includes/opslaan_proefweek.php?tabel=proefweek';
	var avelden=new Array();
	var awaarden=new Array();
	if(!controle('int_contacttijdstip') || !controle('int_naam') || !controle('int_telefoon') || !controle('int_email')){
		alert('U dient alle verplichte velden in te vullen.');
	}else{
		new Ajax.Request('/includes/check_code.php?code='+document.getElementById('captcha_code').value, {
			method: 'get',
			onSuccess: function(transport) {
				if(transport.responseText=="OK"){
					do_opslaan(url,'proefweek');
				}else{
					document.getElementById('captcha').src = '/captcha/securimage_show.php?' + Math.random();
					alert('De beveiligingscode is niet correct.');
					document.getElementById('captcha_code').value = '';
				}
			}
		});
	}
}

function nieuwsbrief_opslaan(){
	var url='/includes/opslaan_nieuwsbrief.php?tabel=nb_adressen';
	var avelden=new Array();
	var awaarden=new Array();
	if(!controle('nba_naam') || !controle('nba_email') || !controle('nba_via')){
		alert('U dient alle verplichte velden in te vullen.');
	}else{
		if(document.getElementById('nba_via').value=='Anders'){
			if(!controle('nba_via_anders')){
				alert('U dient alle verplichte velden in te vullen.');
			}else{
				new Ajax.Request('/includes/check_code.php?code='+document.getElementById('captcha_code').value, {
					method: 'get',
					onSuccess: function(transport) {
						if(transport.responseText=="OK"){
							do_opslaan(url,'nieuwsbrief');
						}else{
							document.getElementById('captcha').src = '/captcha/securimage_show.php?' + Math.random();
							alert('De beveiligingscode is niet correct.');
							document.getElementById('captcha_code').value = '';
						}
					}
				});
			}
		}else{
			new Ajax.Request('/includes/check_code.php?code='+document.getElementById('captcha_code').value, {
				method: 'get',
				onSuccess: function(transport) {
					if(transport.responseText=="OK"){
						do_opslaan(url,'nieuwsbrief');
					}else{
						document.getElementById('captcha').src = '/captcha/securimage_show.php?' + Math.random();
						alert('De beveiligingscode is niet correct.');
						document.getElementById('captcha_code').value = '';
					}
				}
			});
		}
	}
}

function do_opslaan(url,form_id){
	new Ajax.Request(url, {
		method: 'post',
		parameters: $(form_id).serialize(),
		onSuccess: function(transport) {
			message=transport.responseText.split('|');
			alert(message[0]);
			window.location=message[1];
			
/*			window.location=transport.responseText;*/
		}
	});

}

function controle(id){
	if((id.indexOf('Email')>0) || (id.indexOf('email')>0)){
		return emailCheck(document.getElementById(id).value);
	}else{
		if(document.getElementById(id).value != 'undefined' && document.getElementById(id).value != null){
			if(document.getElementById(id).value.length>0){
				return true;
			}
		}
	}
	return false;
}

function emailCheck (emailStr) {
/* Controleer het gebruiker@domein formaat en scheidt gebruiker van domein */
var emailPat=/^(.+)@(.+)$/
/* De volgende karakters zijn niet toegestaan ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* De volgende karakters zijn wel toegestaan in gebruikersnaam. */
var validChars="\[^\\s" + specialChars + "\]"
/* Controleer of gebruikersnaam tussen aanhalingstekens staat. */
var quotedUser="(\"[^\"]*\")"
/* Controle op IP-adressen ipv domeinnaam. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* Definitie van ATOM */
var atom=validChars + '+'
/* Woorden in gebruikersnaam */
var word="(" + atom + "|" + quotedUser + ")"
// Structuur van gebruikersnaam
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* Sturctuur van domeinnaam. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Het ingevulde e-mailadres is totaal ongeldig. */
  alert("Het ingevulde e-mailadres is onjuist.")
  return false
}
var user=matchArray[1]
var domain=matchArray[2]
// Is de gebruiker geldig?
if (user.match(userPat)==null) {
  // Gebruiker is niet geldig
  alert("De gebruikersnaam van het ingevulde e-mailadres is onjuist.")
  return false
}
/* In geval van IP-adres, controleer juistheid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // Het is een IP-adres
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Het IP-adres van het ingevulde e-mailadres is onjuist.")
		return false
	    }
    }
    return true
}
// Het is een domeinnaam
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("De domeinnaam van het ingevulde e-mailadres is onjuist.")
    return false
}
/* Extensiecontrole. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // Extensie bestaat niet uit 2 of 3 letters
   alert("De extensie van het ingevulde e-mailadres is onjuist.")
   return false
}
// Hostnaam voor domeinnaam?
if (len<2) {
   var errStr="De 'hostnaam' of 'extensie' van het ingevulde e-mailadres ontbreekt."
   alert(errStr)
   return false
}
// Alles klopt!
return true;
}
//  End -->

/*
 * jQuery Address Plugin v1.2
 * http://www.asual.com/jquery/address/
 *
 * Copyright (c) 2009-2010 Rostislav Hristov
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * Date: 2010-03-02 09:29:29 +0200 (Tue, 02 Mar 2010)
 */
(function ($) {

    $.address = (function () {

        var _trigger = function(name) {
	            $($.address).trigger(
	                $.extend($.Event(name), 
	                    (function() {
	                        var parameters = {},
	                            parameterNames = $.address.parameterNames();
	                        for (var i = 0, l = parameterNames.length; i < l; i++) {
	                            parameters[parameterNames[i]] = $.address.parameter(parameterNames[i]);
	                        }
	                        return {
	                            value: $.address.value(),
	                            path: $.address.path(),
	                            pathNames: $.address.pathNames(),
	                            parameterNames: parameterNames,
	                            parameters: parameters,
	                            queryString: $.address.queryString()
	                        };
	                    }).call($.address)
	                )
	            );
	        },
	        _bind = function(value, data, fn) {
	            if (fn || data) {
	                $($.address).bind(value, fn || data, fn && data);
	            }
	            return $.address;
	        },
	        _getHash = function() {
	            var index = _l.href.indexOf('#');
	            return index != -1 ? _ec(_dc(_l.href.substr(index + 1))) : '';
	        },
	        _getWindow = function() { 
	            try {
	                return top.document !== undefined ? top : window;
	            } catch (e) { 
	                return window;
	            }
	        },
	        _strictCheck = function(value, force) {
	            if (_opts.strict) {
	                value = force ? (value.substr(0, 1) != '/' ? '/' + value : value) : (value == '' ? '/' : value);
	            }
	            return value;
	        },
	        _ieLocal = function(value, direction) {
	            return (_msie && _l.protocol == 'file:') ? 
	                (direction ? _value.replace(/\?/, '%3F') : _value.replace(/%253F/, '?')) : value;
	        },
	        _searchScript = function(el) {
	        	var url, s;
	            for (var i = 0, l = el.childNodes.length; i < l; i++) {
	                if (el.childNodes[i].src) {
	                    url = String(el.childNodes[i].src);
	                }
	                s = _searchScript(el.childNodes[i]);
	                if (s) {
	                    url = s;
	                }
	            }
	            return url;
	        },
	        _listen = function() {
	            if (!_silent) {
	                var hash = _getHash(),
	                    diff = _value != hash;
	                if (_safari && _version < 523) {
	                    if (_length != _h.length) {
	                        _length = _h.length;
	                        if (typeof _stack[_length - 1] != UNDEFINED) {
	                            _value = _stack[_length - 1];
	                        }
	                        _update(FALSE);
	                    }
	                } else if (_msie && _version < 7 && diff) {
	                    _l.reload();
	                } else if (diff) {
	                    _value = hash;
	                    _update(FALSE);
	                }
	            }
	        },
	        _update = function(internal) {
	            _trigger('change');
	            _trigger(internal ? 'internalChange' : 'externalChange');
	            _st(_track, 10);
	        },
	        _track = function() {
	            var value = (_l.pathname + (/\/$/.test(_l.pathname) ? '' : '/') + $.address.value()).replace(/\/\//, '/').replace(/^\/$/, ''),
	                fn = window[_opts.tracker];
	            if (typeof fn == FUNCTION) {
	                fn(value);
	            } else if (typeof _gaq != UNDEFINED && typeof _gaq.push == FUNCTION) {
	                _gaq.push(['_trackPageview', value]);
	            } else if (typeof pageTracker != UNDEFINED && typeof pageTracker._trackPageview == FUNCTION) {
	                pageTracker._trackPageview(value);
	        	} else if (typeof urchinTracker == FUNCTION) {
	                urchinTracker(value);
    			}
    		},
	        _htmlWrite = function() {
	            var doc = _frame.contentWindow.document;
	            doc.open();
	            doc.write('<html><head><title>' + _d.title + '</title><script>var ' + ID + ' = "' + _getHash() + '";</' + 'script></head></html>');
	            doc.close();
	        },
	        _load = function() {
	            if (!_loaded) {
	                _loaded = TRUE;
	                if (_msie && _version < 8) {
	                    var frameset = _d.getElementsByTagName('frameset')[0];
	                    _frame = _d.createElement((frameset ? '' : 'i') + 'frame');
	                    if (frameset) {
	                        frameset.insertAdjacentElement('beforeEnd', _frame);
	                        frameset[frameset.cols ? 'cols' : 'rows'] += ',0';
	                        _frame.src = 'javascript:false';
	                        _frame.noResize = TRUE;
	                        _frame.frameBorder = _frame.frameSpacing = 0;
	                    } else {
	                        _frame.src = 'javascript:false';
	                        _frame.style.display = 'none';
	                        _d.body.insertAdjacentElement('afterBegin', _frame);
	                    }
	                    _st(function() {
	                        $(_frame).bind('load', function() {
	                            var win = _frame.contentWindow;
	                            var src = win.location.href;
	                            _value = (typeof win[ID] != UNDEFINED ? win[ID] : '');
	                            if (_value != _getHash()) {
	                                _update(FALSE);
	                                _l.hash = _ieLocal(_value, TRUE);
	                            }
	                        });
	                        if (typeof _frame.contentWindow[ID] == UNDEFINED) {
	                            _htmlWrite();
	                        }
	                    }, 50);
	                } else if (_safari) {
	                    if (_version < 418) {
	                        $(_d.body).append('<form id="' + ID + '" style="position:absolute;top:-9999px;" method="get"></form>');
	                        _form = _d.getElementById(ID);
	                    }
	                    if (typeof _l[ID] == UNDEFINED) {
	                    	_l[ID] = {};
	                    }
	                    if (typeof _l[ID][_l.pathname] != UNDEFINED) {
	                    	_stack = _l[ID][_l.pathname].split(',');
	                    }
	                }

	                _st(function() {
	                    _trigger('init');
	                    _update(FALSE);
	                }, 1);
	                
	                if ((_msie && _version > 7) || (!_msie && ('on' + HASH_CHANGE) in _t)) {
                        if (_t.addEventListener) {
                            _t.addEventListener(HASH_CHANGE, _listen, false);
                        } else if (_t.attachEvent) {
                            _t.attachEvent('on' + HASH_CHANGE, _listen);
                        }
	                } else {
	                    _si(_listen, 50);
	                }
	                $('a[rel*=address:]').address();
	            }
	        },
	        _unload = function() {
                if (_t.removeEventListener) {
                    _t.removeEventListener(HASH_CHANGE, _listen, false);
                } else if (_t.detachEvent) {
                    _t.detachEvent('on' + HASH_CHANGE, _listen);
                }
	        },
	        ID = 'jQueryAddress',
	        FUNCTION = 'function',
	        UNDEFINED = 'undefined',
	        HASH_CHANGE = 'hashchange',
	        TRUE = true,
	        FALSE = false,
	        _browser = $.browser, 
	        _version = parseFloat($.browser.version),
	        _mozilla = _browser.mozilla,
	        _msie = _browser.msie,
	        _opera = _browser.opera,
	        _safari = _browser.safari,
	        _supported = FALSE,
	        _t = _getWindow(),
	        _d = _t.document,
	        _h = _t.history, 
	        _l = _t.location,
	        _si = setInterval,
	        _st = setTimeout, 
	        _dc = decodeURI,
	        _ec = encodeURI,
	        _agent = navigator.userAgent,            
	        _frame,
	        _form,
	        _url = _searchScript(document),
	        _qi = _url ? _url.indexOf('?') : -1,
	        _title = _d.title, 
	        _length = _h.length, 
	        _silent = FALSE,
	        _loaded = FALSE,
	        _justset = TRUE,
	        _juststart = TRUE,
	        _updating = FALSE,
	        _stack = [], 
	        _listeners = {}, 
	        _value = _getHash(),
	        _api = {},
	        _opts = {autoUpdate: TRUE, history: TRUE, strict: TRUE};
	        
        if (_msie) {
            _version = parseFloat(_agent.substr(_agent.indexOf('MSIE') + 4));
            if (_d.documentMode && _d.documentMode != _version) {
                _version = _d.documentMode != 8 ? 7 : 8;
            }
        }
        
        _supported = 
            (_mozilla && _version >= 1) || 
            (_msie && _version >= 6) ||
            (_opera && _version >= 9.5) ||
            (_safari && _version >= 312);
            
        if (_supported) {
        
            for (var i = 1; i < _length; i++) {
                _stack.push('');
            }
            
            _stack.push(_getHash());
        
            if (_msie && _l.hash != _getHash()) {
                _l.hash = '#' + _ieLocal(_getHash(), TRUE);
            }
            
            if (_opera) {
                history.navigationMode = 'compatible'; 
            }
            
            if (_url && _qi != -1) {
                var param, params = _url.substr(_qi + 1).split('&');
                for (i = 0; i < params.length; i++) {
                    param = params[i].split('=');
                    if (/^(autoUpdate|history|strict)$/.test(param[0])) {
                        _opts[param[0]] = (isNaN(param[1]) ? /^(true|yes)$/i.test(param[1]) : (parseInt(param[1], 10) !== 0));
                    }
                    if (/^tracker$/.test(param[0])) {
                        _opts[param[0]] = param[1];
                    }
                }
            }
            
            if (document.readyState == 'complete') {
            	_load();
            }
            $(_load);
            $(window).bind('unload', _unload);
            
        } else if ((!_supported && _l.href.indexOf('#') != -1) || 
            (_safari && _version < 418 && _l.href.indexOf('#') != -1 && _l.search != '')) {
            _d.open();
            _d.write('<html><head><meta http-equiv="refresh" content="0;url=' + 
                _l.href.substr(0, _l.href.indexOf('#')) + '" /></head></html>');
            _d.close();
        } else {
            _track();
        }

        return {
            init: function(data, fn) {
                return _bind('init', data, fn);
            },
            change: function(data, fn) {
                return _bind('change', data, fn);
            },
            internalChange: function(data, fn) {
                return _bind('internalChange', data, fn);
            },
            externalChange: function(data, fn) {
                return _bind('externalChange', data, fn);
            },
            baseURL: function() {
                var url = _l.href;
                if (url.indexOf('#') != -1) {
                    url = url.substr(0, url.indexOf('#'));
                }
                if (url.substr(url.length - 1) == '/') {
                    url = url.substr(0, url.length - 1);
                }
                return url;
            },
            strict: function(value) {
                if (value !== undefined) {
                    _opts.strict = value;
                    return this;
                }
                return _opts.strict;
            },
            autoUpdate: function(value) {
                if (value !== undefined) {
                    _opts.autoUpdate = value;
                    return this;
                }
                return _opts.autoUpdate;
            },
            update: function() {
            	_updating = TRUE;
            	this.value(_value);
            	_updating = FALSE;
            	return this;
            },
            history: function(value) {
                if (value !== undefined) {
                    _opts.history = value;
                    return this;
                }
                return _opts.history;
            },
            tracker: function(value) {
                if (value !== undefined) {
                    _opts.tracker = value;
                    return this;
                }
                return _opts.tracker;
            },
            title: function(value) {
                if (value !== undefined) {
                    value = _dc(value);
                    _st(function() {
                        _title = _d.title = value;
                        if (_juststart && _frame && _frame.contentWindow && _frame.contentWindow.document) {
                            _frame.contentWindow.document.title = value;
                            _juststart = FALSE;
                        }
                        if (!_justset && _mozilla) {
                            _l.replace(_l.href.indexOf('#') != -1 ? _l.href : _l.href + '#');
                        }
                        _justset = FALSE;
                    }, 50);
                    return this;
                }
                return _d.title;
            },
            value: function(value) {
                if (value !== undefined) {
                    value = _ec(_dc(_strictCheck(value, TRUE)));
                    if (value == '/') {
                    	value = '';
                    }
                    if (_value == value && !_updating) {
                    	return;
                    }
                    _justset = TRUE;
                    _value = value;
                    if (_opts.autoUpdate || _updating) {
	                    _silent = TRUE;
	                    _update(TRUE);
	                    _stack[_h.length] = _value;
	                    if (_safari) {
	                        if (_opts.history) {
	                            _l[ID][_l.pathname] = _stack.toString();
	                            _length = _h.length + 1;
	                            if (_version < 418) {
	                                if (_l.search == '') {
	                                    _form.action = '#' + _value;
	                                    _form.submit();
	                                }
	                            } else if (_version < 523 || _value == '') {
	                                var evt = _d.createEvent('MouseEvents');
	                                evt.initEvent('click', TRUE, TRUE);
	                                var anchor = _d.createElement('a');
	                                anchor.href = '#' + _value;
	                                anchor.dispatchEvent(evt);                
	                            } else {
	                                _l.hash = '#' + _value;
	                            }
	                        } else {
	                            _l.replace('#' + _value);
	                        }
	                    } else if (_value != _getHash()) {
	                        if (_opts.history) {
	                            _l.hash = '#' + _ieLocal(_value, TRUE);
	                        } else {
	                            _l.replace('#' + _value);
	                        }
	                    }
	                    if ((_msie && _version < 8) && _opts.history) {
	                        _st(_htmlWrite, 50);
	                    }
	                    if (_safari) {
	                        _st(function(){ _silent = FALSE; }, 1);
	                    } else {
	                        _silent = FALSE;
	                    }
	                }
                    return this;
                }
                if (!_supported) {
                	return null;
                }
                return _dc(_strictCheck(_ieLocal(_value, FALSE), FALSE));
            },
            path: function(value) {
                if (value !== undefined) {
                    var qs = this.queryString();
                    this.value(value + (qs ? '?' + qs : ''));
                    return this;
                }
                value = this.value();
                return (value.indexOf('?') != -1) ? value.split('?')[0] : value;
            },
            queryString: function(value) {
                if (value !== undefined) {
                    this.value(this.path() + (value ? '?' + value : ''));
                    return this;
                }
                value = this.value();
                var index = value.indexOf('?');
                if (index != -1 && index < value.length) {
                    return value.substr(index + 1);
                }
            },
            parameter: function(name, value, append) {
            	var i, params;
                if (value !== undefined) {
                    var names = this.parameterNames();
                    params = [];
                    for (i = 0; i < names.length; i++) {
                        var n = names[i],
                            v = this.parameter(n);
                        if (typeof v == 'string') {
                            v = [v];
                        }
                        if (n == name) {
                            v = (value === null || value == '') ? [] : 
                                (append ? v.concat([value]) : [value]);
                        }
                        for (var j = 0; j < v.length; j++) {
                            params.push(n + '=' + v[j]);
                        }
                    }
                    if ($.inArray(name, names) == -1) {
                        params.push(name + '=' + value);
                    }
                    this.queryString(params.join('&'));
                    return this;
                }
                value = this.value();
                var index = value.indexOf('?');
                if (index != -1) {
                    value = value.substr(index + 1);
                    params = value.split('&');
                    var r = [];
                    for (i = 0; i < params.length; i++) {
                        var p = params[i].split('=');
                        if (p[0] == name) {
                            r.push(p[1]);
                        }
                    }
                    if (r.length !== 0) {
                        return r.length != 1 ? r : r[0];
                    }
                }
            },
            pathNames: function() {
                var path = this.path(),
                    names = path.split('/');
                if (path.substr(0, 1) == '/' || path.length === 0) {
                    names.splice(0, 1);
                }
                if (path.substr(path.length - 1, 1) == '/') {
                    names.splice(names.length - 1, 1);
                }
                return names;
            },
            parameterNames: function() {
                var value = this.value(),
                    index = value.indexOf('?'),
                    names = [];
                if (index != -1) {
                    value = value.substr(index + 1);
                    if (value != '' && value.indexOf('=') != -1) {
                        var params = value.split('&');
                        for (var i = 0; i < params.length; i++) {
                            var name = params[i].split('=')[0];
                            if ($.inArray(name, names) == -1) {
                                names.push(name);
                            }
                        }
                    }
                }
                return names;
            }
        };
        
    })();
    
    $.fn.address = function (fn) {
    	var f = function() {
            var value = fn ? fn.call(this) : 
                /address:/.test($(this).attr('rel')) ? $(this).attr('rel').split('address:')[1].split(' ')[0] : 
                $(this).attr('href').replace(/^#/, '');
            $.address.value(value);
            return false;
        };
        $(this).click(f).live('click', f);
    };
    
}(jQuery));

