jQuery.fn.toggleVal = function() {
	this.each(function() { $(this).focus(function() { if($(this).val() == this.defaultValue) { $(this).val(""); } }).blur(function() {if($(this).val() == "") { $(this).val(this.defaultValue); }}); });
}
$(function() {
	var sm = "selectedMenu";
	var smEx = "selectedMenuEx";
	var see_leftside = true;
	var w_left = $("#leftSide").width();
	var w_cent = $("#centerSide").width();
	var preload = '<div id="preloadA"><img src="' + public_root_path + '/images/loading.gif" alt="" /></div>';
	var preloadB = '<div id="preloadB"><img src="' + public_root_path + '/images/loading_bl.gif" alt="" /></div>';
	var preloadC = '<div id="preloadC"><img src="' + public_root_path + '/images/loading.gif" alt="" /></div>';
	$(".menu li").not(".Ex").bind("mouseover",	function(){ $(".menu li."+sm).removeClass(sm); $(this).addClass(sm).fadeTo(1,0.95); });
	$(".menu li").not(".Ex").bind("mouseout",	function(){ $(".menu li."+sm).removeClass(sm).fadeIn(1); });
	$(".menu li.Ex").not(".spzero").bind("mouseover",	function(){ $(".menu li."+smEx).removeClass(smEx); $(this).addClass(smEx).fadeTo(1,0.95); });
	$(".menu li.Ex").not(".spzero").bind("mouseout",	function(){ $(".menu li."+smEx).removeClass(smEx).fadeIn(1); });
	$(".menuFoot li").bind("mouseover",	function(){ $(".menuFoot li."+sm).removeClass(sm); $(this).addClass(sm); });
	$(".menuFoot li").bind("mouseout",	function(){ $(".menuFoot li."+sm).removeClass(sm); });

	$("#catalog_firms").click(function(){
		var offset = $(this).offset();
		$("#special").html(preload);
		$("#special").css({'left': offset.left + 20, 'top': offset.top - 100, 'opacity': 0.92}).fadeIn("normal", function(){
			$.post(public_root_path+"/index.php?action_ajax=loadCategoryPortal", { crc: 'portal'}, function(data){ $("#special").html(data); });
			$(document).one('click', function(){ $('#special').fadeOut('slow'); });
		}); return false;
	});

	$("#remember_password").click(function(){
		$("#top .special_info").html(preloadB);
		$("#top .special_info").css({'opacity': 0.98}).fadeIn("slow", function(){
			$.post(public_root_path+"/index.php?action_ajax=loadRememberPassword", { crc: 'remember'}, function(data){ $("#top .special_info").html(data); $(".togvalue").toggleVal(); $("#remember_close").click(function(){ $('#top .special_info').fadeOut('slow'); }); });
		}); return false;
	});

	$(".naviPrevON, .naviNextON").mouseover(function() { $(".naviNextONE, .naviPrevONE", this).stop().animate({'opacity': 0 }); });
	$(".naviPrevON, .naviNextON").mouseout(function() { $(".naviNextONE, .naviPrevONE", this).stop().animate({'opacity': 1 }); });
	$("#galerry_gcms a, a.fancybox").fancybox({'fancy':true,'speed':750,'overlayShow':true, 'overlayOpacity':0.73});
	$(".firms_pos").click(function(){
		if($("div", this).css("display") == "none") { $("div", this).show("slow").fadeIn("normal");  $("span", this).css({"font-weight":"bold"}); }
		else { $("div", this).hide("slow").fadeOut("normal"); $("span", this).css({"font-weight":""}); }
	});
	$(".firms_pos:first > div").show(1).fadeIn(1);
	$(".firms_pos:first > span").css({"font-weight":"bold"});
	
	$.post(public_root_path+"/index.php?action_ajax=loadSpeedContact", { crc: 'speedcontact'}, function(data){ $("#menufootDSPos").html(data); });
	
	$(".spacemenu h1").css({"display":"none"});
	$("h1.jqu").css({"display":"none"});
	//fontSize
	var cl = ".only_highlight"; var fSmin = 9; var fSmax = 15;
	var oFS = $(cl).css('font-size');
    $('.FontZ').click(function(){ $(cl).css('font-size', oFS); });
	$('.FontP').click(function(){ var size = parseInt($(cl).css('font-size')); if(size < fSmax) $(cl).css('font-size', (size+1)); });
	$('.FontM').click(function(){ var size = parseInt($(cl).css('font-size')); if(size > fSmin) $(cl).css('font-size', (size-1)); });

	$(".TagsJq a").each(function(index) {
		$(this).addClass("tags").css({'font-size':$(this).attr("rel")+"%" }).removeAttr("rel").attr({"href":public_root_path+"/search.html?tags="+$(this).attr("title")}).attr({"title":$(this).text()});
	});
	$("a[@href^='#']").click(function() { var $tr = $(this.hash); $tr = $tr.length && $tr || $('[name=' + this.hash.slice(1) +']');
		if ($tr.length) { $('html,body').animate({scrollTop: $tr.offset().top}, 1000); /*, 'bounceout'*/ return false; } });

	$(".HideLeftSide").click(function() {
		if(see_leftside) { 
			$("#leftSide").hide("slow"); 
			$("#centerSide").animate({"width":w_left+w_cent}, 1000); 
			$("div", this).animate({'opacity': 0 }); 
			see_leftside = false; 
		} else { 
			$("#centerSide").animate({"width":w_cent}, 500); 
			$("#leftSide").show("slow"); 
			$("div", this).animate({'opacity': 1 }); 
			see_leftside = true; 
		}
	});
	$(".op85").css({"opacity":0.8});
	$(".Lmenu").lavaLamp({ fx: "backout", speed: 700 })
	if(jQuery.fn.tooltip) {
		$(".tool_page, area").tooltip({ track: true, delay: 0, showURL: false, showBody: " - ", fade: 250 });
		$('#tooltip').css({"opacity":0.8});
	}
	//$("#module_mainpage_nn").html(preloadC);
	//$("#module_mainpage_gg").html(preloadC);

	$(".LmenuDivN a").click(function(){
		$("#module_mainpage_nn").html(preloadC);
		$.post(public_root_path+"/index.php?action_ajax="+$(this).attr("rel"), { crc: 'portal'}, function(data){ $("#module_mainpage_nn").html(data); });
	});

	$(".LmenuDivG a").click(function(){
		$("module_mainpage_gg").html(preloadC);
		$.post(public_root_path+"/index.php?action_ajax="+$(this).attr("rel"), { crc: 'portal'}, function(data){ $("#module_mainpage_gg").html(data); });
	});

	$("a.jSECe").each(function(index) {
		$(this).html($(this).html().replace("(#)", "@"));
		if($(this).attr("href") == "#") $(this).attr({"href":"mailto:"+$(this).attr("rel").replace("##", "@")});
	});
	$("a.bl_").attr({"target":"_blank"});
	$(".listItemText").focus(function() { return false; }).noContext().rightClick(function() { return false; }).disableTextSelect();
	$(".togvalue").toggleVal();

	//$("#top").click(function() { window.location.href = public_root_path + '/'; });


	$(".miniSizeGalExImg").click(function(event) {
		event.preventDefault();
		var href = $(this).attr("href");
		$(".miniSizeGalExImgRes img").attr({"src": href});
		$(".miniSizeGalExImgRes").attr({"href": href.replace("_300_", "_1000_").replace("h.", ".")});
	});

});