var browser			 = new BrowserDetectLite();
var selected_pano	 = '';
var selected_webcam	 = '';
var liste_vues_XML;
var spots_panos_arr		 = new Array();
var spots_webcams_arr	 = new Array();


var img_topreload_arr	 = ['/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/picto_webcam_on.png',
							'/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/picto_pano_on.png',
							'/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/liste_fond_btn.png',
							'/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/liste_fond_btn_on.png',
							'/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/liste_fond_btn_selected.png'];
var img_preload_arr		 = new Array();

function preload_imgs() {
	for (var i=0; i<img_topreload_arr.length; i++) {
		img_preload_arr[i]		 = new Image();
		img_preload_arr[i].src	 = img_topreload_arr[i];
	}
}


/***** voir la carte du type ******/
function voir(type_on) {
	var type_off	 = (type_on=='webcam'?'pano':'webcam');
	var ie = '';
	if ((browser.isIE55 || browser.isIE6x) && browser.isWin32)
		ie = '_ie';
	// visu
	document.getElementById('encart_'+type_off).style.display	 = 'none';
	// carte
	document.getElementById('pictos_'+type_off+'s').style.display	 = 'none';
	// liste
	document.getElementById('liste_'+type_off+'s'+ie).style.display		 = 'none';
	// affichage
	document.getElementById('encart_'+type_on).style.display	 = 'block';
	document.getElementById('pictos_'+type_on+'s').style.display	 = 'block';
	document.getElementById('liste_'+type_on+'s'+ie).style.display		 = 'block';
}

function selectionner(type, id, ffm) {
	// deselection de la vue courante
	if ((browser.isIE55 || browser.isIE6x) && browser.isWin32) {
		var typejs	 = (typeof(type)=='undefined'?this.type:type);
		var idjs	 = (typeof(id)=='undefined'?this.idjs:id);
		var ffm		 = (typeof(ffm)=='undefined'?this.ffm:ffm);
		var selected = eval('selected_'+typejs);
		if ( selected != idjs && selected != '' ) {
			var picto	 = document.all['picto_'+typejs+'_'+selected+'_swf'];
				picto.setVariable('roll', 'out');
			if ( typejs=='pano' ) {
				document.getElementById('label_'+typejs+'_'+selected).style.background	 = '';
			} else {
				document.getElementById('label_'+typejs+'_'+selected).style.background	= 'url(/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/liste_fond_btn.png) no-repeat';
			}
		}
	} else {
		var selected = eval('selected_'+type);
		if ( selected != id && selected != '' ) {
			document.getElementById('img_'+type+'_'+selected).src			 = '/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/picto_'+type+'.png';
			document.getElementById('label_'+type+'_'+selected).className	 = 'label';
		}
	}

	if ( type=='webcam' ) {
		if ( typeof(id)!='undefined' )
			selected_webcam	 = id;
		else
			selected_webcam	 = idjs;
		// vider la liste deroulante
		var dates = document.getElementById('date');
		for ( var i=dates.options.length-1; i>=0; i-- )
			dates.options[i] = null;
		if (ffm=='xml')
			var ok = lire_fichier_video_xml();
		else
			var ok = lire_fichier_video();
		//alert(ok);
		//lire_fichier_meteo();
		if ( ok=='' )
			if (ffm=='xml')
				selectChange_xml();
			else
				selectChange();
		//chargerDonnees();
		//Load();
	} else {
		if ( typeof(id)!='undefined' )
			selected_pano	 = id;
		else
			selected_pano	 = idjs;
		afficher(type, id);
	}
}

