jQuery.fn.appendCornedFooter = function () {
	var $ = jQuery;
	var fix = "";
	if ($.browser.msie && $.browser.version < '7') {
		fix = " png_fix";
	}
	this.each(function (i) {
		var m_footer = '<div class="foot' + fix + '"><div class="left' + fix +'"></div><div class="right' + fix + '"></div></div>';
		$(m_footer).appendTo(this);
	})
}

$("#header .call_us").appendCornedFooter();

$(document).ready(function() {
	var forms = $(".goodform");
	forms.each(function(){
		var alt = $(".altsubmit", this);
		if (alt.length > 0) {
			$("input:submit", this).hide();
			$(".altsubmit", forms).show().click(function(){
				var $this = $(this);
				var form = $this.parents("form");
				try {
					var inputs = form.find("input:text");
					inputs.each(function(){
						if (this.value.toLowerCase() == this.title.toLowerCase()) {
							this.value = "";
						}
					});
					form.submit();
					
				} catch (e) {
					$(".submit", form).show();
					$this.hide();
				}
				return false;
			}); 
		}
	});
});

$(".main_menu > ul > li").mouseover(function(){
	$(this).addClass("active");
});
$(".main_menu > ul > li").mouseout(function(){
	$(this).removeClass("active");
});

$(".main_menu .submenu").appendCornedFooter();

$(".altsubmit").click(function(){
	//$(this).parents("form").get(0).submit();
	return false;
});

$(function(){
	var inputs = $("input:text").filter("[title]=''");

	var test_focus = function(){
		var $this = $(this);
		if (this.value.toLowerCase() == this.title.toLowerCase()) {
			this.value = "";
			$this.removeClass("inactive");
		}
	}
	var test_blur = function () {
		var $this = $(this);
		if (this.value == "" || this.value.toLowerCase() == this.title.toLowerCase()) {
			this.value = this.title;
			$this.addClass("inactive");
		}
	}
	
	inputs.each(function(){
		var $this = $(this);
		$this.focus(test_focus);
		$this.blur(test_blur);
		test_blur.call(this);
	});
});

$(function(){
	$(".media-gallery dd .c").filter(".t.l").hide()
	$('dl.tabs dt').click(function(){
		$(this)
			.siblings().removeClass('selected').end()
			.next('dd').andSelf().addClass('selected');
		if (this.id) {
			id = this.id;
			location.href = location.href.replace(/\#.*$/, "") + "#" + id + "-body";
			$("a.depend_on_tab").each(function(element){
				$(this).attr("href", ($(this).attr("href").replace(/\#.*$/, "") + "#" + id + "-body"))
			});
		}
	});
});


$(function(){
	var tracking_out = $('<div class="tracking_out"><div class="tr_o"></div><div class="tr_i"></div></div>');
	$(".replies-block .reply").append(tracking_out);
})

$(function(){
	$(".switches a").click(function(){
		this.blur();
		var buttons = $(this).parent().children(); 
		var idx = buttons.index(this);
		var areas = $(this).parents(".switches").siblings(".switch_area").children();
		buttons.removeClass("pressed");
		$(this).addClass("pressed");
		
		areas.removeClass("active");
		$(areas[idx]).addClass("active");
		return false;
	});
});


$(function(){
     var rp = new RegExp(/#(.*)$/);
     var res = rp.exec(location.href);
	  
     if (res && res.length == 2) {
          var anchors = res[1].split(",");
          for (var i = 0, anchor; anchor = anchors[i]; i++) {
               $("a[href='#" + anchor + "']").click();
               
          }
     }
})

$(function(){
	var rp = new RegExp(/#(.*)$/);
	var res = rp.exec(location.href);
	var class_name = "selected";
	if (res && res.length == 2) {
		var anchor_id = res[1];
		anchor_id = anchor_id.replace(/-body/g, "");
		var tab = $("#" + anchor_id);
		if (tab.parent().hasClass("tabs")) {
			var tabs = tab.siblings(); 
			tabs.removeClass(class_name);
			tab.next().andSelf().addClass(class_name);
		}
	}
});

function hidden(tab1, tab2){
    block1 = document.getElementById(tab1);
    block2 = document.getElementById(tab2);
    if (block1.className == 'hide') {
        block1.className = 'show';
        block2.className = 'hide';
    }
    else {
        block1.className = 'hide';
        block2.className = 'show';
    }
}
$(".faq ol li span").click(function(){
	$(this).parent().toggleClass("opened")
});



/**
 * @author Sky
 */
var fadeInOutSpeed = "mid";

function checkMouse(e)
{
	var el = e.target;
	//var login_block = document.getElementById("login_block");
	var search_block = document.getElementById("resSearch");

	while (true){
		if ((el == search_block)) {
			return true;
		} else if (el == document) {
			HideBlocks();
			return false;
		} else {
			el = el.parentNode;
		}
	}
};
	
function HideBlocks()
{
	//$("#login_block").fadeOut(fadeInOutSpeed);
	$("#resSearch").fadeOut(fadeInOutSpeed);
	$(document).unbind('mousedown', checkMouse);
}

$(document).ready(function(){
	$("#table-srav").css("display", "table");
	$("#resSearch").css("display", "none");
	$(document).bind('mousedown', checkMouse);
	$("a[name='login_link']").click(function () {
		if ($("#login_block").css("display") == "none")
		{
			$("#login_block").fadeIn(fadeInOutSpeed);
			$(document).bind('mousedown', checkMouse);
		}
		else
			HideBlocks();
    });
});



var old_str = '';
function ajax_search()
{
	show_results();
	if (window.timeout) {
		clearTimeout(timeout);
	}
	object = { 
			func: function() {
			poiskObj = document.getElementById('poisk');
			if(old_str!=poiskObj.value) {
				old_str = poiskObj.value;
				jsAjaxUtil.InsertDataToNode('/include/template/res_search.php?q='+encodeURI(poiskObj.value), 'resSearch', true);
				$(document).bind('mousedown', checkMouse);
			}
		}
	}
	timeout = setTimeout( function() {object.func.call(this) } , 500); 
}
 
function hide_results()
 {
	document.getElementById('resSearch').style.display='none';

 }   
 
 
function show_results()
 {
	document.getElementById('resSearch').style.display='block'; 
	document.getElementById('resSearch').style.zIndex='9999';
 }
 