myrules = {
	'.sub' : function(el){
		el = $(el);
		el.onmouseover = function(){
			this.addClassName("orange");
			return false;
		}
		el.onmouseout = function(){
			this.removeClassName("orange");
			return false;
		}
	},
	
	'.super' : function(el){
		el = $(el);
		el.onmouseover = function(){
			this.addClassName("orange");
			return false;
		}
		el.onmouseout = function(){
			this.removeClassName("orange");
			return false;
		}
	},
	
	'.morelink' : function(el){
		el = $(el);
		el.onmouseover = function(){
			this.style.color="#FFFFFF";
			this.style.backgroundColor="#666666";
			return false;
		}
		el.onmouseout = function(){
			this.style.color="#FF6633";
			this.style.backgroundColor="#EFEFEF";
			return false;
		}
		el.onclick = function(){
			if(this.id!=moreBlock.id){
				moreBlock.hide();
				var foo = $(el.id.substring(1));
				moreBlock = foo;
				foo.show();
			}
			return false;
		}
	},
	
	'.back' : function(el){
		el = $(el);
		el.onmouseover = function(){
			this.style.color="#FFFFFF";
			this.style.backgroundColor="#666666";
			return false;
		}
		el.onmouseout = function(){
			this.style.color="#FF6633";
			this.style.backgroundColor="#EFEFEF";
			return false;
		}
	}
}

Behaviour.register(myrules);

var scrollInterval;
var upPos;
var downPos;
var scrolled;
var scroller;
var activeMenuIndex;
var right_scroll;

function init(){
	Behaviour.apply();
	activeSubmenu = null;
	
	if($('descr')) moreBlock = $('descr');
	
	initSubMenu();
	
	activeMenuIndex = window.location.search;
	var pos = activeMenuIndex.indexOf('&id=');
	activeMenuIndex = pos == -1 ? activeMenuIndex.substr(activeMenuIndex.indexOf('pg=')+3) : activeMenuIndex.substring(activeMenuIndex.indexOf('pg=')+3,pos);
	
	if(activeSubmenu) {
		showSubmenu(activeSubmenu);
	} else {
		
		if(activeMenuIndex){
			var activeMenuItem = $('hd_project').getElementsByClassName(activeMenuIndex);
			activeMenuItem = activeMenuItem[0];
			if(activeMenuItem){
				activeMenuItem.toggleClassName('a_orange');
			}
			delete activeMenuIndex;
		}
		
	}
	
	var delta = 3;
	scrolled = right_scroll ? $('bd_right') : $('bd_content');
	delete right_scroll;
	var needScroll = parseInt($('bd').getDimensions().height)+delta < parseInt(scrolled.getDimensions().height);
	if(needScroll) {
		scroller = $('scroll');
		upPos = parseInt($('bd').getDimensions().height)-parseInt(scrolled.getDimensions().height);
		downPos = 0;
		count = downPos;
		scroller.setStyle({display:"block"});
	}	
}

function initSubMenu(){
	var s = $('hd_project').getElementsByClassName('sub').each(function(n) {n.makePositioned()});
	s.each(function(n) {n.getElementsByClassName('secondmenu').each(function(n) {
																if(n.id==active) activeSubmenu = n.up();
																n.hide(); n.style.visibility="visible";
															});
												 });
}

function showSubmenu(e){
	if(activeSubmenu) switchSubmenu(activeSubmenu,false);
	activeSubmenu = e;
	switchSubmenu(e,true);
}

function switchSubmenu(e,isShow){
	var e = $(e);
	//isShow ? e.addClassName('orange') : e.removeClassName('orange');
	e.getElementsByClassName('secondmenu').each(function(n){
							 isShow ? n.show() : n.hide();
							 var delimiter_div = n.up().previous();
							 if(n.visible()){
								 delimiter_div.style.height = 101;
								 delimiter_div.style.marginTop=11;
								 
								 if(activeMenuIndex){
									 var activeSubmenuItem = n.down(1).getElementsByClassName(activeMenuIndex);
									 activeSubmenuItem[0].addClassName('orange');
									 delete activeMenuIndex;
								 }
							 } else {
								 delimiter_div.style.height = 10;
								 delimiter_div.style.marginTop=101;
							 }
						});
	
}

// RIBBER OF IMAGES

function showWork(id, url){
	var noo =  $('thumbimager');
	if(noo.style.display = "none") noo.style.display = "block";
}

function hideWork(){
	$('thumbimager').hide();
}

function showContacts(){
	var noo = $('contacts_');
	noo.style.visibility == "visible" ? noo.style.visibility = "hidden" : noo.style.visibility = "visible";
 }
// SCROLLING

function scrollUp(){
	if(count<downPos){
		count++;
		scrolled.setStyle({top: count+'px'});
	}
}

function scrollDown(){
	if(count>upPos){
		count--;
		scrolled.setStyle({top: count+"px"});
	}
}

function startScroll(isUp){
	if(isUp){
		scrollUp();
		scrollInterval = window.setInterval(scrollUp,10);
	} else {
		scrollDown();
		scrollInterval = window.setInterval(scrollDown,10);
	}
}

function stopScroll(){
	clearInterval(scrollInterval);
}



