

function SetScrollOperator(obid,sizes,step) {
	var sop=this;
	this.obid=obid;
	this.wid=sizes[0];
	this.hei=sizes[1];
	sop.qscrollInterval=null;
	sop.interval=null;
	sop.step=step;
	
	$('#newsscr').css('height', 'auto');
	$('#newsscr').css('width', 'auto');
	$('#newsscr').css('overflow', 'visible');
	$('#scroller-wrapper .NavPanel').eq(0).remove();
	$('#scroller-wrapper .NavPanel').eq(0).remove();
	$('#newsscr').attr('id', 'custom'+parseInt(Math.floor(Math.random()*13456789)));

	sop.minDraggerHeight=5; 
	sop.arrHei=11; 

	sop.box=document.getElementById(obid);
	if(!sop.box) return;

	var obDivs=sop.box.getElementsByTagName('DIV');
	
	sop.box.innerHTML='<div>'+sop.box.innerHTML+'<\/div>'; 
	
	sop.obj=sop.box.getElementsByTagName('DIV')[0];
	
	sop.navPanel=document.createElement('DIV'); 
	sop.innerPanel=document.createElement('DIV');
	sop.dragger=document.createElement('SPAN'); 
	sop.arrup=document.createElement('SPAN'); 
	sop.arrdown=document.createElement('SPAN'); 
	sop.navPanel.className='NavPanel top-pagging';
	sop.dragger.className='dragger';
	sop.arrdown.className='arrdown';
	sop.arrup.className='arrup';

	sop.navPanel1=document.createElement('DIV'); 
	sop.innerPanel1=document.createElement('DIV');
	sop.dragger1=document.createElement('SPAN'); 
	sop.arrup1=document.createElement('SPAN'); 
	sop.arrdown1=document.createElement('SPAN'); 
	sop.navPanel1.className='NavPanel bottom-paging';
	sop.dragger1.className='dragger1';
	sop.arrdown1.className='arrdown1';
	sop.arrup1.className='arrup1';
	
	sop.navPanel.appendChild(sop.innerPanel);
	sop.navPanel.appendChild(sop.arrup);
	sop.navPanel.appendChild(sop.dragger);
	sop.navPanel.appendChild(sop.arrdown);
	sop.box.appendChild(sop.navPanel);

	sop.navPanel1.appendChild(sop.innerPanel1);
	sop.navPanel1.appendChild(sop.arrup1);
	sop.navPanel1.appendChild(sop.dragger1);
	sop.navPanel1.appendChild(sop.arrdown1);
	sop.box.appendChild(sop.navPanel1);

	sop.box.style.paddingRight='20px';
	sop.box.style.position='relative';

	sop.obj.style.overflow='hidden';
	sop.obj.style.position='relative';
	sop.obj.id=sop.obid+'scr';

	sop.navPanel.onselectstart=function() {return false;}
	sop.navPanel.onmousedown=function(event) {
		var myElement=(window.event ? window.event.srcElement : event.target);
		if(myElement.tagName!='DIV')
			return false;
	}

	sop.navPanel1.onselectstart=function() {return false;}
	sop.navPanel1.onmousedown=function(event) {
		var myElement=(window.event ? window.event.srcElement : event.target);
		if(myElement.tagName!='DIV')
			return false;
	}

	sop.setScales();


	sop.arrup.onmouseout=function() {sop.clearIntervals();}
	sop.arrup.onmouseover=function() {sop.Scroll('up',sop.step);}
	sop.arrup.onmousedown=function() {sop.obj.step=step+5;}
	sop.arrup.onmouseup=function() {sop.obj.step=step}

	sop.arrup1.onmouseout=function() {sop.clearIntervals();}
	sop.arrup1.onmouseover=function() {sop.Scroll('up',sop.step);}
	sop.arrup1.onmousedown=function() {sop.obj.step=step+5;}
	sop.arrup1.onmouseup=function() {sop.obj.step=step}

	sop.arrdown.onmouseout=function() {sop.clearIntervals();}
	sop.arrdown.onmouseover=function() {sop.Scroll('down',sop.step);}
	sop.arrdown.onmousedown=function() {sop.obj.step=step+5;}
	sop.arrdown.onmouseup=function() {sop.obj.step=step;}

	sop.arrdown1.onmouseout=function() {sop.clearIntervals();}
	sop.arrdown1.onmouseover=function() {sop.Scroll('down',sop.step);}
	sop.arrdown1.onmousedown=function() {sop.obj.step=step+5;}
	sop.arrdown1.onmouseup=function() {sop.obj.step=step;}
	
	sop.dragger.onmousedown=function(e) {
		sop.clearIntervals();
		var y=e?e.pageY:window.event.clientY;
		y-=sop.box.offsetTop;
		sop.dragger.cursorOffset=y-sop.dragger.offsetTop-sop.arrHei;

		document.onmouseup=function() {document.onmousemove=null;}

		var
			ind=true,
			constant1=sop.obj.scrollHei/(sop.obj.offsetHeight-(sop.arrHei*2+2)),
			constant2=sop.obj.offsetHeight-sop.dragger.offsetHeight-sop.arrHei,
			ToBotMax=sop.obj.offsetHeight - sop.dragger.offsetHeight - sop.arrHei
		;

		document.onmousemove=function(e) {
			var y=e?e.pageY:window.event.clientY; y-=sop.box.offsetTop+sop.arrHei;
			var coffsetpos=y-sop.dragger.cursorOffset;

			if(sop.dragger.offsetTop >= sop.arrHei && sop.dragger.offsetTop <= constant2) {
				if(coffsetpos<=sop.arrHei) {coffsetpos=sop.arrHei; sop.obj.scrollTop=0; ind=false;}
				if(coffsetpos>=ToBotMax) {coffsetpos=ToBotMax; sop.obj.scrollTop=sop.obj.scrollHei; ind=false;}
				sop.dragger.style.top=(coffsetpos)+'px';
				if(ind) sop.obj.scrollTop=(sop.dragger.offsetTop-(sop.arrHei-1))*constant1;
				ind=true;
			}
		}
	}


	sop.navPanel.onmouseup=function(e) {
		var myElement=(window.event ? window.event.srcElement : e.target);
		if(myElement.tagName!='SPAN') {
			sop.clearIntervals();
			var y=e?e.pageY:window.event.clientY-2;
			y-=sop.box.offsetTop;

			if(window.event)
				y+=document.documentElement.scrollTop?
					document.documentElement.scrollTop:
					document.body.scrollTop
				;


			if(y<sop.arrHei || y>sop.obj.offsetHeight-sop.arrHei) return;


			var QHei=sop.dragger.offsetHeight;
			var flag=(sop.dragger.offsetTop<y)?1:-1;
			sop.qscrollInterval=window.setInterval(
				function() {
					var Top=sop.dragger.offsetTop;
					if(Top+QHei>=y && flag>0) return sop.clearIntervals();
					if(Top<=y && flag<0) return sop.clearIntervals();

					var qstep=2;
					if(QHei<=flag*(y-Top)/2) qstep=3;
					if(QHei<=flag*(y-Top)/3) qstep=4;
					sop.dragger.style.top=(Top+qstep*flag)+'px';
					sop.obj.scrollTop=(Top-(sop.arrHei-1))*sop.obj.scrollHei/(sop.obj.offsetHeight-(sop.arrHei*2+2));
				}
			,1);
		}
	}


	sop.mWheel=function(e) {
		sop.clearIntervals();
		var e=(!e)?window.event:e;
		var opera = ( window.opera );
		var delta=false;

		if(e.wheelDelta) delta=e.wheelDelta/120*opera;
		else if(e.detail) delta=e.detail/-3;

		if(delta) {
			if(e.preventDefault)
				e.preventDefault();
			e.returnValue=false;
	
			sop.obj.scrollTop+=-delta*20;
			if(sop.obj.scrollTop==0)
				sop.dragger.style.top=sop.arrHei+'px';
			else
				sop.dragger.style.top=(Math.ceil(sop.obj.scrollTop*(sop.obj.offsetHeight-(sop.arrHei*2+2))/sop.obj.scrollHei)+(sop.arrHei-1))+'px';
		}
	}

	if(window.addEventListener)
		sop.box.addEventListener('DOMMouseScroll',sop.mWheel,false);
	sop.box.onmousewheel=sop.mWheel;


	sop.imgs=sop.box.getElementsByTagName('IMG');
	for(var i=0; i<sop.imgs.length; i++)
		sop.imgs[i].onload=function() { sop.setScales(); }
		
	var p = $('#newsscr .active-link');
	var offset = p.position();
	sop.obj.scrollTop = offset.top;
}

