/**
 * EXTSTATS
 * @author Gytis Galvanauskas <gytis@gaumina.lt>
 * @version 1.1
 * @access public
 * @static
 */
	
var is_flash   = false;

var is_flash_2 = false;
var is_flash_3 = false;
var is_flash_4 = false;
var is_flash_5 = false;
var is_flash_6 = false;
var is_flash_7 = false;
var is_flash_8 = false;
var is_flash_9 = false;

var flash_ver  = false;

var detect_min_ver = 2;
var detect_max_ver = 9;

function detectIE() {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	for( var count = detect_min_ver; count <= detect_max_ver; count++ ) {
		document.write( 'is_flash_' + count + ' = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + count + '"))) \n' );
	}
	document.write('<\/SCR' + 'IPT\> \n');
	for( var count = detect_min_ver; count <= detect_max_ver; count++ ) {
		if( eval('is_flash_' + count ) == true ) {
			flash_ver = count;
		}
	}
	if( flash_ver > 0 ) {
		is_flash = true;
	}
}

function detectNS() {
	if( navigator.plugins['Shockwave Flash 2.0'] || navigator.plugins['Shockwave Flash'] ) {
		var is_version_2 = navigator.plugins['Shockwave Flash 2.0'] ? ' 2.0' : "";
		var flash_description = navigator.plugins['Shockwave Flash' + is_version_2].description;
		var flash_version = parseInt( flash_description.substring( 16 ) );
		if( flash_version > 0 ) {
			flash_ver = flash_version;
			is_flash = true;
		}
	}
}

function detectFlash() {

	if( navigator.plugins ) {
		detectNS();
	} 
	if( ( ! is_flash ) && navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0 && ( navigator.appVersion.indexOf( 'Win' ) != -1 ) ) {
		detectIE();
	}
	
}

function detectRes(){

	this.width = screen.width;
	this.height = screen.height;
	this.color = screen.colorDepth;
	this.resolution= (width+"X"+height);
}
	
detectRes();
detectFlash();

var EXTSTATS = {
	
	
	'action' 		: '',
		
	'logInfo' : function() {

		var url = 'http://www.kemi.lt/extstats.additional_info.php?';
		
		url += this.varToURL( 
								{ 
									'flash_title':flash_ver,
									'resolution_title':resolution
								} 
							);

		var oImage = new Image( 1, 1 );
		oImage.src = url;
		
	},
	
	'_varToURL' : function( variable, prefix ) {
		
		var ret_val = '';
		
		if( ( typeof( variable ) == 'object' ) || ( typeof( variable ) == 'array' ) ) {
		
			for( idx in variable ) {
				
				var prefix_variable = ( prefix.length > 0 ) ? ( prefix + '[' + idx + ']' ) : idx;
				
				if( ( typeof( variable[idx] ) != 'object' ) && ( typeof( variable[idx] ) != 'array' ) ) {
					
					ret_val += prefix_variable + '=' + escape( variable[idx], 1 ) + '&';
					
				} else {
					
					ret_val += this._varToURL( variable[idx], prefix_variable );
				}
			}
			
		}
		
		return( ret_val );
	},
	
	'varToURL' : function( variable ) {
	
		var ret_val = '';
		
		ret_val = this._varToURL( variable, '' );
		
		if( ret_val.length > 0 ) {
			ret_val = ret_val.substr( 0, ret_val.length - 1 );
		}
		
		return( ret_val );
	
	},
	
	'getRandString' : function() {
	
		var ret_val = '';
		
		for( var count = 0; count < 10; count++ ) {
			ret_val += Math.floor( Math.random() * 100000 ).toString();
		}
		
		return( ret_val );

	},
	
	'goEmailLink' : function( email_text ) {
		
		var url = this.action + '?';
		
		url += this.varToURL( 
								{ 
									'stat_type' : 'email_cms_item_log', 
									'email_text' : email_text, 
									'item_id' : this.item_id
								} 
							);
		var oImage = new Image( 1, 1 );
				
		oImage.src = url;
		window.location.href = 'mailto:' + email_text;
		
	}
	
	
	
}

EXTSTATS.logInfo();


function logCounter( counter_type ){
	oImg = new Image( 1, 1 );
	var url = 'http://www.kemi.lt/extstats.additional_info.php?counter=' + counter_type;
	oImg.src = url;
}

function logHouse(){
	logCounter( '3d_flash' );
}
