

//   Default file for dhtml library.
//  This file, provide basical tools and must be loaded before any other extentions.


// config
cfg_default_plugins_path="js/dlib/plugins/";
cfg_default_rollover_extension=["_on.", "_off."];

// overide config by setting config variables in document object
if(document.cfg_default_plugins_path) cfg_default_plugins_path=document.cfg_default_plugins_path;
if(document.cfg_prefix_path) cfg_default_plugins_path=document.cfg_prefix_path+cfg_default_plugins_path;
if(document.cfg_default_rollover_extension) cfg_default_rollover_extension=document.cfg_default_rollover_extension;

// variable
dlib=new Object;
dlib.listeners=[];
 __IE__  = false;
__NS__  = false;
__DOM__ = false;
__KONQUEROR__=false;
__SAFARI__=false;
__WIN__=false;
__MAC__=false;
__LINUX__=false;
__OTHER__=false;
__LOADED_NAV_PLUGIN__=false;
__DEBUG_ALLOWED__=false;

// Determine which navigator is used
if(typeof(__CURRENT_NAVIGATOR__)=="undefined")
{
        //test for konqueror
	if(window.clientInformation && window.clientInformation.appName=="Konqueror"){
		__KONQUEROR__=true;
		__CURRENT_NAVIGATOR__="__KONQUEROR__";
	}
        //test fo Safari
	if(window.clientInformation && window.clientInformation.appVersion.indexOf("Safari")>-1){
		__SAFARI__=true;
		__CURRENT_NAVIGATOR__="__SAFARI__";
	}
	// test for IE
	else if(document.all){
		 __IE__ = true;
		__CURRENT_NAVIGATOR__ = "__IE__";
	}
	// test for NS < 6 (4.7x)
	else if (document.layers){
		 __NS__ = true;
		__CURRENT_NAVIGATOR__ = "__NS__";
	}
	// test for DOM compliant (NS 6+, opera 6+, etc.)
	else {
		 __DOM__ = true;
		__CURRENT_NAVIGATOR__ = "__DOM__";
	}
	// !!! ERROR !!! Navigator not supported
	//else alert("dhtml lib:\nError: unsupported Navigator!");
};

// Determine on which platefome we are
if(typeof(__CURRENT_PLATEFORME__)=="undefined")
{
	// test for Windows
	if(navigator.appVersion.indexOf('Windows')>-1){
		__WIN__ = true;
		__CURRENT_PLATEFORME__= "__WIN__";
	}
	// test for Machintosh
	else if(navigator.appVersion.indexOf('Mac')>-1){
		__MAC__ = true;
		__CURRENT_PLATEFORME__ = "__MAC__";
	}
	// test for Linux
	else if (navigator.appVersion.indexOf('Linux')>-1 || navigator.appVersion.indexOf('X11')>-1){
		__LINUX__ = true;
		__CURRENT_PLATEFORME__ = "__LINUX__";
	}
	else {
		__OTHER__=true;
		__CURRENT_PLATEFORME__ = "__OTHER__";
	}
};

// tools that help you getting var sended with get method
dlib._get=[];
dlib._getVarsName=[];
if(self.location.search){
	_tmpget=self.location.search.substring(1).split("&");
	for (i=0; i<_tmpget.length; i++){
		_tmpValues=_tmpget[i].split("=");
		dlib._get[unescape(_tmpValues[0])]=unescape(_tmpValues[1]);
		dlib._getVarsName[dlib._getVarsName.length]=unescape(_tmpValues[0]);
		//dlib.debugLog("_get", "dlib", unescape(_tmpValues[0])+" : "+unescape(_tmpValues[1]) , true, false, false);
	}
};

// return variable value sended in get method
dlib.get=function(strvarname){
   	return (dlib.debugLog("get("+strvarname+")", "dlib", dlib._get[strvarname], dlib._get[strvarname] , 1, false))? dlib._get[strvarname]:false;
};

