BROWSER = new Object();
BROWSER.isOpera  = navigator.userAgent.indexOf("Opera") > -1;
BROWSER.isIE     = navigator.userAgent.indexOf("MSIE") > 1 && !BROWSER.isOpera; 
BROWSER.isMoz    = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !BROWSER.isOpera;
BROWSER.isSafari = navigator.userAgent.indexOf("Safari") == 0 && !BROWSER.isOpera;

if (typeof($) != "function") $ = function(ID){ return document.getElementById(ID); }

function redirect(id) {
   alert("This link works only in front-end site!")
}

function popupimg(img) {
	var win = window.open("/enlarge.php?src="+img, "Popup","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=200,height=200");
	win.focus();
}

/* highlist elements onmouse over event
 */
function highlight(groupElements, classOver) {
   var i, j, Obj, groupObjects = [];
   for(j=1; j<100; j++) {
   	   for(i in groupElements) {
   	   	   Obj = $(groupElements[i]+j);
           if (Obj) {
               Obj.ind = j; 
               groupObjects[groupObjects.length] = Obj;
           }
       }
   }
   
   for(i in groupObjects) {
      Obj = groupObjects[i];
      Obj.classDefault = Obj.className;
      Obj.classOver = classOver;
      Obj.groupObjects = groupObjects;
      
      Obj.onmouseover = function() {
      	  this.className = this.classOver;
      	  for(var i in this.groupObjects){
      	      var Obj = this.groupObjects[i]; 
      	  	  if (Obj.ind == this.ind) Obj.className = Obj.classOver;
      	  }
      }
      Obj.onmouseout = function() {
      	  this.className = this.classDefault;
      	  for(var i in this.groupObjects){
      	  	  var Obj = this.groupObjects[i];
      	  	  if (Obj.ind == this.ind) Obj.className = Obj.classDefault;
      	  }
      }
   }
}

function openLink(link) {
   location.href = link;
}

function changeImage(img1, img2) {
	var Obj1 = document.getElementById(img1), Obj2 = document.getElementById(img2);
	if (!Obj1 || !Obj2) return false;
	Obj2.style.display = "none";
	Obj1.style.display = "block";
}


// -------------  Transpacancy Functions ---------------------- //
var terminate = [];
function swapImage1(cobjectID, objectID, first, ID) {
	terminate[ID] = true
	setTimeout('swapImage("'+cobjectID+'", "'+objectID+'", '+first+','+ID+')', 100);
}

var transInterval = [], transStatus = [],  activeTrans = [], dirTrans = [];
function swapImage(cobjectID, objectID, first, ID) {
       if (first) terminate[ID] = false;
       if (!first && !terminate[ID]) return;
       if (first && (activeTrans[ID] || transStatus[ID])) return;
   	   activeTrans[ID] = first;
   	   var cImg = document.getElementById(cobjectID), Img = document.getElementById(objectID);

	   if (!first) {
	  	   //cImg.className = 'block';
	  	   //Img.className = 'visimg';
       } else {
	  	   cImg.className = 'visimg';
	       Img.className = 'block';
       }

   	   if (!first) {
   	       dirTrans[ID] = 0.04;
   	   } else {
   	   	   dirTrans[ID] = -0.04;
   	   }

       if (!transStatus[ID]) {
       	   transInterval[ID] = 1.0;
       }
       startTrans(cImg.id, Img.id, ID);
}

function startTrans(cobjectID, objectID, ID) {
    var cobject = document.getElementById(cobjectID), object = document.getElementById(objectID);
    transInterval[ID] += dirTrans[ID];
	setTransparency( cobject , transInterval[ID] );
	if (transInterval[ID] > 0.0 && transInterval[ID] <= 1.0) {
	    var tHandler = setTimeout('startTrans("' + cobjectID + '","' + objectID + '",'+ID+')', 30);
	    transStatus[ID] = {handler:tHandler, cobject:cobject, object:object};
	} else {
		//setTransparency(cobject, 1.0);
		//cobject.className = 'none';
		//object.className = 'block';
		transStatus[ID] = null;
	}
}

// set style transparancy of object
function setTransparency(object, trans) {
	if  (trans<0) return;
	if (typeof(object.style.opacity) != 'undefined')
		object.style.opacity = trans
	else if (typeof(object.filters) != 'undefined' && typeof(object.filters.alpha) != 'undefined')
		object.filters.alpha.opacity = trans * 100
	else if (typeof(object.style.MozOpacity) != "undefined")
		object.style.MozOpacity = parseInt(trans)
	else if (typeof(object.style.KhtmlOpacity) != 'undefined')
		object.style.KhtmlOpacity = trans
}


// resets transpacency handler
function resetTrans() {
   if (transStatus){
   	   window.clearTimeout(transStatus.handler);
   	   setTransparency(transStatus.cobject, 1.0);
   	   transStatus.cobject.className = "none";
   	   transStatus.object.className = "block";
   }
   transStatus = null;
}

// --------------------  End Transparancy Functions ------------- //

// open classic popup window
var win_array = [];
function openWin(loc, winName, winWidth, winHeight, winParams){
   if (!win_array[winName]) win_array[winName] = null;
   if (!win_array[winName] || (win_array[winName] && win_array[winName].closed)){
      if (winParams=='full'){
         winParams = 'resizable=yes,menubar=yes,status=yes,toolbar=yes,titlebar=yes,location=yes,directories=yes,scrollbars=yes';
      }
      win_array[winName] = window.open(loc, winName, "width="+winWidth+",height="+winHeight+","+winParams);
   }

   win_array[winName].location = loc;
   win_array[winName].focus();
   return win_array[winName];
}

function setLabel(objID) {
	var Obj = document.getElementById(objID);
	if (!Obj) return;
	Obj.defaultText = Obj.value;
	Obj.onclick = function(){
		if (this.value == Obj.defaultText) this.value = "";
	}
	
	Obj.onblur = function(){
	    if (this.value.match(/^\s*$/)) this.value = this.defaultText;
	}
}
