/*
// 2005-03-02
// Copyright (c) Art. Lebedev | http://www.artlebedev.ru/
// Author - Vladimir Tokmakov
*/

function cmnInformation(){
	this.sUser_agent = navigator.userAgent.toLowerCase()
	this.bIE       = ( ( this.sUser_agent.indexOf("msie") != -1 ) && ( this.sUser_agent.indexOf("opera") == -1 ) )
	this.bOpera    = ( this.sUser_agent.indexOf("opera") != -1 )
	this.bMAC      = ( this.sUser_agent.indexOf("mac") != -1 )
	this.bGecko    = ( navigator.product == "Gecko" )
	this.bMozilla  = this.bGecko
	this.sLanguage = null
	this.bHTTP = null
	return this
}

var cmn_oInformation = new cmnInformation()

function cmnInit_Information(){
	cmn_oInformation.sLanguage = ( document.body.getAttribute( "lang" ) != "" ) ? document.body.getAttribute( "lang" ) : "ru"
	cmn_oInformation.bHTTP = ( document.location.href.indexOf("http://") == 0 ) ? true : false
}

cmnAdd_event( window, "load", cmnInit_Information )

function cmnFlash(){
	var aeFlash = new Array()
	this.build = function( vEnabled, vDisabled, vNone, iVersion  ){
		var vVersion = this.get_version( iVersion )
		if( vVersion ){
			if( vEnabled.nodeType )	vEnabled.style.display = "block"
			else document.write( build_object(vEnabled) )
			if( vDisabled.nodeType ) vDisabled.style.display = "none"
			if( vNone.nodeType ) vNone.style.display = "none"
		}else{
			if( vEnabled.nodeType ) vEnabled.style.display = "none"
			if( vDisabled.nodeType ) vDisabled.style.display = "block"
			else if( vDisabled ) document.write( vDisabled )
			if( parseInt(vVersion) == 0 )
				if( vNone.nodeType ) vNone.style.display = "block"
				else if( vNone ) document.write( vNone )
		}
	}
	this.get_version = function( iVersion ){
		var vVersion = cmnGet_cookie( "flash" )
		if( !vVersion ){
			vVersion = check_flash_version( iVersion )
			set_flash_cookie( vVersion )
			return vVersion
		}else if( iVersion && iVersion > vVersion ){
			vVersion = false
		}
		return ( vVersion == "false" ) ?  false : vVersion
	}
	this.disable = function(){
		set_flash_disabled( true )
	}
	this.enable = function(){
		set_flash_disabled( false )
	}
	this.set_disabled = function( bDisabled ){
		set_flash_disabled( bDisabled )
	}

	return this

	function build_object( sOptions ){
		var asOptions = sOptions.split( "," )
		for( var i = 0 ; i < asOptions.length ; i++){
			asPair = asOptions[i].split( "=" )
			asOptions[asPair[0]] = asPair[1]
		}
		var sHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'
		sHTML += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' + 'width="' + asOptions.width + '" height="' + asOptions.height + '" align="middle">' + '<param name="allowScriptAccess" value="sameDomain">' + '<param name="movie" value="' + asOptions.source + '">' + '<param name="quality" value="high">'
		if( asOptions.background ){ sHTML += '<param name="bgcolor" value="' + asOptions.background + '">' }
		if( asOptions.transparent ){ sHTML += '<param name="wmode" value="transparent">' }
		if( asOptions.flashvars ){ sHTML += '<param name="flashvars" value="' + asOptions.flashvars + '">' }
		sHTML += '<embed quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"' + ' pluginspage="http://www.macromedia.com/go/getflashplayer"' + ' src="' + asOptions.source + '" width="' + asOptions.width + '" height="' + asOptions.height + '"'
		if( asOptions.background ){ sHTML += ' bgcolor="' + asOptions.background + '"' }
		if( asOptions.transparent ){ sHTML += ' wmode="transparent"' }
		if( asOptions.flashvars ){ sHTML += ' flashvars="' + asOptions.flashvars + '"' }
		sHTML += '></embed></object>'
		return sHTML
	}
	function set_flash_disabled( bDisabled ){
		set_flash_cookie( ( bDisabled ) ?  "false" : "" )
	}
	function check_flash_version( iVersion ){
		if( navigator.plugins && navigator.plugins['Shockwave Flash'] ){
			var sVersion = ( !iVersion ) ? "\\d+" : "[" + iVersion + "-9]\\d*" 
			sVersion = parseInt( navigator.plugins['Shockwave Flash'].description.replace( new RegExp( "^[^\\d]+(" + sVersion + ").*$"), "$1" ) )
			return ( isNaN( sVersion ) ) ? ( !iVersion ) ? false : 0 : sVersion
		}else if( cmn_oInformation.bIE && !cmn_oInformation.bMAC ){
			var oTemp, iMax = 20
			iVersion = ( !iVersion ) ? 3 : iVersion
			for( var i = iVersion ; i < iMax ; i++ ){
				try{
					oTemp = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash." + i )
					iVersion = i
				}catch(e){
					return ( i > iVersion ) ? iVersion : 0
				}
			}
			return iVersion
		}else{
			return ( !iVersion ) ? false : 0
		}
	}
	function set_flash_cookie( sCookie_value ){
		var dNow = new Date()
		var dExpires = new Date()
		dExpires.setTime( dNow.getTime() + 1000 * 60 * 60 * 24 * 365 )
		cmnSet_cookie( "flash", ( !sCookie_value ) ? "" : sCookie_value, dExpires )
	}
}