/***** ajouter une vue sur la carte *******/
function placer(type, id, x, y, ffm) {
	var a			 = document.createElement('a');
		a.href 			 = "javascript:selectionner('"+type+"', "+id+", '"+ffm+"');";
		a.id			 = "picto_"+type+"_"+id;
		a.ffm			 = ffm;
	var img		 	 = document.createElement('img');
		img.id			 = "img_"+type+"_"+id;
		img.border		 = "0";
	if ((browser.isIE55 || browser.isIE6x) && browser.isWin32)
	{
		var swf_w	 = (type=='pano'?47:35);
		var swf_h	 = (type=='pano'?47:29);
		var div		 	 = document.createElement('div');
			div.id				 = "picto_ie_"+type+"_"+id;
			div.className		 = "picto";
			div.style.left		 = x+'px';
			div.style.top		 = y+'px';
			div.style.zIndex	 = 100+id;
		var html	 = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" id="picto_'+type+'_'+id+'_swf" align="middle" width="'+swf_w+'" height="'+swf_h+'">';
			html	+= '	<param name="allowScriptAccess" value="sameDomain" />';
			html	+= '	<param name="movie" value="/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/flash/picto_'+type+'.swf" />';
			html	+= '	<param name="quality" value="high" />';
			html	+= '	<param name="salign" value="t" />';
			html	+= '	<param name="wmode" value="transparent" />';
			html	+= '	<param name="flashVars" value="type='+type+'&id='+id+'" />';
			html	+= '	<embed';
			html	+= '			src="/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/flash/picto_'+type+'.swf"';
			html	+= '			width="'+swf_w+'" height="'+swf_h+'"';
			html	+= '			flashvars="type='+type+'&id='+id+'"';
			html	+= '			align="middle"';
			html	+= '			quality="high"';
			html	+= '			salign="t"';
			html	+= '			wmode="transparent"';
			html	+= '			type="application/x-shockwave-flash"';
			html	+= '			pluginspage="http://www.macromedia.com/go/getflashplayer"';
			html	+= '			name="picto_'+type+'_'+id+'_swf" /></embed>';
			html	+= '</object>';
		div.innerHTML	 = html;
		document.getElementById("pictos_"+type+"s").appendChild(div);
	} else {
		if ( browser.isIE6up && browser.isWin32 ) {
			a.idjs			 = id;
			a.onmouseover	 = function () { rollover(type, id) };
			a.onmouseout	 = function () { rollout(type, id) };
		} else {
			a.setAttribute('onMouseOver', "rollover('"+type+"', "+id+");");
			a.setAttribute('onMouseOut', "rollout('"+type+"', "+id+");");
		}
		a.className		 = "picto";
		a.style.left	 = x+'px';
		a.style.top		 = y+'px';
		a.style.zIndex	 = 100+id;
		img.src			 = "/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/picto_"+type+".png";
		a.appendChild(img);
		document.getElementById("pictos_"+type+"s").appendChild(a);
	}
}

