/********************************************************
 * BrowserCheck v4.4
 *******************************************************/
var is = {
	getUserAgents : function() { 
		// segédfunkciók
		this.geckoGetRv = function() {
			var nRv = 0, nStart, nEnd, sRv, aRv, nExp = 1, i, nTemp;
			nStart = this.agent.indexOf( 'rv:' );
			nEnd   = this.agent.indexOf( ')', nStart );
			sRv    = this.agent.substring( nStart + 'rv:'.length , nEnd  );
			aRv    = sRv.split('.');
			for ( i = 0; i < aRv.length; i++ ) {
				nTemp = parseInt( aRv[i] );
				nRv += nTemp / nExp;
				nExp *= 10;
			}
			return nRv;
		}
		this.getVersion = function() {
			var sId;
			switch ( this.app ) {
				case 'gecko' :
					return this.geckoRv; break;
				case 'ie' :
					sId = 'msie ' ; break;
				case 'opera' :
					sId = ( this.agent.indexOf( 'opera/' ) > -1 ) ? 'opera/' : 'opera '; break;
				case 'khtml' :
					sId = ( this.saf ) ? 'applewebkit/' : 'konqueror/';	break;
				case 'ns4' :
					sId = 'mozilla/'; break;
			}
			return parseFloat( '0' + this.agent.substr( this.agent.indexOf( sId ) + sId.length ), 10 );
		}
		// adatok átvétele
		this.ver         = navigator.appVersion.toLowerCase();
		this.agent       = navigator.userAgent.toLowerCase();
		this.platform    = navigator.platform.toLowerCase();
		this.product     = new String( navigator.product ).toLowerCase();
		this.productSub  = new String( navigator.productSub ).toLowerCase();
		this.vendor      = new String( navigator.vendor ).toLowerCase();
		this.vendorSub   = new String( navigator.vendorSub ).toLowerCase();
		this.opera       = typeof ( window.opera ) != 'undefined';
		this.dom         = document.getElementById ? true : false;
		this.compatMode  = new String( document.compatMode ).toLowerCase();
		
		// platformok
		this.win         = this.platform.indexOf("win") > -1;
		this.linux       = ( this.platform.indexOf("linux") > -1 || this.platform.indexOf("x11") > -1 );
		this.mac         = this.platform.indexOf("mac") > -1;
	
		// böngészők
		// khtml
		this.khtml       = ( this.agent.indexOf("khtml") > -1 || this.product.indexOf("khtml") > -1 )
		this.konq        = ( this.agent.indexOf("konqueror") > -1 || this.product.indexOf("konqueror") > -1 );
		this.konq31      = ( this.konq && this.ver.indexOf("konqueror/3.1") > - 1 );
		this.saf         = ( this.agent.indexOf("safari") > -1 || this.ver.indexOf("safari") > -1 );
		// opera
		this.opera       = ( this.opera || this.agent.indexOf("opera") > -1 ); // nem win platformon az opera obj nem jön létre
		this.opera5      = ( this.opera && this.agent.indexOf("opera 5") > -1 );
		this.opera6      = ( this.opera && ( this.agent.indexOf("opera 6") > -1 || this.agent.indexOf("opera/6") > -1 ) );
		this.opera7      = ( this.opera && ( this.agent.indexOf("opera 7") > -1 || this.agent.indexOf("opera/7") > -1 ) );
		// IE
		this.ie          = ( this.ver.indexOf('msie') != -1 && !this.opera ) ? true : false;
		this.ie4         = ( document.all && !this.dom && !this.opera ) ? true : false;
		this.ie5         = ( document.all && this.ver.indexOf("msie 5.0") > -1 && !this.opera ) ? true : false; 
		this.ie5mac      = ( this.ie5 && this.mac ) ? true : false; 
		this.ie55        = ( document.all && this.ver.indexOf("msie 5.5") > -1 && !this.opera ) ? true : false; 
		this.ie6         = ( document.all && this.ver.indexOf("msie 6" )  > -1 && !this.opera ) ? true : false;
		/*@cc_on @*/ /*@if (@_jscript) 
		this.ieJSBuild   = @_jscript_build;
		this.ieJSVersion = @_jscript_version; /*@end @*/
		// mozilla
		this.ns4         = ( document.layers && !this.dom ) ? true : false;
		this.gecko       = ( this.product == "gecko" && !this.khtml ) ? true : false;
		this.geckoRv     = ( this.gecko ) ? this.geckoGetRv() : 0;
		this.gecko1      = ( this.gecko && Number( this.productSub ) > 20020530 ) ? true : false;
		this.moz1        = ( this.gecko && this.vendor == '' && !( this.geckoRv < 1 ) ) ? true : false;
		this.ns6         = ( this.gecko && this.vendor == 'netscape6' && parseFloat( this.vendorSub ) >= 6 && parseFloat( this.vendorSub ) < 7 ) ? true : false;
		this.ns7         = ( this.gecko && this.vendor == 'netscape' && parseFloat( this.vendorSub ) >= 7 ) ? true : false;
		this.fb          = ( this.gecko && ( this.vendor == 'mozilla firebird' || this.vendor == 'phoenix' ) );
		this.cm          = ( this.gecko && ( this.vendor == 'chimera' || this.vendor == 'camino' ) );
		this.beo         = ( this.gecko && this.vendor == 'beonex' );
		this.kmel        = ( this.agent.indexOf('k-meleon') > -1 ) ? true : false ;
		// alkalmazás-verziószám
		this.app         = ( ( this.ie ) ?  'ie' : ( this.gecko ) ? 'gecko' : ( this.opera ) ?  'opera' : ( this.khtml ) ? 'khtml' : ( this.ns4 ) ? 'ns4' : 'undefined' );
		this.appVer      = this.getVersion();
	
		// csoportok
		this.bs4         = ( this.ie || this.ns4 || this.gecko || this.opera || this.khtml );
		this.bs5         = ( ( this.ie && this.appVer >= 5.5 ) || this.gecko || this.opera7 || this.konq31 || this.saf );
		this.bss         = ( this.gecko || this.opera7 || this.konq31 || this.saf )
		this.min         = ( this.bs5 || this.ie5 || this.opera || this.khtml );
		return this;
	}
}
is.getUserAgents();