function cmnSet_cookie( sName, vValue, dExpires ){
   document.cookie = sName + "=" + escape( vValue )
   + ( ( dExpires == null ) ? "" : ( "; expires=" + dExpires.toGMTString() ) )
   + "; path=/";
}

function cmnGet_cookie( sName ){
	return cmnPairs_string_get_value( document.cookie, sName )
}

function cmnSwitch_class( eOn, sA, sB ){
	if( cmnMatch_class( eOn, sA ) ){
		cmnSet_class( eOn, sB, sA )
	}else{
		cmnSet_class( eOn, sA, sB )
	}
}

function cmnRemove_class( eOn, sA ){
	cmnSet_class( eOn, "", sA )
}

function cmnSet_class( eOn, sReplace, sFind ){
	if( eOn ){
		sReplace = ( sReplace.length ) ? sReplace.replace( /(^\s+|\s+$)/, "" ) : ""
		if( eOn.className.length ){
			var sOld = sReplace
			if( sFind && sFind.length ){
				sFind = sFind.replace( /\s+(\S)/g, "|$1" )
				if( sOld ){
					sOld += "|"
				}
				sOld += sFind
			}
			eOn.className = eOn.className.replace( new RegExp("(^|\\s+)(" + sOld +")($|\\s+)", "g"), "$1" )
		}
		eOn.className += ( eOn.className.length ? " " : "" ) + sReplace
	}
}

function cmnMatch_class( eOn, sFind ){
	return ( sFind && eOn.className && eOn.className.length && eOn.className.match( new RegExp("(^|\\s+)(" + sFind +")($|\\s+)") ) )
}

function cmnPairs_string_get_value( sText, sName, sFrom, sBefore ){
	var sValue = ""
	if( sText != "" ){
		if( !sFrom ) sFrom = "="
		if( !sBefore ) sBefore = ";"
		sText = sText.replace( new RegExp( "(" + sBefore + ")\\s+", "g" ), "$1" )
		var iStart = sText.indexOf( sBefore + sName + sFrom )
		if( iStart >= 0 ){
			iStart += ( sBefore.length + sName.length + sFrom.length )
		}else{
			iStart = sText.indexOf( sName + sFrom )
			if( iStart == 0 ){
				iStart += ( sName.length + sFrom.length )
			}else{
				iStart = -1
			}
		}
		if( iStart >= 0 ){
			var iEnd = sText.indexOf( sBefore, iStart )
			if( iEnd < 0 ){
				iEnd = sText.length
			}
			sValue = sText.substring( iStart, iEnd )
		}
	}
	return sValue
}

function cmnPairs_string_set_value( sText, sName, sValue, sFrom, sBefore ){
	if( !sFrom ) sFrom = "="
	if( !sBefore ) sBefore = ";"
	var iStart = -1
	if( sText ){
		sText = sText.replace( new RegExp( "\\s+(" + sBefore + "|" + sFrom + ")\\s+", "g" ), "$1" )
		iStart = sText.indexOf( sBefore + sName + sFrom )
		if( iStart >= 0 ){
			iStart += ( sBefore.length + sName.length + sFrom.length )
		}else{
			iStart = sText.indexOf( sName + sFrom )
			if( iStart == 0 ){
				iStart += ( sName.length + sFrom.length )
			}else{
				iStart = -1
			}
		}
		if( iStart >= 0 ){
			var iEnd = sText.indexOf( sBefore, iStart )
			if( iEnd < 0 ){
				iEnd = sText.length
			}
			sText = sText.substring( 0, iStart ) + sValue + sText.substr( iEnd )
		}
	}
	if( iStart < 0 ){
		if( sText.lastIndexOf( sBefore ) != ( sText.length - sBefore.length ) ){
			sText += sBefore
		}
		sText += sName + sFrom + sValue + sBefore
	}
	return sText
}

function cmnAdd_hover( eOn ){
	cmnAdd_event( eOn, "mouseover", function(){ cmnSet_class( eOn,    "hover" ) } )
	cmnAdd_event( eOn, "mouseout",  function(){ cmnRemove_class( eOn, "hover" ) } )
}

function cmnAdd_events( eOn, asEvent_type, ptrFunction ){
	for( var sName in asEvent_type ){
		cmnAdd_event(eOn, asEvent_type[sName], ptrFunction)
	}
}

function cmnAdd_event( eOn, sEvent_type, ptrFunction ){
	if( eOn.addEventListener ){  
		eOn.addEventListener( sEvent_type, ptrFunction, false )
	}else if(eOn.attachEvent){
		eOn.attachEvent( 'on' + sEvent_type, ptrFunction )
	}
}

function cmnRemove_event( eOn, sEvent_type, ptrFunction ){
	if( eOn.removeEventListener ){  
		eOn.removeEventListener( sEvent_type, ptrFunction, false )
	}else if( eOn.detachEvent ){
		eOn.detachEvent( 'on' + sEvent_type, ptrFunction )
	}
}

