//insert to favorites
function bookmarksite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}




/* include js */

//jquery
//include_js('js/jquery.js');
//include_js('js/jquery.cycle.all.js');



//make home
$(document).ready(function(){
	
	//form submit
	if($("#search_form_1").length){
		search_form_help("#search_form_1");
		$("#search_form_1").submit(function(){						
			search_form_help_clear("#search_form_1");
		});	
	}
	if($("#search_form_2").length){
		search_form_help("#search_form_2");
		$("#search_form_2").submit(function(){						
			search_form_help_clear("#search_form_2");
		});	
	}
	
	if($("#search_map_form_1").length){
		search_form_help("#search_map_form_1");
		$("#search_map_form_1").submit(function(){						
			search_form_help_clear("#search_map_form_1");
		});	
	}
	
	if($("#weather_city_select").length){
		//weather block list box
		$("#weather_city_select").jListbox();
		
		$("#weather_city_select").change(function(){
			$("#weather_block_list .weather").addClass("hide");
			$("#weather_block_list_item"+$(this).attr("value")).removeClass("hide");
		});
	}
	
});


//map popup
var fw=760
var fh=550
if (window.screen) {
   fw = window.screen.availWidth-40;
   fh = window.screen.availHeight-80;
}


/*

//Search form tabs
$(document).ready(function(){
	$("#PaieskosAnketa > ul").tabs();
	$('#PaieskosAnketa > ul').bind('tabsselect', function(event, ui) {
		//location.href = ui.tab.href.split('#')[0];
		if(ui.index == 0 || ui.index == 1){
			new_location = ui.tab.href.split('#')[0];
			if(location.href != new_location){
				location.href = new_location;
				return false;
			}
			//return false;
		}
		//if(ui.index == 1){
		//	location.href = 'index.php?page=zemelapiai_c&view=greita';
		//	return false;
		//}
    //ui.options // options used to intialize this widget
    //ui.tab // anchor element of the selected (clicked) tab
    //ui.panel // element, that contains the contents of the selected (clicked) tab
    //ui.index // zero-based index of the selected (clicked) tab
	});
});


//vidine
$(document).ready(function(){
	$("#PaieskosAnketaVidine > ul").tabs();
	$('#PaieskosAnketaVidine > ul').bind('tabsselect', function(event, ui) {
		if(ui.index == 0 || ui.index == 1){
			new_location = ui.tab.href.split('#')[0];
			if(location.href != new_location){
				location.href = new_location;
				return false;
			}
			//return false;
		}
		//if(ui.index == 0){
		//	location.href = 'index.php';
		//	return false;
		//}
	});
});

*/


var original_height;
var original_content_height;
var original_inner_height;

var original_content_height;
var accordion_content_height;
var accordion_content_height_minus;
var maps_height;

var accordion_content_height_old;
var accordion_content_height_new;


//height
$(document).ready(function(){
	//buggy?

	original_height = $.browser.opera && $.browser.version > "9.5" && $.fn.jquery <= "1.2.6" ? document.documentElement["clientHeight"] : $(window).height();
	original_content_height = $("#page_content_main").height();
	original_inner_height = $("#page_content_inner").height();
	
	accordion_content_height = $("#Maps #maps_control .ui-accordion-content").height();
	accordion_content_height_minus = $("#Maps").height() - accordion_content_height;
	maps_height = $("#Maps").height();

	maximize_content(0);
	$(window).resize(function(){
		maximize_content(4);
	});
	
});


function maximize_content(height_fix){
	//alert($.browser.version);
	//alert($.browser.iexplorer);
	original_height = $.browser.opera && $.browser.version > "9.5" && $.fn.jquery <= "1.2.6" ? document.documentElement["clientHeight"] : $(window).height();
	
	if(original_height>original_content_height || (original_height<original_content_height && original_content_height<$("#page_content_main").height())){
	
		if(original_height<original_content_height && original_content_height<$("#page_content_main").height()){
			height_inner = original_inner_height;
			$("#page_content_inner").css("height",original_inner_height+"px");
			$("#ImonesLentele").css("height",height_inner+"px");
		}else{
			height_inner = original_height - $("#page_content_main").height() + $("#page_content_inner").height();
			$("#page_content_inner").css("height",height_inner+"px");
			$("#ImonesLentele").css("height",height_inner+"px");
		}

		
		if($("#Maps").length){
			
			//map fix
			maps_height = height_inner - 24;
			
			//accordion fix
			accordion_content_height_old = accordion_content_height_new;
			accordion_content_height_new = maps_height-accordion_content_height_minus + height_fix;
			
			if(accordion_content_height_new!=accordion_content_height_old){
				$("#Maps #map").css("height",maps_height+"px");
				$("#Maps #maps_control .ui-accordion-content").css("height",accordion_content_height_new+"px");
			}
		}
		
	}

}









//search form subform greita, detali
//var show_search_firm_form;
function SetElementCSSClass(id, css_class){
	if(document.getElementById(id)){
		block_id = document.getElementById(id);
		block_id.className = css_class;
	}
}

//dynamic js loading
function include_js(path_js, callback){
  var script = document.createElement("script");
  script.src = path_js;
  script.type = "text/javascript";
  document.getElementsByTagName("head")[0].appendChild(script);
  
  if(callback){
		// Firefox
		script.onload = function() {
			eval(callback + "();");
		}
		
		// IE
		script.onreadystatechange = function() {
			if (/loaded|complete/.test(this.readyState)) {
			  eval(callback + "();");
			}
		}
  }


}

function print_r(theObj){ 
	output = '';
	if(theObj.constructor == Array || theObj.constructor == Object){ 
	  //document.write("<ul>")
	  output += "\t\n";
	  for(var p in theObj){ 
		 if(theObj[p].constructor == Array || theObj[p].constructor == Object){ 
			//document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
			output += "["+p+"] => "+typeof(theObj)+"\n";
			//document.write("<ul>") 
			output += "\t\n";
			print_r(theObj[p]); 
			//document.write("</ul>") 
		 } else { 
			//document.write("<li>["+p+"] => "+theObj[p]+"</li>");
			output += "["+p+"] => "+theObj[p]+"\n";
		 } 
	  } 
	  //document.write("</ul>") 
	  return output;
	}
	return false;
}


//jquery plugin clear form
/*
$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};
*/


function search_form_help(form_id){
	$(form_id+" input[title!='']").each(function (i) {
		if($(this).attr("value")=="" && $(this).attr("title"))$(this).attr("value", $(this).attr("title"));
	});

	selector = $(form_id+" input[title!='']");
	selector.click(function(){
		if($(this).attr("value")==$(this).attr("title"))$(this).attr("value", "");
	});
	selector.focus(function(){
		if($(this).attr("value")==$(this).attr("title"))$(this).attr("value", "");
	});
}

function search_form_help_clear(form_id){
	$(form_id+" input[title!='']").each(function (i) {
		if($(this).attr("value")==$(this).attr("title"))$(this).attr("value", "");
	});
}


