var DocAddr = document.location.href.substr(DocumentRoot.length+4).toLowerCase();

jQuery.fn.floatVal = function() {
	var v = $(this).val();
	if(v=="") v = "0";
	v = parseFloat(v.replace(",","."));
	return parseFloat(v);
};
function changeText(obgName, text, state) {
	if(text=="") return false;
	var obj = ((obgName.value!=null) ? obgName : document.getElementById(obgName));
	if(state==1) {
		if(obj.value==text) obj.value='';
	} else {
		if(obj.value=='') obj.value=text;
	}
}
function function_exists( function_name ) {  
  
    if (typeof function_name == 'string'){  
        return (typeof window[function_name] == 'function');  
    } else{  
        return (function_name instanceof Function);  
    }  
}  
$(document).ready(function() {
	if (navigator.appVersion.match(/MSIE [0-6]\./)) {
		$('*').each(function () {
			  if (this.currentStyle.backgroundImage != 'none') {
				src = this.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/);
			    if (src) {
			        src = src[1]; 
				    $(this).css({'backgroundImage': 'none', 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + src + "')"});
				 }
			  }
		});
		$('IMG').each(function () {
			if (this.src.indexOf(".png")>0) {
		        src = this.src; 
		        this.src = RootAddress + ''+DocumentRoot+'images/spacer.gif';
			    $(this).css({'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + src + "')"});
			 }
		});
	}
	
	$("#initLogo").fadeOut("slow");
	$("#MainTable").show();
	
	if(!(DocAddr=='' || DocAddr.indexOf('home')>0)) {
		$('#headerQuote').hide();
		$('#Portfolio').hide();
		$("#HeaderCell").hide();
	}
	$('BODY').mousemove(function(e){ 
		scrollTop = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		e = window.event || e;
		var top = 150+70;
		if(($('#HeaderCell').css('display')!='none')) top += 140;
		var y = e.clientY+scrollTop;
		$('#ScrollableLogos').css("top", Math.min(Math.max(0,y-top),document.body.scrollHeight-(top+80))+"px");
	});
	$('INPUT').blur(function(){ changeText(this,this.alt,0) }).focus(function(){ changeText(this,this.alt,1) });

	$('.str', '#MainMenu').hide();
	$('A', '#MainMenu')
		.mouseover(function() { var el = $($('.str', '#MainMenu')[parseInt(this.id.substr(2))-1]); el.stop(true, true); el.fadeIn('fast') })
		.mouseout(function() { if(this.className!='active') { var el = $($('.str', '#MainMenu')[parseInt(this.id.substr(2))-1]); el.stop(true, true); el.fadeOut('slow') } })
		.click(function() {
			if(this.className!='active') {
				$('A.active', '#MainMenu').each(function() { $($('.str', '#MainMenu')[parseInt(this.id.substr(2))-1]).fadeOut('slow') }).removeClass("active");
				$(this).addClass("active");
				var relhref = this.href.substr(DocumentRoot.length);
				if(relhref=="rus/home") {
					$("#HeaderCell").show("fast");
					$('#headerQuote').fadeIn("fast");
					$('#Portfolio').fadeIn("fast");
				} else {
					$('#headerQuote').fadeOut("fast");
					$('#Portfolio').fadeOut("fast");
					$("#HeaderCell").hide("slow");
				}
			}
		});
	$('A.active', '#MainMenu').each(function() { $($('.str', '#MainMenu')[parseInt(this.id.substr(2))-1]).fadeIn('slow') });
});