SetScrollOperator.prototype.setScales=function() {
	var sop=this;


	sop.box.style.width=sop.wid+'px';
	sop.box.style.height=sop.hei+'px';


	sop.obj.style.width=sop.wid+'px';
	sop.obj.scrollHei=sop.obj.scrollHeight;
	sop.obj.style.height=sop.hei+'px';


	sop.dragger.id=sop.obid+'dragger';
	if(sop.obj.scrollHei<=sop.hei) {
		sop.navPanel.style.display='none';
		sop.navPanel1.style.display='none';
	} else {
		sop.navPanel.style.display='block';
		sop.navPanel1.style.display='block';
		sop.dragger.style.height=Math.ceil(sop.hei*(sop.hei-(sop.arrHei*2+2))/sop.obj.scrollHei)+'px';
		if(sop.dragger.offsetHeight<sop.minDraggerHeight)
			sop.dragger.style.height=sop.minDraggerHeight+'px';
	}
	sop.dragger.style.top=sop.arrHei+'px';
}


SetScrollOperator.prototype.Scroll=function(dir,step) {
	var sop=this;

	sop.obj.step=step;
	sop.clearIntervals();
	sop.interval=window.setInterval(
		function() {
			switch(dir) {
				case 'up': sop.obj.scrollTop-=sop.obj.step; break;
				case 'down': sop.obj.scrollTop+=sop.obj.step; break;
			}
			if(sop.obj.scrollTop==0)
				sop.dragger.style.top=sop.arrHei+'px';
			else
				sop.dragger.style.top=(Math.ceil(sop.obj.scrollTop*(sop.obj.offsetHeight-(sop.arrHei*2+2))/sop.obj.scrollHei)+(sop.arrHei-1))+'px';
		}
	,1);
}


