function publClick(which, where){
	if(where != ''){
		which = where + "/" + which;
	}

	window.location = "/publication/" + which + "/";	
}


function publBlockOver(el){
	newsBlockOver(el);
}


function publBlockOut(el){	
	newsBlockOut(el);
}

function newsClick(which, where){
	if(where != ''){
		which = where + "/" + which;
	}

	window.location = "/news/" + which + "/";	
}


function newsBlockOver(el){
	if(Element.hasClassName(el, 'newsBlock')){
		el.className = 'newsBlockActive';
	}
}


function newsBlockOut(el){	
	if(Element.hasClassName(el, 'newsBlockActive')){
		el.className = 'newsBlock';
	}
}


function factoryDescrBlockOver(el){
	el.style.backgroundColor = '#7d9899';
}


function factoryDescrBlockOut(el){
	el.style.backgroundColor = '#636466';
}


function factoryClick(where){
	window.location = where;
}

var bgImage = '';
function factoryBlockOver(el, msss){
  if (sflg==1){factoryBlockOut(cmd_div)}
	if(Element.hasClassName(el, 'factoryTypeBlock')){
		el.className = 'factoryTypeBlockActive';
		bgImage = el.style.backgroundImage;
		el.style.backgroundImage = '';
		var txt = $A(el.getElementsByTagName('DIV'));
		if(txt.length > 0){
			if(txt[0].id.indexOf('descr') != -1){
				Element.show(txt[0]);
			}
		}
	}
 cmd_div=el;
 olep = cmd_div.innerHTML;
 cmd_div.innerHTML=msss;
 sflg=1;
}


function factoryBlockOut(el){	
cmd_div=el;
cmd_div.innerHTML = olep;
	if(Element.hasClassName(el, 'factoryTypeBlockActive')){
		el.className = 'factoryTypeBlock';
		el.style.backgroundImage = bgImage;
		var txt = $A(el.getElementsByTagName('DIV'));
		if(txt.length > 0){
			if(txt[0].id.indexOf('descr') != -1){
				Element.hide(txt[0]);
			}
		}
	}
 sflg=0;
}


function scrollPubl(which, selected, where){
	scrollStrip(which, selected, where, 'publ');
}

function scrollNews(which, selected, where){
	scrollStrip(which, selected, where, 'news');
}

function scrollStrip(which, selected, where, section){
	var unique = (new Date()).getTime();
	var url = '/get_page.php';
	var pars = 'where=' + where + '&mode=scroll&which=' + which + '&selected=' + selected + '&section=' + section + '&unique=' + unique;
	
	var myAjax = new Ajax.Updater(
	        'scrollNewsBlock',
	        url,
	        {
	                method: 'get',
	                parameters: pars,
	                evalScripts: true
	        }
	);
}


function changePublViewType(type, where, selected){
	changeViewType(type, where, selected, 'publ');
}

function changeNewsViewType(type, where, selected){
	changeViewType(type, where, selected, 'news');
}

function changeViewType(type, where, selected, section){
	var unique=(new Date()).getTime();
	var url = '/get_page.php';
	var pars = 'where=' + where + '&mode=viewtype&type=' + type + '&which=' + selected + '&selected=' + selected + '&section=' + section + '&unique=' + unique;
	
	var myAjax = new Ajax.Updater(
			'contentBlock',
	        url,
	        {
	                method: 'get',
	                parameters: pars,
	                evalScripts: true,
	                onComplete: function(){
	                	if(type != 1 && blockWidth == 0){
	                		var list = $A($$('#trueContainer IMG'));
		
							list.each(function(n){
								n.onload = function (evt) {
									blockWidth += this.width + 2;
									if(n == list.last()){
										blockWidth += $('container').getWidth() - this.width;		
									}
								};
							});							
	                	}
	                	initLightbox();
	                }
	        }
	);	

	
	if(type == 1){
		$('contentBlock').className = 'oneColumn';
		$('viewType1').src = '/i/view-type-1-a.gif';
		$('viewType2').src = '/i/view-type-2.gif';
		$('scrollNewsBlock').innerHTML = '<div id="scrollNewsBlock"><div class="scrollButtonEmp"><spacer /></div></div>';
	} else {
		$('contentBlock').className = 'twoColumns';
		$('viewType1').src = '/i/view-type-1.gif';
		$('viewType2').src = '/i/view-type-2-a.gif';
		
		scrollStrip(selected, selected, where, section);
	}
}