// function that return true when a sended parameter is an undefined variable
function IsUndefined(Var){
	return (Var!=0 && !Var || typeof Var=="undefined")?true:false;
};

// function that return true when a sended parameter is an object
function IsObject(Object){
	return (typeof Object=="object")? true:false;
};

// function that return treu when a sended parameter is an object
function IsString(strstr){
	return (typeof strstr=="string")? true:false;
};

function  isInteger(intint){
	return (!isNaN(parseInt(intint)))? true:false;
};

// function that let you increment numerical value for methods like layers top()
function add(intint){
	d_add_retValue=(arguments.length && dlib.debugLog("dlib subfunction", "add", intint+"  (intint) : ",  isInteger(intint), 3, true))?intint+"add":intint;
	return d_add_retValue;
};

// useful only function for layers clip method. Allow you not to give every clip values. Just fill params with keep function when you
//   do not need to change a value
function keep(){
	return "1k";
};

// function that loads required libs
// function that return platforme name or false is strPlateforme is sended is not equal to __CURRENT_PLATEFORME__
function load_required_lib(strFilePath, strFileName){
	if(dlib.debugLog("dlib", "load_required_lib", "strFilePath, strFileName : ",  ((arguments.length>1)?1:0), 5, true)){
		dlib.debugLog("load_required_lib", "dlib", strFilePath+strFileName, true, false, false);
		document.write("<script language=\"javascript\" src=\""+strFilePath+strFileName+"\"> </script>");
	}
};

// function that return platforme name or false is strPlateforme is sended is not equal to __CURRENT_PLATEFORME__
dlib.plateforme=function (strPlateforme){
	if (arguments.length && strPlateforme.toUpperCase()!=__CURRENT_PLATEFORME__) return 0;
	return __CURRENT_PLATEFORME__;
};

// function that return navigator name or false is strNavigator is sended is not equal to __CURRENT_NAVIGATOR__
dlib.navigator=function (strNavigator){
	if (arguments.length && strNavigator.toUpperCase()!=__CURRENT_NAVIGATOR__) return 0;
	return __CURRENT_NAVIGATOR__;
};

dlib.screenLeft=function(intValue){
	if(arguments.length && dlib.debugLog("dlib", "screenLeft", intValue+" (intValue) : ",  isInteger(intValue), 3, true)) dlib.setScreenLeft((intValue.toString().indexOf("add")>-1)?parseInt(intValue)+parseInt(dlib.getScreenLeft()) :parseInt(intValue));
	return dlib.getScreenLeft();
};

dlib.screenTop=function(intValue){
   	if(arguments.length && dlib.debugLog("dlib", "screenTop", intValue+" (intValue) : ",  isInteger(intValue), 3, true)) dlib.setScreenTop((intValue.toString().indexOf("add")>-1)?parseInt(intValue)+parseInt(dlib.getScreenTop()) :parseInt(intValue));
	return dlib.getScreenTop();
};

// abstract functions

// function that return document height
dlib.documentHeight=function(){};

// function that return document width
dlib.documentWidth=function(){};

// function that return screen height
dlib.screenHeight=function(){};

// function that return screen width
dlib.screenWidth=function(){};

// private function
dlib.debugLog=function (strTitle, strObjectName, mixedValue, intCondition, intErrorMessage, intOnlyErrors, intReturnValue){
	if(arguments.length<7) intReturnValue=false;
	return (intReturnValue)? mixedValue:intCondition;
};

// loading needing plugin
load_required_lib (cfg_default_plugins_path, __CURRENT_NAVIGATOR__+".js");

// Private objects
dlib.object=function (strObjName, strType){
	this.object=dlib.getElement(strObjName, strType);
	this.dlibObject=this;
	this.type=strType;
	this.exists=(this.object)?true:false;
	this.name=strObjName;
	this.style=dlib.getStyle(this.object);
	this.document=dlib.getDocument(this.object);
	this.object.dlibObject=this;
	dlib.debugLog(strType+"s", this.name, false, this.exists, 0, true);
	return true;
};