// FlashCheck v3.1
var flash = {
	 getFlashCheck : function ( nVer, fError, fScriptableError ) { // fScriptableError :: gecko nincs szkriptelhető plugin telepítve
		var sDesc, strCommand;
		this.shockMode = false;  // telepítve van-e
		this.flashVer = 0;       // nagyverzió
		this.rv = 0;             // alverzió
		this.ver = 0;            // együtt
		this.scriptable = false; // van-e js kapcsolat
		this.minVerRound = parseInt( nVer );
		this.elEmbed;            // gecko Scriptable-hez kell
		this.timeout;
		this.bAppend = false;
		this.fScriptableError = ( typeof fScriptableError == 'function' ) ? fScriptableError : false;
		if ( is.ns4 || is.gecko || is.opera || is.ie5mac || is.khtml ) {
			if ( navigator.mimeTypes && 
				 navigator.mimeTypes["application/x-shockwave-flash"] && 
				 navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin && 
				 navigator.plugins && 
				 navigator.plugins["Shockwave Flash"] ) {
				sDesc = navigator.plugins["Shockwave Flash"].description + '';
				this.shockMode = true;
				this.flashVer = parseInt( sDesc.charAt( sDesc.indexOf(".") -1 ) );
				this.rv = sDesc.substr( sDesc.lastIndexOf("r") + 1, sDesc.length );
			}
		}
		else if ( is.ie ) { //  && is.win
			strCommand =    'function checkIE( obj ) { ' +
							'	aFlashPlugins = [];' +
							'	for ( i = 2; i < 11; i++ ) {' +
							'		try {' +
							'			aFlashPlugins[i] = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i );' +
							'		}' +
							'		catch ( ex ) {};' +
							'	}' +
							'	for ( i = 0; i < aFlashPlugins.length; i++ ) {' +
							'		if ( typeof aFlashPlugins[i] == "object" ) {' +
							'		obj.shockMode = true;' +
							'		obj.flashVer = i;' +
							'		}' +
							'	}' +
							'}'
			eval( strCommand );
			checkIE( this );
		}
		this.ver = parseFloat( this.flashVer + '.' + this.rv );
		// nincs plugin
		if ( !this.shockMode )
			fError();
		// IE és kisebb az activeX fő verziószáma
		if ( ( is.ie && is.win ) && this.flashVer < this.minVerRound )
			fError();
		// a plugin alapú böngészőkben a plugin kiadását is ellenőrizzük (rv)
		if ( ( is.ns4 || is.gecko || is.opera || is.ie5mac || is.khtml ) && this.ver < nVer )
			fError();
		// scriptable: alapbeállítások szerint ezekben van scriptelhető flash plugin
		// win  : ie5, ie55, ie6;      moz1, ns7 && plugin v6.47;  ! fb, ns4, o6, o7
		// linux: moz1, ns7
		// mac  : ns7 && plugin v6.47;                             ! moz, cm, ie5, saf
		if ( is.ie && !is.mac )
			this.scriptable = true;
		if ( is.gecko ) {
			// ha a geckó és scriptable = null, akkor még nem futott le az időzítés
			this.scriptable = null;
			this.elEmbed = document.createElement('embed');
			this.elEmbed.type = 'application/x-shockwave-flash';
			this.elEmbed.width = 0;
			this.elEmbed.height = 0;
			// általában load a gyorsabb!(?)
			loadEventBinding( window, flash.appendGeckoScriptable );
			this.timeout = setInterval( 'flash.appendGeckoScriptable()', 1 );
		}
		// if ( is.gecko && !is.fb && !( is.mac && !is.ns7 ) && !is.linux ) { // régi
		//      if ( this.ver >= 6.49 ) this.scriptable = true;
		// }
	},
	appendGeckoScriptable : function() {
		if ( document.body && !this.bAppend ) {
			// eventBinding this = window!
			clearInterval( flash.timeout );
			document.body.appendChild( flash.elEmbed );
			flash.timeout = setTimeout( 'flash.finalizeGeckoScriptable()', 1 );
			flash.bAppend = true;
		}
	},
	finalizeGeckoScriptable : function() {
		this.scriptable = ( typeof this.elEmbed.SetVariable == 'function' ) ? true: false; 
		this.elEmbed.parentNode.removeChild( this.elEmbed );
		if ( this.fScriptableError && !this.scriptable )
			this.fScriptableError();
	}
}
// Ez nem változtatható! Ha hiba oldalt akarunk adni, akkor külön kell meghívnunk ponton paraméterekkel!
flash.getFlashCheck( 6.49, function() {}, function() {} ); 


