﻿///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 	HK510 Browser Class v3.22
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//

function _browser()
{
	this.type 		= this.getType();
	this.platform 	= this.getPlatform();
	this.flashVersion 	= this.getFlashVersion();
	this.find 		= this.getObject;
	this.getWidth	= this.getWidth;
	this.getHeight	= this.getHeight;
}

_browser.prototype.setRequiredVersion = function(v)
{
	this.requiredVersion = v;
}

_browser.prototype.getType = function()
{
	var v = 'others';
	if(document.all && document.getElementById) v = 'ie';
	if(document.all && navigator.userAgent.toLowerCase( ).indexOf("opera") != -1) v = 'opera'; 
	if(!document.all && document.addEventListener) v = 'moz';
	if(document.layers) v = 'ns4';
	return v;
}

_browser.prototype.getPlatform = function()
{
	var v = 'others';
	 if(navigator.appVersion.indexOf('Mac')!=-1) v = 'mac';
	 if(navigator.appVersion.indexOf('Win')!=-1) v = 'win';
	return v;
}
_browser.prototype.getFlashVersion = function(){
	var r=null,v=null,s='ShockwaveFlash.ShockwaveFlash';
	try{r=new ActiveXObject(s+'.7');}
	catch(e){
		try{
			r=new ActiveXObject(s+'.6');
			v=6;
		}catch(e){try{r=new ActiveXObject(s+'.3');}catch(e){}}
	}
	v = ( typeof v == 'undefined' || v == null ) && ( typeof r != 'undefined' && r != null ) ? r.GetVariable('$version').match(/\d+/) : v ;
	if( typeof v == 'undefined' || v == null ){
		var a=navigator.plugins,s='Shockwave Flash';
		try{r=a[s];}
		catch(e){try{r=a[s+' 2.0'];}catch(e){}}
		v=typeof r != 'undefined' && r != null ? r.description.match(/\d+/) : null ;
	}
	return !isNaN(v)?Number(v):v;
}
/*
_browser.prototype.getFlashVersion = function()
{
	this.flashObj 	= new Object();
	var o 		= this.flashObj.version = new Object(); 
	o.max		= 11;
	o.min		= 4;
	var n 		= navigator.plugins;
	var v		= null;
	for(var i=o.max;i>=o.min;i--) o['v'+i] = false;
	if(this.type == 'ie' && this.platform=='win')
	{
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('l11 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
		document.write('l10 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
		document.write('l9 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
		document.write('l8 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
		document.write('l7 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
		document.write('l6 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
		document.write('l5 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
		document.write('l4 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
		document.write('<\/SCR' + 'IPT\> \n');
		for(var i=o.min;i<=o.max;i++) o['v'+i] = eval('l'+i);				
	}

	if(n)
	{
		var _s1 	= "Shockwave Flash";
		var _s2 	= " 2.0";
		if(n[_s1+_s2] || n[_s1])
		{
			var _s3 = n[_s1+_s2] ? _s2 : "";
			var _s4 = Number(n[_s1+_s3].description.match('\\d'));
			for(var i=o.min;i<=o.max;i++) o['v'+i] 	= _s4 == i;
		}
	}

	for(var i=o.max;i>=o.min;i--)
	{
		if(o['v'+i])
		{
			v = i;
			break;
		}
	}
	return v;
}
*/
_browser.prototype.openPopup = function(_p,_w,_h,_n,_l,_t,_f)
{
	var _n1 = (_l!=null)? _l : this.getHorizontalCenterPoint(_w);
	var _n2 = (_t!=null)? _t : this.getVerticalCenterPoint(_h);
	_win = null;
	_win = window.open(_p,_n,'width='+_w+',height='+_h+',top='+_n2+',left='+_n1+','+_f);
	if(_win!=null)
	{
		if(parseInt(navigator.appVersion) >= 4) _win.window.focus();
	}
}

_browser.prototype.openGallery = function(i)
{
	this.openPopup('/site/popup/gallery.html?'+i,250,100,'gallery',null,null,'scrollbars=true,toolbar=no,location=no,status=no,menubar=no,resizable=yes,dependent=no');
}

_browser.prototype.getHorizontalCenterPoint = function(w)
{
	return (this.getScreenWidth()-w)/2;
}

_browser.prototype.getVerticalCenterPoint = function(h)
{
	return (this.getScreenHeight()-h)/2;
}

_browser.prototype.getWidth = function()
{
	return (this.type=='ie')? document.body.clientWidth : window.innerWidth;
}

_browser.prototype.getScreenWidth = function()
{
	return screen.width;
}

_browser.prototype.getHeight = function()
{
	return (this.type=='ie')? document.body.clientHeight : window.innerHeight;
}

_browser.prototype.getScreenHeight = function()
{
	return screen.height;
}

_browser.prototype.getObject = function(n,d)
{
	if(typeof(n)=='object') return n;
	if(typeof(n)=='undefined') return null;
	var p,i,x;
	if(!d) d = document;
	if((p=n.indexOf("@"))>0 && parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n]) && d.all) x=d.all[n];
	for (i=0;!x && i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x && d.layers&&i<d.layers.length;i++) x = this.getObject(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}

_browser.prototype.toString = function()
{
	var s 	= "HK510 Browser Class // Generic // v3.22\n";
	s 	+= "-----------------------------------------------------------\n";
	s 	+= "Available Properties:\n\n";
	s	+= "   -> type\n   -> platform\n   -> flashVersion\n   -> requiredVersion\n\n";
	s 	+= "-----------------------------------------------------------\n";
	s 	+= "Available Methods:\n\n";
	s	+= "   -> find\n   -> getWidth\n   -> getScreenWidth\n   -> getHeight\n   -> getScreenHeight\n   -> getHorizontalCenterPoint\n   -> getVerticalCenterPoint\n   -> openPopup\n   -> openGallery\n";
	return s;
}

//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Class Instanciation

var __browser 	= new _browser();

//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

