var d = document;
var winIE = (navigator.userAgent.indexOf("Opera")==-1 && (d.getElementById && d.documentElement.behaviorUrns)) ? true : false;
var tim;
var ie6 = winIE && navigator.appVersion.indexOf("MSIE 7") == -1;
var g_speed = 5;
if(winIE) 
{
	jsHover = function() 
	{
	    var hEls = document.getElementById("allPage").getElementsByTagName("LI");
	    for (var i=0, len=hEls.length; i<len; i++) {
	      hEls[i].onmouseover=function() {this.className+=" jshover"; }
	      hEls[i].onmouseout=function() { this.className=this.className.replace(" jshover", ""); }
	    }
  	}
  if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1) window.attachEvent("onload", jsHover);
}

function init()
{
	tim = new Timer(30);
	tim.start();
	var h=document.getElementById("allPage").offsetHeight;
	/*var w=document.getElementById("allPage").offsetWidth;*/
	

	if (document.getElementById("mycustomscroll"))
	{
		document.getElementById("mycustomscroll").style.height = h - 364+'px'
/*		document.getElementById("mycustomscroll").style.width = w - 420+'px';*/
	}
	init_icons();
	
	jQuery("#region2").autocomplete( root + "include/getAutoCompleteRegion.php4", { minChars:2 }) ;
	//jQuery("#region2").autocomplete( root + "include/getAutoCompleteRegion.php4", { minChars:2 }) ;
}

function init_icons(){
	var root = $('icons');
	if(!root){
		return false;
	}
	root.items = $C('item', root, 'DIV');
	root.items.each(function(item){
		item.root = root;
		item.input = $T('INPUT', item, 1);
		item._percent_val = Number(item.input.value);

	//	item._val = item._percent_val != 0 ? Math.round((c.lim_val / 100) * item._percent_val) : 1;

		var arr = $C_arr(['img-holder', 'img', 'hidden'], item, 'DIV');
		item.link = $C("shit", item, "A", 1);
		item.d_holder = arr.shift();
		item.d_img = arr.shift();
		item.d_hidden = arr.shift();
		item.hidden_img = $T('IMG', item.d_hidden, 1);
		var imags = 
		item.img = $T('IMG', item.d_img, 1);
		item.from = {
			w: item.img.width, h: item.img.height, src: item.img.src
		};
		item.to = {
			w: item.hidden_img.width, h: item.hidden_img.height, src: item.hidden_img.src
		};
		item.d_img.style.left = Math.floor((item.d_holder.offsetWidth - item.img.width) / 2) + "px";
		item.d_img.style.width = item.img.width + "px";
		item.d_img.style.height = item.img.height + "px";
		item.d_img.style.top = Math.floor((item.d_holder.offsetHeight - item.img.height) / 2) + "px";
		item.mov = new moveable(item.d_img);
		item.res = new Resize(item.d_img, tim);
		Resize.setGrow(item.res, item.mov);
		item.res.resizeable.onafterresize.register('img', function(oR){
			this.img.style.width = oR.width + "px";
			this.img.style.height = oR.height + "px";
		}.bind(item, item.res.resizeable));
		item.link_top = 0;
		item.coeff = 0;
		item.res.onresize.register('change link position', function(oR){
			this.link_top += this.res.stepY.signOf();
			
			this.link.style.top = this.link_top + "px";
			if (this.link_top <2){
				this.link.style.color = "#909090";
			} else {
				this.link.style.color = "#666666";
			}
			
		}.bind(item, item.res.resizeable));
		item.res.ongrown.register('src', function(){
			if(this.GROWING){
				if(!ie6){
					this.img.src = this.to.src;
				}
			}
		}.bind(item));
		var w = item.img.width;
		var h = item.img.height;
		item.grow = function(){
			if(this.GROWING){
				return false;
			}
			this.res.growTo(this.to.w, this.to.h, g_speed);
			this.GROWING = 1;
			this.root.here_item = this;		
		};
		item.grow_out = function(){
			if(!ie6){
				this.root.here_item.img.src = this.root.here_item.from.src;	
			}
			this.root.here_item.res.growTo(this.root.here_item.from.w, this.root.here_item.from.h, g_speed);
			this.root.here_item.GROWING = false;		
		};
		item.onmouseover = item.grow.bind(item);
		item.onmouseout = function(e){
			var ev = window.event || e;
			var relTarget = ev.relatedTarget || ev.toElement;
			if(relTarget == this || _isChild(relTarget, this)){
				return false;
			}
			this.grow_out();
		}
		if(ie6){
			item.d_img.style.fontSize = "0";
			item._src = item.hidden_img.src;
			item.img.style.width = w + 'px';
			item.img.style.height = h + 'px';
			item.img.src = item.img.src.replace(item.img.nameProp, 'blank.gif');
			item.img.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + item._src + '", sizingMethod="scale"';
		}
		var dims = Style.$D(item.d_holder);
		Style.set(item.d_img, {width: w, height: h}, null, true);
		item.img.style.left = Math.floor((dims.width - w) / 2) + "px";
	});
	i_root = root;
}

function ChangeFromRegionType(elem) {
	
	countryId = elem.value;
	if ( countryId != '' ) {

		jQuery.ajax({
			url: root+'include/changeRegionType.php4',
			type: "POST",
			dataType: "HTML",
			data:'countryId='+countryId,
			success: function(data){
				document.transportSearch.region_from1.value = '';
				document.transportSearch.region_from2.value = '';
				if ( data == 1) {
					jQuery("#region1").show();
					jQuery("#region2").hide();
					jQuery("#region1").value = '';
					jQuery("#region2").value = '';
				}
				else if ( data == 2){
					jQuery("#region2").show();
					jQuery("#region1").hide();	
					jQuery("#region1").value = '';
					jQuery("#region2").value = '';
				}
				else {
					jQuery("#region2").show();
					jQuery("#region1").hide();
					jQuery("#region1").value = '';
					jQuery("#region2").value = '';
				}
			}
		});

	}

}