// createFlashVBSriptHandler 1.2 - flash fejléc fscommand inicializálása
// IE: a flash-js kapcsolat létrehozása
function createFlashVBSriptHandler( aObjectId ) {
	if ( !is.ie || is.ie5mac ) return false;
	var elVbs, elHead, i;
	elHead = document.getElementsByTagName('HEAD')[0];
	if ( !elHead )
		return alert( 'A Flash VBSript eseménykezelőjét nem sikerült létrehozni' )
	for ( i = 0; i < aObjectId.length; i++ ) {
		elVbs = document.createElement('SCRIPT');
		elVbs.language = 'VBScript';
		elVbs.text = '\n'
				 + 'on error resume next \n'
				 + 'Sub ' + aObjectId[i] + '_FSCommand(ByVal command, ByVal args)\n'
				 + '  call ' + aObjectId[i] + '_DoFSCommand(command, args)\n'
				 + 'end sub\n';
		elHead.appendChild( elVbs );
	}
}


// sendToFlash & getFromFlash 1.0
// vissztérési értéket nem kívánó flash föggvények hívása
// a setFlashVariable 1.0 továbbfejlesztéséből
function sendToFlash( sId, sFunctionName, aArguments ) {
	var elFlash;
	// csak geckók: ha még nem végződött be a FlashCheck lekérdezése
	if ( flash.scriptable == null )
		return setTimeout( function() {
			sendToFlash( sId, sFunctionName, aArguments )
		}, 1   )
	// ha nem scriptelhető visszatérünk
	if ( !flash.scriptable )
		return false;
	elFlash = ( is.ie ) ? document.all[sId] : document.embeds[sId];
	if ( !elFlash ) {
		return setTimeout( function() {
			sendToFlash( sId, sFunctionName, aArguments )
		}, 1000 );
	}
	/*if ( is.gecko && !elFlash.PercentLoaded ) {
		return setTimeout( function() {
			sendToFlash( sId, sFunctionName, aArguments )
		}, 200 );
	}*/
	if ( elFlash.PercentLoaded() != 100 ) {
		return setTimeout( function() {
			sendToFlash( sId, sFunctionName, aArguments )
		}, 200 );
	}
	switch( sFunctionName ) {
		case 'GotoFrame' :
			elFlash.GotoFrame( aArguments[0] ); // GotoFrame( frameNumber ) :: GotoFrame(24);
			break;
		case 'LoadMovie' :
			elFlash.LoadMovie( aArguments[0], aArguments[1] ); // LoadMovie( layerNumber, url ) :: LoadMovie(0, "mymovie.swf");
			break;
		case 'Pan' :
			elFlash.Pan( aArguments[0], aArguments[1], aArguments[2] ); // Pan ( x, y, mode )  :: Pan(50, 50, 1) 
			break;
		case 'Play' :
			elFlash.Play() ; // Play()
			break;
		case 'Rewind' :
			elFlash.Rewind() ; // Rewind()
			break;
		case 'SetVariable' :
			elFlash.SetVariable( aArguments[0], aArguments[1] ); // SetVariable( variableName, value ) :: SetVariable("/Form:UserName", "John Smith");
			break;
		case 'SetZoomRect' :
			elFlash.SetZoomRect( aArguments[0], aArguments[1], aArguments[2], aArguments[3] ); // SetZoomRect ( left, top, right, bottom ) :: SetZoomRect(0, 0, 200, 200);
			break;
		case 'StopPlay' :
			elFlash.StopPlay() ; // StopPlay()
			break;
		case 'Zoom' :
			elFlash.Zoom( aArguments[0] ); // Zoom( percent ) :: Zoom(50)
			break;
		case 'TCallFrame' :
			elFlash.TCallFrame( aArguments[0], aArguments[1] ); // TCallFrame( target, frameNumber ) :: TCallFrame("/", 4);
			break;
		case 'TCallLabel' :
			elFlash.TCallLabel( aArguments[0], aArguments[1] ); // 	TCallLabel( target, label ) :: TCallLabel("/", "HandleScriptNotify");
			break;
		case 'TGotoFrame' :
			elFlash.TGotoFrame( aArguments[0], aArguments[1] ); // TGotoFrame( target, frameNumber ) :: TGotoFrame("/MovieClip", 2);
			break;
		case 'TGotoLabel' :
			elFlash.TGotoLabel( aArguments[0], aArguments[1] ); // TGotoLabel( target, label ) :: TGotoLabel("/MovieClip", "MyLabel");
			break;
		case 'TPlay' :
			elFlash.TPlay( aArguments[0] ); // TPlay( target ) :: TPlay("/MovieClip");
			break;
		case 'TSetProperty' :
			elFlash.TSetProperty( aArguments[0], aArguments[1], aArguments[2] ); // TSetProperty( target, property, value) :: TSetProperty("/MovieClip", nameIndex, "NewName");
			break;
		case 'TStopPlay' :
			elFlash.TStopPlay( aArguments[0] ); // TStopPlay( target )
			break;
	}
}
// visszérési értékkel rendelkező flash függvények hívása
function getFromFlash( sId, sFunctionName, aArguments ) {
	if ( !flash || flash.scriptable != true )
		return null;
	elFlash = ( is.ie ) ? document.all[sId] : document.embeds[sId];
	if ( !elFlash )
		return null;
	switch( sFunctionName ) {
		// TCurrentFrame( target ), TCurrentLabel(target), TGetProperty( target, property), TGetPropertyAsNumber (target, property)
		case 'GetVariable' :
			return elFlash.GetVariable( aArguments[0] ); // GetVariable( varName ) :: GetVariable("/Form/RadioButton:Value");
			break;
		case 'IsPlaying' :
			return elFlash.IsPlaying(); // IsPlaying();
			break;
		case 'PercentLoaded' :
			return elFlash.PercentLoaded(); // PercentLoaded();
			break;
		case 'TotalFrames' :
			return elFlash.TotalFrames(); // TotalFrames();
			break;
		case 'TCurrentFrame' :
			return elFlash.TCurrentFrame( aArguments[0] ); // TCurrentFrame( target ) :: TCurrentFrame("/MovieClip");
			break;
		case 'TCurrentLabel' :
			return elFlash.TCurrentLabel( aArguments[0] ); // TCurrentLabel( target ) :: TCurrentLabel("/MovieClip")
			break;
		case 'TGetProperty' :
			return elFlash.TGetProperty( aArguments[0], aArguments[1] ); // TGetProperty( target, property) :: TGetProperty("/", nameIndex);
			break;
		case 'TGetPropertyAsNumber' :
			return elFlash.TGetPropertyAsNumber( aArguments[0], aArguments[1] ); // 	TGetPropertyAsNumber (target, property) :: TGetProperty("/", framesLoadedIndex);
			break;
	}
}