/******* ajouter une vue dans la liste *******/
function ajouter_label(colonne, type, id, label, ffm) {
	var ie = '';

	/*
	var img		 	 = document.createElement('div');
		img.style.float	 = 'left';
		img.style.width	 = '10px';
	var puce		 	 = document.createElement('img');
		puce.border		 = "0";
		puce.src		 = "images/puce.png";
	img.appendChild(puce);
	*/
	var lbl			 = document.createElement('div');
	var nb_crlf	 	 = 0;
	if ( label.indexOf('\\n') ) {
		var label_arr	 = label.split(/\\n/);
		lbl.appendChild(document.createTextNode(label_arr[0]));
		nb_crlf	 = label_arr.length-1;
		for (var i=1; i<label_arr.length; i++) {
			lbl.appendChild(document.createElement('br'));
			lbl.appendChild(document.createTextNode(label_arr[i]));
		} // fin for
		
	} else {
		lbl.appendChild(document.createTextNode(label));
	} // fin label

	// si plusieurs lignes dans label
	if ( nb_crlf>0 )
		lbl.style.marginTop	 = '-7px';

	var a			 = document.createElement('a');
		a.href 			 = "javascript:selectionner('"+type+"', "+id+", '"+ffm+"');";
		a.style.paddingLeft	 = '10px';
		a.style.display		 = 'block';

	if ((browser.isIE55 || browser.isIE6x) && browser.isWin32) {
		ie = '_ie';
		var liste_panos_ie	 = document.getElementById('liste_panos_ie');
		var liste_panos		 = document.getElementById('liste_panos');
		if ( liste_panos_ie.style.display == 'none' ) {
			liste_panos.style.display		 = 'none';
			liste_panos_ie.style.display	 = 'block';
		}


		var puce_ie			 = document.createElement('img');
			puce_ie.src		 = 'images/puce_ie.png';
			puce_ie.width	 = 4;
			puce_ie.height	 = 7;
			puce_ie.border	 = 0;
		a.type			 = type;
			a.idjs			 = id;
			a.onmouseover	 = function () { rollover(type, id) };
			a.onmouseout	 = function () { rollout(type, id) };
			a.style.background	 = 'url(images/puce_ie.png) left center no-repeat';
		//a.appendChild(puce_ie);
	} else {
		if ( browser.isIE6up && browser.isWin32 ) {
			a.idjs			 = id;
			a.onmouseover	 = function () { rollover(type, id) };
			a.onmouseout	 = function () { rollout(type, id) };
		} else {
			a.setAttribute('onMouseOver', "rollover('"+type+"', "+id+");");
			a.setAttribute('onMouseOut', "rollout('"+type+"', "+id+");");
		}
		a.style.background	 = 'url(/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/puce.png) left center no-repeat';
		//a.appendChild(img);
	}
	a.appendChild(lbl);

	var div		 	 = document.createElement('div');
	div.id			 = "label_"+type+"_"+id;
	div.className	 = "label";
	div.appendChild(a);

	document.getElementById(colonne+ie).appendChild(div);
}

/******* survol picto ou label ********/
function rollover(type, id) {
	if ((browser.isIE55 || browser.isIE6x) && browser.isWin32) {
		var typejs	 = (typeof(type)=='undefined'?this.type:type);
		var idjs	 = (typeof(id)=='undefined'?this.idjs:id);
		// allumer le picto
		var picto	 = document.all['picto_'+typejs+'_'+idjs+'_swf'];
		if (typeof(type)=='undefined')
			picto.setVariable('roll', 'over');
		// allumer le label
		if ( typejs=='pano' )
			document.getElementById('label_'+typejs+'_'+idjs).style.background	= '#6bd325';
		else
			document.getElementById('label_'+typejs+'_'+idjs).style.background	= 'url(/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/liste_fond_btn_on.png) no-repeat';
	} else {
		document.getElementById('img_'+type+'_'+id).src			 = '/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/picto_'+type+'_on.png';
		document.getElementById('label_'+type+'_'+id).className	 = 'label_on';
	}
}

function rollout(type, id) {
	if ((browser.isIE55 || browser.isIE6x) && browser.isWin32) {
		// IE
		var typejs	 = (typeof(type)=='undefined'?this.type:type);
		var idjs	 = (typeof(id)=='undefined'?this.idjs:id);
		var selected = eval('selected_'+typejs);
		// eteindre le label
		if ( selected != idjs ) {	// cas de la vue courante
			if ( typejs=='pano' )
				document.getElementById('label_'+typejs+'_'+idjs).style.background	 = '';
			else
				document.getElementById('label_'+typejs+'_'+idjs).style.background	= 'url(/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/liste_fond_btn.png) no-repeat';
			// eteindre le picto
			var picto	 = document.all['picto_'+typejs+'_'+idjs+'_swf'];
			if (typeof(type)=='undefined')
				picto.setVariable('roll', 'out');
		} else {
			if ( typejs=='pano' )
				document.getElementById('label_'+typejs+'_'+idjs).style.background	 = '#e1b839';
			else
				document.getElementById('label_'+typejs+'_'+idjs).style.background	= 'url(images/liste_fond_btn_selected.png) no-repeat';
			// eteindre le picto
			var picto	 = document.all['picto_'+typejs+'_'+idjs+'_swf'];
			if (typeof(type)=='undefined')
				picto.setVariable('roll', 'over');
		}
	} else {
		// ! IE
		var selected = eval('selected_'+type);
		if ( selected != id ) {	// cas de la vue courante
			document.getElementById('img_'+type+'_'+id).src			 = '/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/picto_'+type+'.png';
			document.getElementById('label_'+type+'_'+id).className	 = 'label';
		} else {
			document.getElementById('label_'+type+'_'+id).className	 = 'label_selected';
			document.getElementById('img_'+type+'_'+id).src			 = '/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/picto_'+type+'_on.png';
		}
	}
}

