//------------- general functions ---------------
function $(e){
	if(typeof(e)=="string"){
		e= document.getElementById(e);
	}
	if(e != null){
		e.setOpacity=setOpacity;
		e.elementWidth=  elementWidth;
		e.elementHeight= elementHeight;
		e.absolutePosition=absolutePosition;
		return e;
	}else{
		return false;
	}
}
function setOpacity(n) {
	this.style.opacity = n/10;
	this.style.MozOpacity = n/10;
	this.style.KhtmlOpacity = n/10;
	this.style.filter = n==10 ? '':'alpha(opacity=' + n*10 + ')';
	/* fot ie8 ?
	-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
    filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50);
    opacity: .5;
	*/
	return n;
}
function elementWidth(n){
	if(typeof(n)=="number"){
		this.style.width=n+'px';
		return n;
	}else{
		return this.offsetWidth;
	}	
}
function elementHeight(n){
	if(typeof(n)=="number"){
		this.style.height=n+'px';
		return n;
	}else{
		return this.offsetHeight;
	}	
}

var __isFireFox = navigator.userAgent.match(/gecko/i); 

function absolutePosition(x, y) {
	if(typeof(x)=="number" && typeof(y)=="number" ){
		this.style.top=		y+'px';
		this.style.left=	x+'px';
	}else{
        var x = this.offsetLeft;    
        var y = this.offsetTop;    
        e=this;  
        var offsetParent = 	e.offsetParent;   
        var parentNode = 	e.parentNode;   
  strx= x;
        while (offsetParent !== null) {   
            x += offsetParent.offsetLeft;   
            y += offsetParent.offsetTop;   
  strx=strx+'-'+x;
            if (offsetParent != document.body && offsetParent != document.documentElement) {   
                x -= offsetParent.scrollLeft;   
                y -= offsetParent.scrollTop;   
            }   
            //next lines are necessary to support FireFox problem with offsetParent   
			if (__isFireFox) {   
                while (offsetParent != parentNode && parentNode !== null) {   
                    x -= parentNode.scrollLeft;   
                    y -= parentNode.scrollTop;   
                    parentNode = parentNode.parentNode;   
                }       
            }  
            parentNode = offsetParent.parentNode;   
            offsetParent = offsetParent.offsetParent;   
        }   
	}
	return [x,y];	
}
 

var mouseXY= Array();
document.onmousemove=function (e)
{ 
	mouseX = !e ? window.event.clientX + document.body.scrollLeft : e.pageX;
	mouseY = !e ? window.event.clientY + document.body.scrollTop  : e.pageY;
	mouseXY= [mouseX, mouseY];
}
function fade(e, theOpacity, minOpacity, maxOpacity){
	$(e).ease=0.3;
	$(e).maxOpacity=maxOpacity;
	$(e).theOpacity=theOpacity;
	$(e).setOpacity($(e).theOpacity/10);
	$(e).minOpacity=minOpacity;
	
	$(e).fadeOutWithTimeout=function(n){
		this.timeoutId=window.setTimeout('$("'+$(e).id+'").fadeOut()', n);
	}
	$(e).fadeOut=function(){
		window.clearTimeout(this.timeoutId);
		window.clearInterval(this.intervalId); 
		this.intervalId=window.setInterval ( '$("'+$(e).id+'")._fade('+this.minOpacity+')', 40);
	}
	$(e).fadeIn=function(){
		window.clearTimeout(this.timeoutId);
		window.clearInterval(this.intervalId);
		this.intervalId=setInterval ('$("'+$(e).id+'")._fade('+this.maxOpacity+')', 40);
	}
	$(e).fadeTo=function(n){
		window.clearTimeout(this.timeoutId);
		window.clearInterval(this.intervalId);
		this.intervalId=setInterval ('$("'+$(e).id+'")._fade('+n+')', 40);
	}
	$(e)._fade=function(n){
		var c=this.theOpacity;
		if(c==n){
			window.clearInterval(this.intervalId); 
		}else{
			c= n>c ? c+Math.ceil((n-c)*this.ease) : c-Math.ceil((c-n)*this.ease);
			this.setOpacity(c/10);
			this.theOpacity=c;	
		}
	}
} 
/*
var bodyW;
window.onresize = function()
{
	bodyW=document.body.offsetWidth;
}
*/
//------------- general functions end ---------------
//------------- general object behavior functions ---------------
function previewBhv(e){
		//fade(e);
		fade(e,  30, 30, 100);
		$(e).onmouseover=function(){
			this.fadeIn();
			showDescription(this.n);
		}
		$(e).onmouseout=function(){
			$(e).fadeOutWithTimeout(300);
			hideDescription(this.n);
		}	
}
function leftMenuBhv(e){
		fade(e,  30, 0, 100);	
		//$(e).minOpacity=0;

		$(e).onmouseover=function(){
			this.fadeIn();
		}
		$(e).onmouseout=function(){
			$(e).fadeOutWithTimeout(1000);
		}
}
function fadedivBhv(e){
		//fade(e);
		fade(e,  30, 30, 100);
		$(e).onmouseover=function(){
			this.fadeIn();
		}
		$(e).onmouseout=function(){
			$(e).fadeOutWithTimeout(300);
		}	
}


