function slideUpLinks() {
	/*$(".open").bind("click", function() {
		swapper("none", "block");
		$("#links_content").slideUp("normal", function() {});
	});
	
	$(".close").bind("click", function() {
		swapper ("block", "none");
		$("#links_content").slideDown("normal", function() {});
	});
	*/
	$("#links > .wrapper").bind("click", function() {
		if ($("a.close").css('display') == 'none') {
			$("#links_content").slideUp("normal", function() {});
			swapper("none", "block");
			
		} else {
			$("#links_content").slideDown("normal", function() {});
			swapper("block", "none");
		}
	});
	
	function swapper(_open, _close) {
		$("a.open").css({"display" : _open});
		$("a.close").css({"display" : _close});
	}
}

function customselect(){
	$("#CitySelect").selectdecorator({"DIVClass" : "selectholder"});
}

function tablecolor () {
	$("table.table_variant_1 tr").alternate({"odd" : "off", "even" : "on"});
	$("table.table_variant_3 tr").alternate({"odd" : "off", "even" : "on"});
	$("table.table_variant_4 tr").alternate({"odd" : "off", "even" : "on"});
}

function productmenu() {
	$("li.parent_open span.arr").click(function() {
		if ($("ul.all_parent").css("display") == "none") {
			$("ul.all_parent").slideDown("normal", function() {});
			
			$("ul.all_child").slideUp("normal", function() {});
			
		} else {
			$("ul.all_parent").slideUp("normal", function() {});
		}
		
		return false;
	});
	
	$("li.child_open span.arr").click(function() {
		if ($("ul.all_child").css("display") == "none") {
			$("ul.all_child").slideDown("normal", function() {});
			
			$("ul.all_parent").slideUp("normal", function() {});
			
		} else {
			$("ul.all_child").slideUp("normal",function() {});
		}
		
		return false;
	});
	
	$("ul.all_parent, ul.all_child").find("a").each(function() {
		$(this).click(function() {
			window.location.href = this.href;
		});
	});
	
	$('body').bind('click', function() {
		$('ul.all_child').hide();
		$('ul.all_parent').hide();
	});
}

function accordions() {
	$('#accordion').accordion();
}

function tabs_init() {
	var tabs_count = $("div#tabs-set div.filials-tab");
	$("ul.filials-nav").tabs("#tabs-set > div");//.history();
}

function tablemenu(what, to) {
	var totalWidth = 0;
	
	$(what).find("a").each(
		function() {
			totalWidth += $(this).outerWidth();
		}
	);
	
	var paddingLeft = parseInt(($(what).width() - totalWidth) / ($(what).find("a").length - 1), 10) - 1;
	
	var liCount = $(what).find("li").length;
	var counter = 1;
	
	$(what).find("li").each(
		function() {
			$(this).css("margin", 0);
			$(this).css("padding-right", 0);
			
			if(counter == liCount) {
				$(this).css("position", "absolute");
				$(this).css("right", 0);
				
			} else if (counter > 1) {
				$(this).css("padding-left", paddingLeft);
			}
			
			counter += 1;
		}
	);
}

function initFilesIcons() {
	$("#page a").each(function() {
		if (!$(this).children("img").length) {
			var sHref = $(this).attr("href");
			
			if (sHref) {
				switch (sHref.substr(sHref.length - 4)) {
					case ".doc":
						setFileIcon(this, "word");
						break;
					
					case ".xls":
						setFileIcon(this, "exel");
						break;
					
					case ".pdf":
						setFileIcon(this, "acrobat");
						break;
					
					case ".zip":
						setFileIcon(this, "zip");
						break;
					
					case ".rar":
						setFileIcon(this, "rar");
						break;
					
					case ".txt":
						setFileIcon(this, "txt");
						break;
				}
			}
		}
	});
}

function setFileIcon(oLink, sType) {
	var $oLink = $(oLink);
	
	if ($.browser.msie) {
		$oLink.removeClass(sType);
		$oLink.append("<span class=\"" + sType + "\">&nbsp;</span>");
		
	} else {
		$oLink.addClass(sType);
	}
}

/*var m = document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand;

try {
	if (!!m) {
		m("BackgroundImageCache", false, true);
	}
} catch(oh) {}*/

$(document).ready(function() {
	$("div.block").each(function() {
		if ($(this).html().replace(/\s+/g, "") === "") {
			$(this).css("display", "none");
		}
	});
	
	slideUpLinks();
	customselect();
	tablecolor ();
	productmenu();
	
	tabs_init();
	tablemenu("#dd_menu > #menu_top","main-menu_new");
	tablemenu("#main_menu > #main-menu","main-menu");
	$(window).resize(function() {
		tablemenu("#dd_menu > #menu_top","main-menu_new");
		tablemenu("#main_menu > #main-menu","main-menu");
	});
	initFilesIcons();
	accordions();
	//setEqualWidth($("#dd_menu  > ul > li"));
	
//	$.getScript("/common/js/jquery.bgiframe.js", function() {
//		$('ul.all_child, ul.all_parent').bgiframe();
//	});
});