/****** selection d'une vue *******/
function afficher (type, id) {
	var html	 = '';

	if  (type=='webcam') {
		selected = id;
		selected_webcam = id;
		//alert(spots_webcams_arr[id]+'/'+last);
		html = '<applet code="com.fluendo.player.Cortado.class" codebase="http://www.ile-oleron-marennes.com/fileadmin/scripts/pmo_tourisme/bonnes_adresses/webcam/applet/" archive="cortado-vs-0.1.2-3.jar" width="320" height="240"><param name="url" value="http://www.ile-oleron-marennes.com/fileadmin/scripts/pmo_tourisme/webcam/'+spots_webcams_arr[id]+'/'+last+'.ogg" /><param name="debug" value="0" /><param name="loopPause" value="0" /><param name="logo" value="false" /><param name="loadscreen" value="false" /></applet>';

	} else {
		selected = id;
		selected_pano = id;
	
		html	 = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="440" height="304" align="middle" id="pano_swf">';
		html	+= '	<param name="allowScriptAccess" value="sameDomain" />';
		html	+= '	<param name="movie" value="/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/panoramiques/flash/PMOVuePanoramiqueSansSons.swf" />';
		html	+= '	<param name="quality" value="high" />';
		html	+= '	<param name="salign" value="t" />';
		html	+= '	<param name="wmode" value="transparent" />';
		html	+= '	<param name="flashVars" value="fichierXML=/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/panoramiques/pano_xml/'+spots_panos_arr[id]+'" />';
		html	+= '	<embed';
		html	+= '			src="/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/panoramiques/flash/PMOVuePanoramiqueSansSons.swf"';
		html	+= '			width="440" height="304"';
		html	+= '			align="middle"';
		html	+= '			quality="high"';
		html	+= '			salign="t"';
		html	+= '			wmode="transparent"';
		html	+= '			flashVars="fichierXML=/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/panoramiques/pano_xml/'+spots_panos_arr[id]+'" allowscriptaccess="sameDomain"';
		html	+= '			type="application/x-shockwave-flash"';
		html	+= '			pluginspage="http://www.macromedia.com/go/getflashplayer"';
		html	+= '			name="pano_swf" /></embed>';
		html	+= '</object>';
	}

	document.getElementById('vue_'+type).innerHTML				 = html;

	// selection de la vue
	if ((browser.isIE55 || browser.isIE6x) && browser.isWin32) {
		if ( type=='pano' )
			document.getElementById('label_'+type+'_'+id).style.background	= '#e1b839';
		else
			document.getElementById('label_'+type+'_'+id).style.background	= 'url(/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/liste_fond_btn_selected.png) no-repeat';
	} else {
		document.getElementById('label_'+type+'_'+id).className	 = 'label_selected';
		document.getElementById('img_'+type+'_'+id).src			 = '/fileadmin/scripts/pmo_tourisme/bonnes_adresses/carte_pano_webcam/images/picto_'+type+'_on.png';
	}

	//document.getElementById('attente').style.display	 = 'none';
}