//------------- initialization objects functions ---------------
function initTopmenu(){
	topMenu=$('header');
	topMenu.menu=$('topmenu');
	topMenu.shutter=$('topMenuShutter');
	topMenu.shutterX=280;
	topMenu.menu.style.clip='rect(0px, '+topMenu.shutter.offsetLeft+'px, 20px, 0px)';
	topMenu.minClip=0;
	topMenu.theClip=topMenu.shutter.offsetLeft;
	topMenu.maxClip=topMenu.menu.offsetWidth;
	topMenu.ease=0.3;
	topMenu.onmouseover=function(){
		if(mouseXY[0]<800){
			this.show();	
		}
	}
	topMenu.onmouseout=function(){
		this.timeoutId=window.setTimeout('topMenu.hide()', 1000);
	}
	topMenu.hide=function(){
		window.clearTimeout(topMenu.timeoutId);
		window.clearInterval(topMenu.intervalId); 
		this.intervalId=window.setInterval ( 'topMenu.clip('+topMenu.minClip+')', 40);
	}
	topMenu.show=function(){
		window.clearTimeout(topMenu.timeoutId);
		window.clearInterval(topMenu.intervalId); 
		this.intervalId=window.setInterval ( 'topMenu.clip('+topMenu.maxClip+')', 40);
	}
	topMenu.clip=function(n){
		var c=topMenu.theClip;
		if(c==n){
			window.clearInterval(topMenu.intervalId); 
		}else{
			c= n>c ? c+Math.ceil((n-c)*topMenu.ease) : c-Math.ceil((c-n)*topMenu.ease);
			topMenu.menu.style.clip='rect(0px,'+c+'px, 20px, 0px)';
			topMenu.shutter.style.left=(topMenu.shutterX+c)+'px';
			topMenu.theClip=c;	
		}
	}
	//topMenu.hide();
}
//------------- initialization objects functions ---------------
//------------- specific object functions ---------------

function showPageNum(n){
	$('pageNum').innerHTML=n;
}
function hidePageNum(n){
	$('pageNum').innerHTML=thePageNum;
}
//------------- specific object functions end ---------------
function loadScript(){
	initTopmenu();
	leftMenuBhv('leftmenu');
	initForm();
}
function initForm(){
	forms=document.forms;
	for(i=0; i<forms.length; i++){
		elements=forms[i].elements;
		for(ii=0; ii<elements.length; ii++){
			if(elements[ii].type=='checkbox'){
				var p= elements[ii].parentNode;
				var cbx= elements[ii];
				cbx.style.display='none';
				cbx.value = elements[ii].checked?1:0;

				titles=	elements[ii].title.split("/");
				ie = document.createElement('img');
				ie.id= elements[ii].name+'img';
				ie.src = chkBoxOff.src;
				ie.cid=cbx.id;
				ie.style.verticalAlign="bottom";
				ie.did=elements[ii].name+'dsc';
				ie.onclick = function(){ sfChkboxCntr(this.id, this.cid) };
				
				document.createTextNode( "Order" ); 
				
				p.appendChild(ie);
			}
		}	
	}
}
var chkBoxOn= new Image();
chkBoxOn.src='/images/chkbox_on.gif';
var chkBoxOff= new Image();
chkBoxOff.src='/images/chkbox_off.gif';


function sfChkboxCntr(img, chkbx){
	curvalue=$(chkbx).value;
	if(curvalue==1){
		$(chkbx).value=0;	
		$(chkbx).checked=false;
		$(img).src=chkBoxOff.src;
	}else{
		$(chkbx).value=1;	
		$(chkbx).checked=true;
		$(img).src=chkBoxOn.src;	
	}
}
function setCookie(c_name,value,expiredays)
{var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
} 