
window.onload = prelaud;
window.onresize = resize;

var image_url;
// ---------------------- Prelauder -----------------------------

function prelaud() {
	if (image_url)
	{
		preloadimages(image_url);
	}
	resize();
}
	var h=1;
	//var image_url = new Array;
	

	function preloadimages(){

			var image = new Image();

			image.onload = function() {
				
			imagesLoaded(image_url[h],h);
			};
			image.src = "/uploads/catalog/"+image_url[h];


    }


	function imagesLoaded(src,a)
	{
		if (h<image_url.length)
		{
			h += 1;
			setTimeout('preloadimages()',100);
			//preloadimages();
		}
		document.getElementById('work_'+a).style.background = "#fff url(/uploads/catalog/"+src+") no-repeat";
		
		//$("#work_"+a).fadeIn("fast"); 
	};

// ---------------------- END Prelauder -----------------------------

// ---------------------- Lango dydis -----------------------------

function resize()
{
	if (document.getElementById('main'))
		{

			if (document.body.clientHeight < 700) {
				document.getElementById('main').style.height = '553px';
	
			} else {
				document.getElementById('main').style.height = document.body.clientHeight - 143 + 'px';
			}

			if (document.body.clientWidth < 1150) {

				document.getElementById('holder').style.width = '940px';
				document.getElementById('main_left').style.width = '669px';
			} else {

				document.getElementById('holder').style.width = '1140px';
				document.getElementById('main_left').style.width = '869px';
			}
			
			if (document.body.clientHeight < 601) {
				//document.getElementById('main').style.top = '-40px';
				document.getElementById('slide_ul').style.height = '400px';
			}	

			else if (document.body.clientHeight > 600 && document.body.clientHeight < 813) {
				//document.getElementById('main').style.top = (document.body.clientHeight - 900)/8 + 'px';
				document.getElementById('slide_ul').style.height = document.body.clientHeight - 200 + 'px';
			}
			
			else {
				//document.getElementById('main').style.top = (document.body.clientHeight - 900)/8 + 'px';
				document.getElementById('slide_ul').style.height = '609px';
			}

		} 
	else {
		s.recalculate();
	}

	if (document.getElementById('text_w'))
	{
		if (document.body.clientWidth < 1080) {
			document.getElementById('text_w').style.display = 'none';
		}
		if (document.body.clientWidth > 1080) {
			document.getElementById('text_w').style.display = 'inline';
		}
	}

	document.getElementById('scroller').style.width = scroller_width + 'px';

	if (document.body.clientWidth > scroller_width) {
		$("#handle").addClass("handle_off")
			document.getElementById('anim_arrow').style.display = 'none';
	} else {
			$("#handle").removeClass("handle_off");
			document.getElementById('anim_arrow').style.display = 'block';
	}
	// skaicius 15 - darbu skaicius sarase

	if (document.body.clientHeight < 600) {
		if (document.getElementById('works_list')){
		document.getElementById('works_list').style.height = '395px';
		}
		if (document.getElementById('work_footer'))
		{
			document.getElementById('work_footer').style.top = '498px';
		}

	}

	if (document.body.clientHeight > 600) {
		if (document.getElementById('works_list')){
			document.getElementById('works_list').style.height = document.body.clientHeight - 198 + 'px';
		}
		if (document.getElementById('work_footer'))
		{
			document.getElementById('work_footer').style.top = document.body.clientHeight - 102 + 'px';
		}
		
	} 


	if (document.getElementById('services')){

		document.getElementById('services').style.width = document.body.clientWidth - 180 + 'px';

		if (document.body.clientHeight < 622) {
			document.getElementById('services').style.height = '418px';
			if (document.getElementById('service_sub_menu')){document.getElementById('service_sub_menu').style.height = '418px';};
		} 

		else	{
			document.getElementById('services').style.height = document.body.clientHeight - 198 + 'px';
			if (document.getElementById('service_sub_menu')){document.getElementById('service_sub_menu').style.height = document.body.clientHeight - 198 + 'px';};
		}

		if (document.getElementById('scroller').clientWidth < document.body.clientWidth) {
				if (document.getElementById('service_sub_menu')){
					document.getElementById('service_sub_menu').style.display = 'none';
					document.getElementById('scroller').style.width = document.getElementById('scroller').clientWidth - 210 + 'px';
					};
					document.getElementById('services').className='no_sub';
			} else {
				if (document.getElementById('service_sub_menu')){document.getElementById('service_sub_menu').style.display = 'block';};
					document.getElementById('services').className='sub';
		}
	
	}
}

// ---------------------- End Lango dydis -----------------------------

// ---------------------- Mouse Wheel ---------------------------------

// --------- FF ------------

var sroll, t1;
var tween = 0;
var sroll_ff = 0;
var sroll_ie = 0;
window.addEventListener('DOMMouseScroll', scroll, false);

function scroll(e){
	sroll_ff = s.getValue();
//sroll = (document.getElementById('works_list').scrollLeft+e.detail*100)*100/(scroller_width-document.body.clientWidth);
if (e.detail>0)
{
	if (sroll_ff<100)
	sroll_ff = sroll_ff+Math.ceil(10000/scroller_width);
} 
else {
	if (sroll_ff>0)
	sroll_ff = sroll_ff-Math.ceil(10000/scroller_width);
}
	tween = 1;
	slider(sroll_ff,tween);
}

// --------- IE ------------ 

function srollewheel (id)
{
	sroll_ie = s.getValue();
	//sroll = (document.getElementById(id).scrollLeft-event.wheelDelta*3)*100/(scroller_width-document.body.clientWidth);
	if (event.wheelDelta<0)
{
	if (sroll_ie<100)
	sroll_ie = sroll_ie+Math.ceil(10000/scroller_width);
} 
else {
	if (sroll_ie>0)
	sroll_ie = sroll_ie-Math.ceil(10000/scroller_width);
}
	tween = 1;
	slider(sroll_ie,tween);
}

// ---------------------- End Horizontalus skrolas ------------------------

// ---------------------- Slider ------------------------------------------

function  slider(Value,tween) {
	
		if (t1) {
		t1.stop();
	}

	if (document.getElementById('works_list')){
		if (tween>0) {
			
			t1 = new Tween(document.getElementById("works_list"),'scrollLeft',Tween.regularEaseOut,document.getElementById("works_list").scrollLeft,(scroller_width-document.body.clientWidth)*Value/100,0.5,'');

			s.setValue(Value);
			t1.start();
			
		} else {
			document.getElementById('works_list').scrollLeft = (scroller_width-document.body.clientWidth)*Value/100;
		}
	}
	if (document.getElementById('services')){
		if (tween>0) {
			
			t1 = new Tween(document.getElementById("services"),'scrollLeft',Tween.regularEaseOut,document.getElementById("services").scrollLeft,(scroller_width-document.body.clientWidth)*Value/100,0.5,'');
			s.setValue(Math.round(Value));
			t1.start();
			
		} else {
			document.getElementById('services').scrollLeft = (scroller_width-document.body.clientWidth)*Value/100;
		}
	}
}

// ---------------------- End Slider --------------------------------------