SetScrollOperator.prototype.clearIntervals=function() {
	window.clearInterval(this.qscrollInterval);
	window.clearInterval(this.interval);
	return true;
}


/////////////////// sandh

/*
* Problem with height of column
*/
$(document).ready( function() {
    var cnt = $('div.links').length;
	for (var i = 0; i < cnt; i += 2)
	{
		var tmpH = 0;

		if( $('div.links').eq(i).height() > tmpH ) tmpH = $('div.links').eq(i).height();

		if( $('div.links').eq(i+1).height() > tmpH ) tmpH = $('div.links').eq(i+1).height();
		$('div.links').eq(i).css('height', (tmpH + 0 ) + "px");
		$('div.links').eq(i+1).css('height', (tmpH + 0 )+ "px");
	}
});

/*
* Problem with height of column
*/
$(document).ready( function() {
    var cnt = $('div.clients').length;
	for (var i = 0; i < cnt; i += 1)
	{
		var tmpH = 0;

		if( $('div.clients').eq(i).height() > tmpH ) tmpH = $('div.clients').eq(i).height();

		if( $('div.clients').eq(i+1).height() > tmpH ) tmpH = $('div.clients').eq(i+1).height();
		$('div.clients').eq(i).css('height', (tmpH + 0 ) + "px");
		$('div.clients').eq(i+1).css('height', (tmpH + 0 )+ "px");
	}
});

/*
* Problem with height of column
*/
$(document).ready( function() {
    var cnt = $('div.press').length;
	for (var i = 0; i < cnt; i += 2)
	{
		var tmpH = 0;

		if( $('div.press').eq(i).height() > tmpH ) tmpH = $('div.press').eq(i).height();

		if( $('div.press').eq(i+1).height() > tmpH ) tmpH = $('div.press').eq(i+1).height();
		$('div.press').eq(i).css('height', (tmpH + 0 ) + "px");
		$('div.press').eq(i+1).css('height', (tmpH + 0 )+ "px");
	}
});


/*
* Fade Header Effect
*/
$(document).ready(
	function(){
		$('ul#portfolio').innerfade({
			speed: 1000,
			timeout: 5000,
			type: 'sequence',
			containerheight: '262px'
	});
});

$(document).ready(function() { 
	$('#news ul li.status-0').show();
	$('#news ul li.status-1').hide();
	$('#news').show('slow');
	$('a.current').click(function(){ 
		$(this).css('font-weight', '600');
		$(this).css('text-decoration', 'none');
		$(this).css('color', '#858585');
		$('a.completed').css('font-weight', '400');
		$('a.completed').css('color', '#B4B4B4');
		$('#news').hide();
		$('#news ul li.status-1').css('display', 'none');
		$('#news ul li.status-0').show();
		$('#news').show('slow');
		return false;
	});
	$('a.completed').click(function(){ 
		$(this).css('font-weight', '600');
		$(this).css('text-decoration', 'none');
		$(this).css('color', '#858585');
		$('a.current').css('font-weight', '400');
		$('a.current').css('color', '#B4B4B4');
		$('#news').hide();
		$('#news ul li.status-0').css('display', 'none');
		$('#news ul li.status-1').show();
		$('#news').show('slow');
		return false;
	});
});


/*
* News&Projects Scroll
*/

//new SetScrollOperator('news',[358,375],1);