/*****************************************
*********** charger vues xml *************
******************************************/
function getXMLHttpRequest() {
	try { // Firefox
		return new XMLHttpRequest();
		//alert("Firefox");
	} catch (e) { // Internet Explorer
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
			//alert("Internet Explorer");
		} catch (e) {
			alert('Your browser can\'t handle this script');
			return false;
		}
	}
}

function charger_vues(fichierXML) {
	liste_vues_XML = getXMLHttpRequest();
	if (liste_vues_XML) {
		liste_vues_XML.onreadystatechange = traitementXML;
		liste_vues_XML.open('GET', fichierXML, true);
		liste_vues_XML.send(null);
		//document.getElementById('attente').style.display	 = 'block';
	}
}
function traitementXML() {
	if (liste_vues_XML.readyState == 4) {
		if (liste_vues_XML.status == 200) {
			var xmldoc	 = liste_vues_XML.responseXML;
			var root	 = xmldoc.getElementsByTagName('spots')[0];
			var nodes	 = xmldoc.getElementsByTagName('spot');
			for ( var i=0, nb_panos=0; i<nodes.length; i++)
				if (nodes[i].getAttribute('type') == 'pano')
					nb_panos++
			for ( var i=0, nb_webcams=0; i<nodes.length; i++)
				if (nodes[i].getAttribute('type') == 'webcam')
					nb_webcams++
			var lignes_pano_max		 = Math.ceil(nb_panos/2);
			var lignes_webcam_max	 = Math.ceil(nb_webcams/2);
			var txt = '';
			var first_pano		 = 0;
			var first_webcam	 = 0;
			for (var iNode = 0; iNode < nodes.length; iNode++) {
				var node	 = nodes[iNode];//root.childNodes[iNode];
				var type	 = node.getAttribute('type');
				var colonne	 = (type=='webcam'?
									'liste_webcams_contenu'
									: (iNode<lignes_pano_max ? 'liste_colonne_gauche' : 'liste_colonne_droite'));
				var id		 = parseInt(node.getAttribute('idjs'));
				var ffm		 = (node.getAttribute('ffm'));
				var x		 = parseInt(node.getAttribute('x'));
				var y		 = parseInt(node.getAttribute('y'));
				var label	 = node.getAttribute('label');
				var vues	 = node.getAttribute('vues');

				txt += '['+node+'] '+type+' '+id+' : '+label+" "+vues+"\n";

				if ( type == 'pano' ) {
					spots_panos_arr[id]		 = vues;
					// pour selection par defaut
					if ( first_webcam==0 )
						first_webcam	 = id;
				} else {
					spots_webcams_arr[id]	 = vues;
					// pour selection par defaut
					if ( first_pano==0 )
						first_pano		 = id;
				}
				placer(type, id, x, y, ffm);
				ajouter_label(colonne, type, id, label, ffm);
			} // fin for
			//document.getElementById('attente').style.display	 = 'none';
			//alert(txt);
			// chargement d'une vue par défaut
			selected_pano	 = (pano_defaut?pano_defaut:first_pano);
			selectionner('pano', selected_pano);
			selected_webcam	 = (webcam_defaut?webcam_defaut:first_webcam);
			selectionner('webcam', selected_webcam);
			if ( type_defaut )
				voir(type_defaut);
		} else {
			alert('Problème avec la requête.');
		} // fin if status
	} // fin if ready
}





/********** popup ***********/
function popup_centree(page,largeur,hauteur,options) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  return window.open(page,"popup","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}


function popup_envoyer_ami(quoi, id_produit) {
	// centrer la popup
	var largeur = 400;
	var hauteur = 125;
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	var popup = window.open('/envoyer_ami.php?quoi='+quoi+'&id_produit='+id_produit, 'popup', 'top='+top+',left='+left+',width='+largeur+', height='+hauteur);
}




/**
 *   Array convenience method to check for membership.
 *
 *   @param object element
 *   @returns boolean
 */
Array.prototype.in_array = function (element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            return true;
        }
    }
    return false;
};
/**
 *   Array convenience method to remove duplicates.
 *
 */