var factoryData = new Array();
function displayFactoryDescription(which, section){
	var unique = (new Date()).getTime();
	var url = '/get_page.php';
	var pars = 'mode=factory' + '&which=' + which + '&section=' + section + '&unique=' + unique;
	
	var el = $$('#contentBlock .factoryDescrBlock');
	factoryDescrBlockOut(el[0]);
	
	factoryData[which] = $('contentBlock').innerHTML;
	
	var myAjax = new Ajax.Updater(
			'contentBlock',
	        url,
	        {
	                method: 'get',
	                parameters: pars,
	                evalScripts: true
	        }
	);		
}

function restoreFactory(which){
	$('contentBlock').innerHTML = factoryData[which];
}


function scrollToSlide(which){
	scrollNavigation(which);
	
	var el = $('slide' + which);
	var list = $A($$('#trueContainer IMG'));
	var shift = 0;
	list.find(function(n){
		shift += n.getWidth() + 2;
		return n.getAttribute('id') == 'slide' + which;
	});
	shift -= el.getWidth() + 2;
	
	var currentPosition = Math.abs(parseFloat($('pict').getStyle('left') || 0));
	
	shift = currentPosition - shift;
	
	if(Math.abs(shift) > 0){
		var value = ((currentPosition - shift)*100/(blockWidth - $('container').getWidth() - 2))/100;
		gallery.setValue(value, 0);
	}
	
	$('pict').makePositioned();
	
	new Effect.MoveBy($('pict'), 0, shift, {
	    duration: 1,
		afterFinish: function() {									
		}
	});
}

function scrollNavigation(page){
	var pager = $A($$('#container .caption A'));
	pager.each(function(n, i){
		n.className = (i+2)!= page ? '' : 'active';
	});	
}

function changeActivity(which, state){
	var el = $('img' + which);
	if(el){
		if(state != '') which = which + '-' + state;
		el.src = '/i/m-' + which + '.gif';
	}
}


var blockWidth = 0;
var gallery;
function sliderInit(){
	$('container').makeClipping();
	
	Event.observe(window, 'load', function() {
		var list = $A($$('#trueContainer IMG'));
		
		list.each(function(n){
			blockWidth += n.getWidth() + 2;
		});
		blockWidth += $('container').getWidth() - (list.last()).getWidth();
	});
	
	gallery = new Control.Slider('handle', 'track', {axis: 'horizontal', 
		onSlide: function(value, o){
			$('pict').makePositioned();
			var movement = ((blockWidth - $('container').getWidth()) * Math.round(value * 100)) / 100;
			
			var currentPosition = parseFloat($('pict').getStyle('left') || 0);
			movement = Math.abs(currentPosition) - movement;
			
			if(currentPosition + movement > 0){
				movement = 0 - currentPosition;	
			}

			var list = $A($$('#trueContainer IMG'));
			var w = 0;
			var currentPage = list.find(function(n){
				w += n.getWidth() + 2;
				return w >= Math.abs(currentPosition + movement) + 3;
			});
			
			currentPage = currentPage.id.replace('slide', '');
			scrollNavigation(currentPage);
			
			$('pict').setStyle({left: (currentPosition + movement) + 'px'});
		}
	});
}

function changeCopyState(s){
	$('copyright').src = (s == 0) ? $('copyright').src.replace('-a', '-p') : $('copyright').src.replace('-p', '-a');
}

