ie = (document.all)?((window.opera)?false:true):false;

function findPosTop(fObject){
	fTop = 0
	if(fObject.offsetParent){
		fTop = fObject.offsetTop;
		while(fObject = fObject.offsetParent){
			fTop += fObject.offsetTop;
		}
	}
	return fTop;
}
function With(o, p){
	for(var prop in p){
		o[prop] = p[prop]; 
	}
}
function setOpacity(fObject, fOpacity){
	if(fOpacity > 100)
		fOpacity = 100;
	
	if(ie)
		fObject.style.filter = (fOpacity == 100)?'none':'alpha(opacity = '+ fOpacity +')';
	else
		fObject.style.opacity = fOpacity / 100;
}
vCurrentPhoto = 0;
function Rotator(){
	function show(oObject){
		var fOpacity = 0;
		function fade(){
			fOpacity += 5;
			
			setOpacity(oObject, fOpacity);
			if(fOpacity != 100)
				setTimeout(fade, 50);
		}
		fade();
	}
	function hide(oObject){
		var fOpacity = 100;
		function fade(){
			fOpacity -= 10;
			
			setOpacity(oObject, fOpacity);
			if(fOpacity != 0)
				setTimeout(fade, 50);
		}
		fade();
	}
	if(aImage.length > 1){
		oCurrent = document.getElementById('imagerotator'+ vCurrentPhoto);
		vNext = vCurrentPhoto + 1;
		if(vNext == aImage.length)
			vNext = 0;
		oNext = document.getElementById('imagerotator'+ vNext);
		
		vCurrentPhoto = vNext;
		
		show(oNext);
		hide(oCurrent);
		
		setTimeout(Rotator, 4000);
	}
}
/*menu */
function findPos(fObject, fReturn) {
	var fLeft = fTop = 0;
	if (fObject.offsetParent){
		do{
			fLeft += fObject.offsetLeft;
			fTop += fObject.offsetTop;
		}while(fObject = fObject.offsetParent);
	}
	if(fReturn == 'x')
		return fLeft
	else if(fReturn == 'y')
		return fTop;
	else
		return [fLeft, fTop];
}
function addEvent(fElement, fEvent, fFuntion){
	if(fElement.addEventListener){
		fElement.addEventListener(fEvent, fFuntion, false); 
		return true; 
	}
	else if(fElement.attachEvent){
		var r = fElement.attachEvent('on'+fEvent, fFuntion); 
		return r; 
	}
	else{ 
		return false; 
	} 
}
/* dropdown */
dropdown = {
	add: function(fButton, fContent, fMaxWidth, fMaxHeight, fMinWidth, fMinHeight){
		fId = dropdown.settings.length;
		fId++;
		if(fId == 1)
			addEvent(window, 'resize', function(){dropdown.resizenumber++;});
		else
			fId--;
		
		
		fWidth = fMinWidth;
		if(!fMinWidth)
			fWidth = dropdown.defaults.minWidth;
		fHeight = fMinHeight;
		if(!fMinHeight)
			fHeight = dropdown.defaults.minHeight;
		
		
		fDropdown = document.createElement('div');
		fDropdown.id = 'dropdown'+ fId;
		fDropdown.style.position = 'absolute';
		fDropdown.style.overflow = 'hidden';
		fDropdown.style.height = fHeight +'px';
		fDropdown.style.zIndex = dropdown.defaults.zIndex;
		fDropdown.dropdownid = fId;
		fButton.dropdownid = fId;
		
		addEvent(fButton, 'mousemove', dropdown.schuiven.down);
		addEvent(fButton, 'mouseout', dropdown.schuiven.up);
		addEvent(fDropdown, 'mousemove', dropdown.schuiven.down);
		addEvent(fDropdown, 'mouseout', dropdown.schuiven.up);
		
		document.body.insertBefore(fDropdown, document.body.firstChild);
		document.getElementById('dropdown'+ fId).innerHTML = '<div id="dropdownfg'+ fId +'" style="white-space:nowrap;">'+ fContent +'</div>';
		
		fFg = document.getElementById('dropdownfg'+ fId);
		fFg.style.display = 'block';
		
		
		if(!fMaxWidth){
			if((fMaxWidth = dropdown.defaults.maxWidth) == 0){
				for(fI=0; fI<5; fI++)
					fMaxWidth = fFg.offsetWidth;
			}
		}
		if(fMaxWidth < fButton.clientWidth)
			fMaxWidth = fButton.clientWidth + 2;
		
		if(fWidth.indexOf('content') > -1)
			fWidth = fMaxWidth
		
		fDropdown.style.width = fWidth +'px';
		
		if(!fMaxHeight){
			if((fMaxHeight = dropdown.defaults.maxHeight) == 0){
				for(fI=0; fI<5; fI++)
					fMaxHeight = fFg.offsetHeight;
			}
		}
		
		/*
			dropdown.settings[fId]:
				0: button element
				1: max width
				2: max hieght
				3: current width
				4: current height
				5: min width
				6: min height
				7: dropdown status up/down
				8: moving
				9: resize counter
				10: default button classname
				11: hover button classname
				12: position X
				13: position Y
		*/
		dropdown.settings[fId] = [fButton, fMaxWidth, fMaxHeight, fWidth, fHeight, fWidth, fHeight, 'up', false, -1, fButton.className, dropdown.defaults.buttonHoverClass, dropdown.defaults.posX, dropdown.defaults.posY];
		
		dropdown.position(fId);
	},
	defaults: {
		maxHeight:0,
		maxWidth:0,
		minHeight:0,
		minWidth:0,
		zIndex: 1000,
		posX: 'left',
		posY: 'bottom',
		tunePosX: 0,
		tunePosY: 0,
		buttonHoverClass: ''
	},
	resizenumber: 0,
	settings: new Array(),
	position: function(fId){
		if(dropdown.settings[fId][9] != dropdown.resizenumber){
			fButton = dropdown.settings[fId][0];
			fPosition = findPos(fButton);
			fWidth = fButton.offsetWidth;
			fHeight = fButton.offsetHeight;
			
			switch(dropdown.settings[fId][12]){
				case 'right':
					fLeft = fPosition[0] + fWidth;
					break;
				default: //left
					fLeft = fPosition[0];
					break;
			}
			switch(dropdown.settings[fId][13]){
				case 'top':
					fTop = fPosition[1];
					break;
				default: //botttom
					fTop = fPosition[1] + fHeight;
			}
			document.getElementById('dropdown'+ fId).style.top = (fTop + dropdown.defaults.tunePosY) +'px';
			document.getElementById('dropdown'+ fId).style.left = (fLeft + dropdown.defaults.tunePosX) +'px';
			dropdown.settings[fId][9] = dropdown.resizenumber;
		}
	},
	schuiven: {
		up: function(e, fId, fUp){
			if(!fId){
				if(ie){
					if(!e)
						e = window.event;
					fObject = e.srcElement;
					while(!(fId = fObject.dropdownid)){
						fObject = fObject.parentNode;
					}
				}
				else
					fId = this.dropdownid;
			}
			if(fUp){
				if(dropdown.settings[fId][7] == 'up')
					if(!dropdown.settings[fId][8])
						dropdown.schuiven.move(fId);
			}
			else{
				dropdown.settings[fId][7] = 'up';
				setTimeout('dropdown.schuiven.up(false, '+ fId +', true)', 50);
			}
		},
		move: function(fId){
			fDone = false;
			fDropdown 	= dropdown.settings[fId];
			fObject 	= document.getElementById('dropdown'+ fId);
			fWidth		= fDropdown[3];
			fHeight 	= fDropdown[4];
			fDirection	= fDropdown[7];
			
			if(fDirection == 'down'){
				if(fWidth < fDropdown[1]){
					fWidth += 20;
					if(fWidth > fDropdown[1])
						fWidth = fDropdown[1];
				}
				else if(fHeight < fDropdown[2]){
					fHeight += 20;
					if(fHeight > fDropdown[2])
						fHeight = fDropdown[2];
				}
				else
					fDone = true;
			}
			else{
				if(fHeight > fDropdown[6]){
					fHeight -= 40;
					if(fHeight < fDropdown[6])
						fHeight = fDropdown[6];
				}
				else if(fWidth > fDropdown[5]){
					fWidth -= 40;
					if(fWidth < fDropdown[5])
						fWidth = fDropdown[5];
				}
				else{
					fDone = true;
					dropdown.settings[fId][0].className = dropdown.settings[fId][10];
				}
			}
			
			fDropdown[3] = fWidth;
			fDropdown[4] = fHeight;
			fObject.style.width = fWidth +'px';
			fObject.style.height = fHeight +'px';
			fDropdown[8] = (fDone)?false:true;
			if(!fDone)
				setTimeout('dropdown.schuiven.move('+ fId +')', 40);
		},
		down: function(e){
			if(ie){
				if(!e)
					e = window.event;
				fObject = e.srcElement;
				while(!(fId = fObject.dropdownid)){
					fObject = fObject.parentNode;
				}
			}
			else
				fId = this.dropdownid;
			dropdown.position(fId);
			dropdown.settings[fId][7] = 'down';
			if(!dropdown.settings[fId][8]){
				
				dropdown.settings[fId][0].className = dropdown.settings[fId][11];
				dropdown.schuiven.move(fId);
			}
		}
	}
};