/*
* Dynamic AJAX Content
*/
function loadContentProjects(id, client) {
	$('#show-title-projects a').css('background', 'none');
	$('#show-title-projects a#projects_'+id).css('background', '#d2d2d2');
	$('#show-title-projects a').removeClass('active-link');
	$('#show-title-projects a#projects_'+id).addClass('active-link');
	//$('.title_en').html('<iframe frameborder="0" scrolling="no" src="ajax-projects-title/'+id+'" style="float: left; width:460px; height: 32px; border: 0;"></iframe>');
	$('.title_en').html('<ul id="site-title"><li>'+page_title+'</li></ul>');

	$('.title-section .nambers').load('ajax-projects-namber/'+id);
	$('.show-content-projects').load('/ajax-projects/'+id, function() {
		var rhg_box = parseInt($('.show-content-projects').height());
		rhg_box = rhg_box - parseInt($('.show-content-projects h1').height()) - 6;
		if(rhg_box < 100) rhg_box = 100;
		new SetScrollOperator('news',[358,rhg_box],1);
	});
	$('#header').html('<iframe frameborder="0" scrolling="no" src="ajax-projects-header/'+id+'" style="width:917px; height: 368px; border: 0;"></iframe>');
	clearInterval(imageInterval);
	delete imageInterval;
}

/*
* Dynamic AJAX Content
*/
function loadContentSustainability(id, client) {
	$('#show-title-projects a').css('background', 'none');
	$('#show-title-projects a#projects_'+id).css('background', '#d2d2d2');
	$('#show-title-projects a').removeClass('active-link');
	$('#show-title-projects a#projects_'+id).addClass('active-link');
	//$('.title_en').html('<iframe frameborder="0" scrolling="no" src="ajax-sustainability-title/'+id+'" style="float: left; width:460px; height: 32px; border: 0;"></iframe>');
	$('.title_en').html('<ul id="site-title"><li>'+page_title+'</li></ul>');

	$('.title-section .nambers').load('ajax-sustainability-namber/'+id);
	$('.show-content-projects').load('/ajax-sustainability/'+id, function() {
		var rhg_box = parseInt($('.show-content-projects').height());
		rhg_box = rhg_box - parseInt($('.show-content-projects h1').height()) - 6;
		if(rhg_box < 100) rhg_box = 100;
		new SetScrollOperator('news',[358,rhg_box],1);
	});
	$('#header').html('<iframe frameborder="0" scrolling="no" src="ajax-sustainability-header/'+id+'" style="width:917px; height: 368px; border: 0;"></iframe>');
	clearInterval(imageInterval);
	delete imageInterval;
}

/*
* Dynamic AJAX Content
*/
function loadContentNews(id) {
	$('#show-title-news a').css('background', 'none');
	$('#show-title-news a#news_'+id).css('background', '#d2d2d2');
	$('#show-title-news li').removeClass('active-link');
	$('#show-title-news a#news_'+id).parent().addClass('active-link');
	//$('.title-section').html('<iframe frameborder="0" scrolling="no" src="/ajax-news-title/'+id+'" style="float: left; width:460px; height: 32px; border: 0;"></iframe>');
	$('.title-section').html('<ul id="site-title"><li>'+page_title+'</li></ul>');
	
	$('.show-content-news').load('/ajax-news/'+id, function() {
		var rhg_box = parseInt($('.show-content-news').height());
		rhg_box = rhg_box - parseInt($('.show-content-news h1').height()) - 6;
		if(rhg_box < 100) rhg_box = 100;
		new SetScrollOperator('news',[358,rhg_box],1);
	});
	$('#header').html('');
	$('#header').append('<iframe frameborder="0" border="0" scrolling="no" src="ajax-news-header/'+id+'" style="width:917px; height: 368px; border: 0; padding: 0; margin: 0;"></iframe>');
}

/*
* Dynamic AJAX Content
*/
function loadContentPress(id) {
	$('#show-title-news a').css('background', 'none');
	$('#show-title-news a#press_'+id).css('background', '#d2d2d2');
	$('#show-title-news a').removeClass('active-link');
	$('#show-title-news a#press_'+id).addClass('active-link');
	$('.title-section').html('<iframe frameborder="0" scrolling="no" src="/ajax-press-title/'+id+'" style="float: left; width:460px; height: 32px; border: 0;"></iframe>');
	$('.title-section').html('<ul id="site-title"><li>'+page_title+'</li></ul>');
	
	$('.show-content-news').load('/ajax-press/'+id, function() {
		var rhg_box = parseInt($('.show-content-news').height());
		rhg_box = rhg_box - parseInt($('.show-content-news h1').height()) - 6;
		if(rhg_box < 100) rhg_box = 100;
		new SetScrollOperator('news',[358,rhg_box],1);
	});
	$('#header').html('');
	$('#header').append('<iframe frameborder="0" border="0" scrolling="no" src="ajax-press-header/'+id+'" style="width:917px; height: 368px; border: 0; padding: 0; margin: 0;"></iframe>');
}

/*
* Dynamic AJAX Content
*/
function loadContentImage(id, name) {
	$('#header').html('<img src="/images/phpThumb.php/q=100;zc=1;917x368;/var/'+id+'" style="width:917px; height: 368px;" />');
	var nameALT = $('.title-section h1#'+name).html();
	//$('.title_en').html('<h1 style="float: left;">'+nameALT+'</h1>');
}