// createElementEmbed 1.0 - ie5mac - ben ben működik
function createFlashEmbed( aObjectId ) {
	var i, elObject, elEmbed, sSrc, j, elChild;
	if ( !( is.gecko && navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash'] ) )
		return false;
	for ( i = 0; i < aObjectId.length; i++ ) {
		elObject = document.getElementById( aObjectId[i] )
		if ( !elObject )
			continue;
		elEmbed = document.createElement('embed');
		elEmbed.name = elObject.id;
		elEmbed.className = elObject.className;
		elEmbed.setAttribute( 'pluginspage', 'http://www.macromedia.com/go/getflashplayer' );
		elEmbed.type = 'application/x-shockwave-flash';
		elEmbed.width = elObject.width;
		elEmbed.height = elObject.height;
		elEmbed.swLiveConnect = true;
		for ( j = 0; j < elObject.childNodes.length; j++ ) {
			elChild = elObject.childNodes[j];
			if ( elChild.nodeType != Node.ELEMENT_NODE )
				continue;
			if ( elChild.tagName.toLowerCase() == 'param' ) {
				switch ( elChild.name.toLowerCase() ) {
					case 'movie' :
						elEmbed.src = elChild.value;
						break;
					case 'quality' :
					case 'wmode' :
					case 'menu' :
					case 'flashvars' :
						elEmbed.setAttribute( elChild.name.toLowerCase(), elChild.value );
						break;
				}
			}
		}
		elObject.parentNode.replaceChild( elEmbed, elObject );
		elEmbed.id = elEmbed.name;
	}
}


// setFlashObject 0.1 - Object tag kiegészítése IE-re
function setFlashObject( aObjectId ) {
	var i;
	if ( !is.ie )
		return false;
	for ( i = 0; i < aObjectId.length; i++ ) {
		elObject = document.getElementById( aObjectId[i] )
		if ( !elObject )
			continue;
		elObject.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
		elObject.codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0';
	}
}