Array.prototype.sort_distinct = function () {
	this.sort();
	var idx = 1;
    for (var i=1; i<this.length; i++) {
		if (this[idx-1]!=this[i]) {
			this[idx++] = this[i];
		}
    }
	while (idx<this.length)
		this.pop();
};
/**
 *	String pad
 *	dir : 'right', 'left'
 */
String.prototype.pad = function (str, len, dir) {
	if (this.length<len) {
		var orig_len = this.length;
		var diff_len = len-orig_len;

		if (str.length==0) str = ' ';
		// decalage à droite
		if ( dir.toLowerCase()=='left' )
			for (k=len; k>diff_len; k--)
				this[k] = this[k-diff_len];
		// boucle
		i = 0;
		while ( i<diff_len ) {
			j = 0;
			while ( j<str.length && i<diff_len ) {
				switch ( dir.toLowerCase() ) {
					case 'right' :
						this[this.length] = str[j];
						break;
					case 'left' :
						this[i] = str[j];
						break;
				} // fin switch
				j++;
				i++;
			} // fin while str.length
		} // fin while this.length
	} // fin if
};


// Browser Detect Lite  v2.1
// http://www.dithered.com/javascript/browser_detect/index.html
// modified by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
//
// modified by Michael Lovitt to include OmniWeb and Dreamcast

function BrowserDetectLite() {
	var ua = navigator.userAgent.toLowerCase(); 
	this.ua = ua;

	// browser name
	this.isGecko     = (ua.indexOf('gecko') != -1);
	this.isMozilla   = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length);
	this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
	this.isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
	this.isOpera     = (ua.indexOf("opera") != -1); 
	this.isKonqueror = (ua.indexOf("konqueror") != -1); 
	this.isIcab      = (ua.indexOf("icab") != -1); 
	this.isAol       = (ua.indexOf("aol") != -1); 
	this.isWebtv     = (ua.indexOf("webtv") != -1); 
	this.isOmniweb   = (ua.indexOf("omniweb") != -1);
	this.isDreamcast   = (ua.indexOf("dreamcast") != -1);
	
	// spoofing and compatible browsers
	this.isIECompatible = ( (ua.indexOf("msie") != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);
	
	// browser version
	this.versionMinor = parseFloat(navigator.appVersion); 
	
	// correct version number for NS6+ 
	if (this.isNS && this.isGecko) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}
	
	// correct version number for IE4+ 
	else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	
	// correct version number for Opera 
	else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
		}
	}
	
	// correct version number for Konqueror
	else if (this.isKonqueror) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
	}
	
	// correct version number for iCab 
	else if (this.isIcab) {
		if (ua.indexOf('icab/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
		}
	}
	
	// correct version number for WebTV
	else if (this.isWebtv) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('webtv/') + 6 ) );
	}
	
	this.versionMajor = parseInt(this.versionMinor); 
	this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
	
	// platform
	this.isWin   = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1) );
	this.isMac   = (ua.indexOf('mac') != -1);
	this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('linux') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
	
	// specific browser shortcuts
	this.isNS4x = (this.isNS && this.versionMajor == 4);
	this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
	this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
	this.isNS4up = (this.isNS && this.versionMinor >= 4);
	this.isNS6x = (this.isNS && this.versionMajor == 6);
	this.isNS6up = (this.isNS && this.versionMajor >= 6);
	
	this.isIE4x = (this.isIE && this.versionMajor == 4);
	this.isIE4up = (this.isIE && this.versionMajor >= 4);
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x = (this.isIE && this.versionMajor == 6);
	this.isIE6up = (this.isIE && this.versionMajor >= 6);
	
	this.isIE4xMac = (this.isIE4x && this.isMac);
}

