window.onload = resize;
window.onresize = resize;
window.onload = load;

// Resizers

function resize()
{
	var sizes = getPageSizes();
	var img_h = $('#bg_img img').height();
	var img_w = $('#bg_img img').width();
	//alert('s: ' + sizes[0] + ' : ' + sizes[1] + "\n" + img_w + ' : ' + img_h);
	var h_body = parseInt($('body').height());
	var hh = h_body;
	
	//var h_wrapper = parseInt($('#wrapper').height());
	//alert(sizes + '\n' + 'img: ' + img_w + ' x ' + img_h + '\n' + h_body + '\n' + h_wrapper);
	
	var iev = getIEVersion();
	if (iev !== false)
	{
		if (iev < 7)
		{
			var h_wrapper = parseInt($('#wrapper').height());
			hh = sizes[1];
			if (hh < h_wrapper)
			{
				hh = h_wrapper;
			}
		}
	}
	
	if (img_h < hh) {
		$('#bg_img img').css({ height: hh+'px' });
		//$('#bg_img img').css({ height: '100%' });
		$('#bg_img img').css({ width: 'auto' });
	} else {
		$('#bg_img img').css({ height: 'auto' });
		$('#bg_img img').css({ width: '100%' });
	}
	
}


// Main Submeniu

function load()
{
	$("#menu li.first").click(function(){
		$(this).parent().find('ul li').css("display","none");
		$(this).find('li').css("display","block");
	});
	resize();
}


// Puslapio stiliai

function changeStyle(style)
{
	$("#body").removeClass("style_1");
	$("#body").removeClass("style_2"); 
	$("#body").removeClass("style_3"); 
	$("#body").addClass("style_"+style); 
}

function getPageSizes() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

function getPageScrolls() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}

function getIEVersion()
{
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	if (isIE)
	{
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		{
			rv = parseFloat( RegExp.$1 );
			return rv;
		}
	}
	
	return false;
}

