/* $ = jQuery.noConflict(); */

$(document).ready(function() {

// Функция определения версии браузера
(function($) {
  var userAgent = navigator.userAgent.toLowerCase();
  var ie_version = -1;
  if (navigator.appName == 'Microsoft Internet Explorer') {
   var re = new RegExp("msie ([0-9]{1,}[\.0-9]{0,})");
   if (re.exec(userAgent) != null)
   ie_version = parseFloat(RegExp.$1);
  }
  $.browser = {
    version: (ie_version>-1)?ie_version:(userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
    safari: /webkit/.test( userAgent ),
    opera: /opera/.test( userAgent ),
    msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
    mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
  };
})(jQuery);

	// Работа выпадающего меню	
	$("#hormenu li").mouseenter(function(){
		$(this).find("span.antiborder").css("display", "block");
		if(!$(this).hasClass("last") && !$(this).hasClass("first")) $(this).addClass("active");
	});
	$("#hormenu li").mouseleave(function(){
		$(this).find("span.antiborder").css("display", "none");
		$(this).removeClass("active");
	});
	
	// Переключение между вкладками поиска
 $("#tabwrapper ul li").bind("click", function(){
		$("#tabwrapper ul li").removeClass("selected");
		$(this).addClass("selected");
		$("#where").val($(this).children("span.data").text());
	});
	
	// Убираем дефолтный текст по наведению фокуса и делаем черный шрифт
	$("#login, #password, #email, #fastsrch input.inputtext").focus(function() {
		if($(this).attr("value") == "логин" || $(this).attr("value") == "пароль" || $(this).attr("value") == "Ваш email" || $(this).attr("value") == "Поиск по сайту")
			$(this).attr("value", "");
			$(this).css("color", "#000000");
	});
	
	// и восстанавливаем все при блуре
	$("#login").blur(function() {
		if($(this).attr("value") == "") {
			$(this).attr("value", "логин");
			$(this).css("color", "#919191");
		}
	});
	$("#password").blur(function() {
		if($(this).attr("value") == "") {
			$(this).attr("value", "пароль");
			$(this).css("color", "#919191");
		}
	});
	$("#email").blur(function() {
		if($(this).attr("value") == "") {
			$(this).attr("value", "Ваш email");
			$(this).css("color", "#919191");
		}
	});
	$("#fastsrch input.inputtext").blur(function() {
		if($(this).attr("value") == "") {
			$(this).attr("value", "Поиск по сайту");
			$(this).css("color", "#919191");
		}
	});
	
	// Раскрытие дерева каталога
	$("li div.switch").click(function() {
		var parent = $(this).parent();
		if(parent.hasClass("close")) {
			parent.removeClass("close");
		}
		else {
			parent.addClass("close");
			parent.children("ul.in-path").removeClass("in-path");
		}
	});
	
	/* Работа карточки товара */
	// Переключение между вкладками
	$("div.tabs ul li").mouseenter(function(){$(this).addClass("hover"); $("p#ind").html("enter");});
	$("div.tabs ul li").mouseleave(function(){$(this).removeClass("hover"); $("p#ind").html("leave");});
	$("div.tabs li").click(function(){
		$("div.tabs li").removeClass("selected");
		$(this).addClass("selected");		
		$("div.tabcontent").children("div").hide();
		$("div.tabcontent div#"+$(this).attr("id")+"div").show();
		return false;
	});
	
	// Всплывающие подсказки
	/* CONFIG */
		var xOffset = 4;
		var yOffset = 30;
		var t;
	/* END CONFIG */
	$("div.wareitem div.warename").hover(
		function(e){
			 var a = $(this).children("a.name");		
			t = a.attr("title");
			a.attr("title", "");
			$("body").append("<p id='tooltip'>"+ t +"</p>");
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");
    },
		function(){
			var a = $(this).find("a.name");
			$("#tooltip").remove();
			a.attr("title", t); 
		}
	);
	$("div.wareitem").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
	
	$("div.wareitem div.pic").hover(
		function(){
			$(this).children("div.additional").show();
		},
		function(){
			$(this).children("div.additional").hide();
		}
	);
	
	$("div.wareitem div.pic div.additional a").hover(
		function(){
			$(this).addClass("hover");
		},
		function(){
			$(this).removeClass("hover");
		}
	);
	
	// Скрытие-показ дополнительного описания
	$("#warecard span.switch").click(function() {
		if($(this).text() == "показать") $(this).text("скрыть");
		else $(this).text("показать");
		$("#warecard div.additional-descr-wrap div.text").slideToggle("normal");
	});
	
	// Хак для reforaml.ru
	/* $("div.furrghtd")
		.css("width", "16px")
		.css("overflow", "hidden")
		.css("margin-left", "4px");
	$("div.furrghtd a")
		.css("margin-left", "-4px"); */
	
	// Костыли для ссылок IE6
	if($.browser.msie) {
		$("a[href$=pdf]").addClass("pdf");
		$("a[href$=zip]").addClass("zip");
		$("a[href$=psd]").addClass("psd");
		$("a[href$=zip]").addClass("zip");
		$("a[href$=rar]").addClass("rar");
	}
	
	// Плавная прокрутка до якоря
	/*******
	***	Anchor Slider by Cedric Dugas   ***
	*** Http://www.position-absolute.com ***	
	You can use and modify this script for any project you want, but please leave this comment as credit.	
	Never have an anchor jumping your content, slide it.	
	Just add the class anchor at your <a> tag and it will slide, user with no javascript will 
	still go to destination with the normal html anchor
	Don't forget to put an id to your anchor !		
	*****/
	$("a.anchorLink").click(function () {
		elementClick = $(this).attr("href");
		destination = $(elementClick).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 600 );
			return false;
	});
});
