var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);

function windowWidth() {
	var body_width = 0, body_height = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		body_width = window.innerWidth;
//		body_height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
		body_width = document.documentElement.clientWidth;
//		body_height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
		body_width = document.body.clientWidth;
//		body_height = document.body.clientHeight;
	}
	return body_width;
//	window.alert( 'Width = ' + body_width );
//	window.alert( 'Height = ' + body_height );
}

function onResize(){
	var body_width = windowWidth();
	if (body_width <= 918){
		var star_left = 459;
	}else{
		var star_left = ((body_width - 918) / 2) + 459;
	}
	document.getElementById("star").style.backgroundPosition = parseInt(star_left)+"px 0";
}

function changeVisual(){
	var visual = document.getElementById("visual").value;
	if (visual=="3d"){
		document.getElementById("big_visual").src = "get.php?i." + images["2d_small"]["file_id"];
		document.getElementById("visual").value = "2d";
		document.getElementById("change_icon").src = "client/img/visual_3d.jpg";
	}else if (visual=="2d"){
		document.getElementById("big_visual").src = "get.php?i." + images["3d_small"]["file_id"];
		document.getElementById("visual").value = "3d";
		document.getElementById("change_icon").src = "client/img/visual_2d.jpg";
	}
//	alert(document.getElementById("change_icon").src);
}
function popup(url,windowWidth,windowHeight){
	myleft=(screen.width)?(screen.width-windowWidth)/2:100;
	mytop=(screen.height)?(screen.height-windowHeight)/2:100;
	properties = "width="+windowWidth+",height="+windowHeight+",scrollbars=no, status=0, top="+mytop+",left="+myleft;
	window.open(url,'popupas',properties)
}
 
function popups(url,windowWidth,windowHeight){
	myleft=(screen.width)?(screen.width-windowWidth)/2:100;
	mytop=(screen.height)?(screen.height-windowHeight)/2:100;
	properties = "width="+windowWidth+",height="+windowHeight+",scrollbars=yes, status=0, top="+mytop+",left="+myleft;
	window.open(url,'popupas',properties)
}
 
function zoomVisual(){
	var visual = document.getElementById("visual").value;
	if (visual=="3d"){
		popup("index.php?cid="+page_id+"&popup=1&img=" + images["3d_big"]["file_id"],images["3d_big"]["width"],images["3d_big"]["height"]);
	}else if (visual=="2d"){
		popup("index.php?cid="+page_id+"&popup=1&img=" + images["2d_big"]["file_id"],images["2d_big"]["width"],images["2d_big"]["height"]);
	}
}

function zoomVisualPrint(){
	var visual = document.getElementById("visual").value;
	if (visual=="3d"){
		popup(location.href + "&popup=1&pv=1&img=" + images["3d_big"]["file_id"],images["3d_big"]["width"],images["3d_big"]["height"]);
	}else if (visual=="2d"){
		popup(location.href + "&popup=1&pv=1&img=" + images["2d_big"]["file_id"],images["2d_big"]["width"],images["2d_big"]["height"]);
	}
}

function moreNecessity(){
	document.getElementById("more_pri").style.display = "block";
	document.getElementById("more").style.display = "none";
}

function priceFromTo(object){
	var objektas = object.options[object.selectedIndex].value;
	if (objektas){
		var value_array = objektas.split("-");
	}else{
		var value_array = new Array();
		value_array[0] = "";
		value_array[1] = "";
	}
	document.getElementById("sum_price_from").value = value_array[0];
	document.getElementById("sum_price_to").value = value_array[1];
}

function roomsFromTo(object){
	document.getElementById("rooms_from").value = object.options[object.selectedIndex].value;
	document.getElementById("rooms_to").value = object.options[object.selectedIndex].value;
}

function correctPNG() {
	if ((version >= 5.5) && (document.body.filters)){
		for(var i=0; i<document.images.length; i++){
			var img = document.images[i];
			var imgName = img.src.toUpperCase();
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
				var imgID = (img.id) ? "id=\"" + img.id + "\" " : "";
				var imgClass = (img.className) ? "class=\"" + img.className + "\" " : "";
				var imgTitle = (img.title) ? "title=\"" + img.title + "\" " : "title=\"" + img.alt + "\" ";
				var imgStyle = "display:inline-block; " + img.style.cssText;
				if (img.align == "left"){
					imgStyle = "float:left; " + imgStyle;
				}
				if (img.align == "right"){
					imgStyle = "float:right; " + imgStyle;
				}
				if (img.parentElement.href){
					imgStyle = "cursor:hand;" + imgStyle;
				}
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
				img.outerHTML = strNewHTML;
				i = i-1;
			}
		}
	}
}

function pngImages(){
	if(document.all){
		for(x=0;x < arguments.length;x++){
			elm = document.getElementById(arguments[x]);
			elm.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='" + elm.src + "')";
			elm.src = "images/blank.gif";
		}
	}
}

function hidenElements(){
	document.getElementById("more_pri").style.display = "none";
}