
function CBrowserInfo(){}

CBrowserInfo.compareLangPref = function CBrowserInfo_compareLangPref( sLang1, sLang2 ){
  	var asLang1 = sLang1.split( ';' );
  	var asLang2 = sLang2.split( ';' );
  	return ( !asLang1[ 1 ] )? 1: ( !asLang2[ 1 ] )? -1:
  	 ( ( asLang1[ 1 ].split( '=' )[ 1 ] - 0 ) - ( asLang2[ 1 ].split( '=' )[ 1 ] - 0 ) );
};

CBrowserInfo.prototype.getLangPref = function CBrowserInfo_getLangPref(){
	if( this.sLangPref )
		return this.sLangPref;

	var asAvailableLang = [ 'en', 'ja' ];

	if( !( sAcceptLang = 'en-us,en;q=0.5' ) )
		return this.sLangPref = 'en';

	var asLangs = sAcceptLang.replace( / /g, '' ).split( ',' );
	asLangs.sort( CBrowserInfo.compareLangPref );

	for( var i = asLangs.length - 1; i >= 0; i-- ){
		for( var sLang = asLangs[ i ].split( ';' )[ 0 ].split( '-' )[ 0 ], j = 0; j < asAvailableLang.length; j++ ){
			if( asAvailableLang[ j ] == sLang )
				return this.sLangPref = sLang;
		}
	}

	return this.sLangPref = 'en';
};

CBrowserInfo.prototype.setLangPref = function CBrowserInfo_setLangPref( sLang ){ return this.sLangPref = sLang; };

CBrowserInfo.prototype.hasXMLHttp = function CBrowserInfo_hasXMLHttp(){
	return this.isGecko() && !this.isSafari() && window.XMLHttpRequest && !!( ( new XMLHttpRequest ).send );
};

CBrowserInfo.prototype.needXMLProxy = function CBrowserInfo_needXMLProxy(){
	if( typeof( this.fNeedXMLProxy ) != 'undefined' )
		return this.fNeedXMLProxy;

	if( this.hasXMLHttp() )
		return this.fNeedProxy = false;

	var oXml = ( !this.isSafari() )? document.createElement( 'XML' ): {};
	return CCommonRes.fNeedProxy = typeof( oXml.load ) == 'undefined';
};

CBrowserInfo.prototype.getRealVersion = function CBrowserInfo_getRealVersion(){
	var asTokens = ( this.isGecko() && !this.isSafari() )? navigator.userAgent.match( /rv:([0-9\.]+)/ ):
	 ( this.isIE() )? navigator.userAgent.match( /MSIE ([0-9\.]+)/ ):
	 void 0;
	var sVer = ( asTokens && asTokens[ 1 ] )? asTokens[ 1 ]: void 0;

	if( sVer && this.isIE() ){
		var asVers = sVer.split( '.' );
		for( var i = 1; i < asVers.length; i++ ){
			var s = asVers[ i ].substr( 0, 1 );
			for( var j = 1; j < asVers.length; j++ ){
				s += '.' + asVers[ i ].substr( j, 1 );
			}
			asVers[ i ] = s;
		}
		sVer = asVers.join( '.' );
	}

	return sVer;
};

CBrowserInfo.prototype.isSupported = function CBrowserInfo_isSupported(){
	return ( this.isGecko() && this.compareVer( '1.0.1' ) >= 0 ) || ( this.isIE() && this.compareVer( '5.0' ) >= 0 ) || this.isSafari();
};

CBrowserInfo.prototype.isBuggy = function CBrowserInfo_isBuggy(){
	return this.isIE() && this.isMac() && this.compareVer( '5.0' ) >= 0;
};

CBrowserInfo.prototype.isMac = function CBrowserInfo_isMac(){ return !!navigator.platform.match( /^Mac/ ); };
CBrowserInfo.prototype.isGecko = function CBrowserInfo_isGecko(){ return navigator.product == 'Gecko'; };
CBrowserInfo.prototype.isSafari = function CBrowserInfo_isSafari(){ return !!navigator.userAgent.match( /Safari/ ); };
CBrowserInfo.prototype.isOpera = function CBrowserInfo_isOpera(){ return !!navigator.userAgent.match( /Opera/ ); };

CBrowserInfo.prototype.isChimera = function CBrowserinfo_isChimera(){
	return navigator.vendor == 'Chimera' || navigator.vendor == 'Camino';
};

CBrowserInfo.prototype.isIE = function CBrowserInfo_isIE(){
	return navigator.appName == 'Microsoft Internet Explorer' && !this.isOpera();
};

CBrowserInfo.prototype.compareVer = function CBrowserInfo_compareVer( sVerSrc ){
	var sVerDst = this.getRealVersion();

	if( !sVerDst )
		return -1;

	var asVersDst = sVerDst.split( '.' );
	var asVersSrc = sVerSrc.split( '.' );

	for( var i = 0; typeof( asVersDst[ i ] ) != 'undefined' || typeof( asVersSrc[ i ] ) != 'undefined'; i++ ){
		if( typeof( asVersSrc[ i ] ) == 'undefined' )
			return 1;
		if( typeof( asVersDst[ i ] ) == 'undefined' )
			return -1;
		var nVerDst = asVersDst[ i ] - 0;
		var nVerSrc = asVersSrc[ i ] - 0;
		if( nVerDst > nVerSrc )
			return 1;
		if( nVerDst < nVerSrc )
			return -1;
	}

	return 0;		
};

function SP(){}

SP.oWin = window;
SP.oDoc = window.document;
SP.oBrowserInfo = new CBrowserInfo;

SP.shared = function SP_shared(){};

SP.shared.unescape = function SP_shared_unescape( s ){
	return s.replace( /%0A/gi, '\n' ).replace( /%27/g, '\'' );
};

SP.shared.openWindow = function SP_shared_openWindow( sUrl, sName, nWidth, nHeight ){
	var sFullScreenAttr = ( !nWidth && !nHeight )? 'fullscreen=yes,titlebar=no': '';

	nWidth = ( !nWidth )? screen.width: nWidth;
	nHeight = ( !nHeight )? screen.height: nHeight;

	var sAttr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,sidebar=no,resizable=no,copyhistory=yes'
	 + ',width=' + nWidth + ',height=' + nHeight + ( ( sFullScreenAttr )? ',': '' ) + sFullScreenAttr;
	var oWin = SP.oWin.open( sUrl + '&width=' + nWidth + '&height=' + nHeight, sName, sAttr );

	oWin.moveTo( 0, 0 );
	oWin.focus();
};

SP.shared.getWinInnerWidth = function SP_shared_getWinInnerWidth(){
	return ( SP.oWin.innerWidth )? SP.oWin.innerWidth: SP.oDoc.body.clientWidth;
};

SP.shared.getWinInnerHeight = function SP_shared_getWinInnerHeight(){
	return ( SP.oWin.innerHeight )? SP.oWin.innerHeight: SP.oDoc.body.clientHeight;
};

if( !SP.oBrowserInfo.isSupported() ){
	alert( 'Sorry, you\'re using a browser which is not supported by streetphoto.jp.\n'
	 + '(The browser is: ' + navigator.userAgent + ')\n'
	 + 'streetphoto.jp intensively uses Dynamic HTML. (DHTML)'
	 + ' streetphoto.jp puts much effort for the contents to be standard-based,'
	 + ' so this site will best be seen using browsers having good DHTML standard support,'
	 + ' such as IE 5.5 or later, Netscape 7.01 or later or Mozilla 1.01 or later.\n'
	 + 'Thank you for your understanding and hope you come back to this site soon. :)' );
}