dlib.ImageObject=function (strObjName){
	this.object=dlib.getElement(strObjName, "image");
	this.dlibObject=this;
	this.type="image";
	this.exists=(this.object)?true:false;
	this.name=strObjName;
	this.object.dlibObject=this;
	dlib.debugLog("images", this.name, false, this.exists, 0, true);
	return true;
};

// ref objects for programmers
dlib.layers=function (strObjectName){
	return new dlib.object(dlib.debugLog("layers", "dlib", " strObjectName : ",  arguments.length, 5, true)?strObjectName:"unknown" ,"layer");
};

dlib.forms=function (strObjectName){
	return  new dlib.object(dlib.debugLog("forms", "dlib", " strObjectName : ",  arguments.length, 5, true)?strObjectName:"unknown","form");
};

dlib.images=function (strObjectName){
	return  new dlib.ImageObject(dlib.debugLog("images", "dlib", " strObjectName : ",  arguments.length, 5, true)?strObjectName:"unknown");
};

dlib.anchors=function (strObjectName){
	return  new dlib.object(dlib.debugLog("anchors", "dlib", " strObjectName : ",  arguments.length, 5, true)?strObjectName:"unknown","anchor");
};

// images methods
dlib.ImageObject.prototype.rollOver=function (intPos){
	if(this.exists){
		if(!arguments.length) intPos=(this.object.src.indexOf(cfg_default_rollover_extension[0])>-1)?false:true;
		this.object.src=(intPos)? this.object.src.replace(new RegExp(cfg_default_rollover_extension[1]),cfg_default_rollover_extension[0]):this.object.src.replace(new RegExp(cfg_default_rollover_extension[0]),cfg_default_rollover_extension[1]);
		dlib.debugLog("images.rollOver", this.name, "switched to : "+(intPos? cfg_default_rollover_extension[0]:cfg_default_rollover_extension[1]), true, false, false);
	}
};

dlib.ImageObject.prototype.setSwap=function (strImgSrc, intRollOver){
	if(this.exists && dlib.debugLog("images.setSwap", this.name, false, (arguments.length)?true:false, 5, true) && dlib.debugLog("images.setSwap", this.name, "strImgSrc : ", IsString(strImgSrc), 1, true)){
                dlib.debugLog("images.setSwap", this.name, "swap set to : "+strImgSrc, true, false);
		this.object.swapsrc=(arguments.length>1 && intRollOver)?this.object.src:strImgSrc;
		if(arguments.length>1 && dlib.debugLog("images.setSwap", this.name, "src set to : "+strImgSrc, intRollOver, false, false)) this.object.src=strImgSrc;
	}
};

dlib.ImageObject.prototype.swap=function (){
	if(this.exists){
                strCurrentSwap=this.object.swapsrc;
		this.object.swapsrc=this.object.src;
		this.object.src=strCurrentSwap;
		dlib.debugLog("images.swap", this.name, "src set to : "+strCurrentSwap, true, false, false);
	}
};

dlib.ImageObject.prototype.height=function(){
	if(this.exists) return dlib.debugLog("images.height", this.name, this.object.height, this.object.height, false, false);
	return 0;
};

dlib.ImageObject.prototype.width=function(){
   	if(this.exists) return dlib.debugLog("image.width", this.name, this.object.width, this.object.width, false, false);
	return 0;
};

dlib.preloadImg=function(){
        if(!dlib.arrPreloadedImg) dlib.arrPreloadedImg=[];
	for(i=0; i<arguments.length; i++){
                dlib.debugLog("preloadImg", "dlib", "preloading image : "+arguments[i], this.object.width, false, false);
		count=dlib.arrPreloadedImg.length;
		dlib.arrPreloadedImg[count]=new Image();
		dlib.arrPreloadedImg[count].src=arguments[i];
	}
};





