/* Проблема IE */
$(function(){
	$(".popup_wr").each(function(i, item){
		$(item).appendTo("#popup_wrs");
	});	
	$(".t_left a img").hover(function(){
 	 $(this).parent().addClass("zoomed");
	  $(this).animate({'width':"300px"}, 700);
	},function(){
	  $(this).parent().removeClass("zoomed");
	  $(this).animate({'width' : "181px"}, 700);
	});
	/*
	var items=$(".mini_photos a");
	if(items.length>1){
	  var url=$(items[0]).attr("rel");
	  var url2=$(items[0]).attr("rel2");
	  $("#bigPhoto").attr({'src':url});
	  $("#bigPhotoHref").attr({'href':url2});
	}
	*/
	$(".mini_photos a").click(function(){
	  /*
	  var url=$(this).attr("rel");
	  var url2=$(this).attr("rel2");
	  */
	  
	  $(".mini_photos a").removeClass("act");
	  $(this).addClass("act");
	  
	  /*
	  $("#bigPhoto").attr({'src':url});
	  $("#bigPhotoHref").attr({'href':url2});
	  
	  $(".lightbx").attr({'rel':'lightbox'});
	  $(".lightbx[href="+url2+"]").attr({'rel':''});
	  $("a[rel=lightbox]").lightBox();
	  */
	});
});

function changePhoto(n){
  $(".bigPhotoHolder a").fadeOut("1500");
  $("#photo"+n).fadeIn("1500");
}

/* Ошибка в IE c popup */
function dob_op() {
    $(".dobavlen").show();
}
function dob_cl() {
    $(".dobavlen").hide();
}

function open_wind1(id){
    var h;
    h = document.getElementById('wrap').offsetHeight;
    document.getElementById('alles').style.height = h+ 'px';
    document.getElementById('alles').style.display = 'block';
    
    $("#popup_wr_"+id).show();
}

function close_wind1(id){
    document.getElementById('alles').style.display = 'none';
    $("#popup_wr_"+id).fadeOut();
}

function open_wind2(){
    var h;
    h = document.getElementById('wrap').offsetHeight;
    document.getElementById('alles').style.height = h+ 'px';
    document.getElementById('alles').style.display = 'block';
    document.getElementById('popup').style.display = 'block';
    document.getElementById('popup_n').style.display = 'block';
    document.getElementById('popup2').style.display = 'block';
}

function close_wind2(){
    document.getElementById('alles').style.display = 'none';
    document.getElementById('popup').style.display = 'none';
    document.getElementById('popup_n').style.display = 'none';
    document.getElementById('popup2').style.display = 'none';
}

// Переключение между ключевыми словами
function seo_text(rel)
{
	$(".seo_url").parent().removeClass("active");
	$(".seo_url[rel="+rel+"]").parent().addClass("active");
	
	$(".seo_text").hide();
	$(".seo_text[rel="+rel+"]").fadeIn();
}

// Положить в корзину
function cartClick()
{
	var parent = $(this).parent();
	var href = $(this).attr("href");
	href += "&ajax=1"+Math.random();

	$.getJSON(href,function(result){
		var popup = $("#popup_"+result.type).html();
		$("#cart_response").show();
		$(parent).append(popup);
        $(".close", parent).click(function(){
        	$("#cart_response").hide();
        	$(".popup", parent).fadeOut("slow").remove();
        	return false;
        });
		$(".popup", parent).fadeIn();
		
		// Обновление корзины
		$.getJSON("/netcat/modules/default/cart.php?a=cart", function(cart){
			$("#cart_count").html(cart.count);
			$("#cart_money").html(cart.money);
		});
	});
	
	return false;
}

// Удалить из корзины
function removeCart()
{
	var parent = $(this).parent().parent().parent().parent().parent().parent().parent();
	var href = $(this).attr("href")+"&ajax=1";

	$.get(href,function(result){
		$(parent).fadeOut("slow").remove();
		
		// Обновление корзины
		refreshCart(1);
		
		$.getJSON("/netcat/modules/default/cart.php?a=cart", function(cart){
			$("#cart_count").html(cart.count);
			$("#cart_money").html(cart.money);
		});
	});
	
	return false;	
}

// Обновление кол-во в корзине
function refreshCart(item,i)
{
	var summa = 0;
	
	$(".price").each(function(i, item){
		var id = $(item).attr("rel");
		var price = parseInt($(item).html());
		var count = parseInt($("#count_"+id).attr("value"));
		if ( !Number(count)||count<0) {
			count = 1;
			$("#count_"+id).attr("value", count);
		}
		
		
		
		$("#cost_"+id).html(price*count);
		summa += price*count;
	});
	
	if ( !summa) {
		document.location.href = '/cart/empty/';
	}
	
	$("#summa").html(summa);
}

// Логотипы торговых комплексов
function tkSlide(rel) {
	$(".tk").hide();
	
	if ($(".tk[rel="+rel+"]").get(0)) {
		$(".tk[rel="+rel+"]").fadeIn("slow");
	} else {
		tkSlide(0);
		return;
	}
	
	setTimeout("tkSlide("+(rel+1)+")", 2000);
}

$(function(){
  var col=$(".tk");
  if(col.length>1){
    tkSlide(0);
  }
});



function getBrowserInfo() {
    var t,v = undefined;

    if (window.chrome) t = 'Chrome';
    else if (window.opera) t = 'Opera';
    else if (document.all) {
        t = 'IE';
        var nv = navigator.appVersion;
        var s = nv.indexOf('MSIE')+5;
        v = nv.substring(s,s+1);
    }
    else if (navigator.appName) t = 'Netscape';

    return {type:t,version:v};
}

function bookmark(a){
    var url = window.document.location;
    var title = window.document.title;
    var b = getBrowserInfo();

    if (b.type == 'IE' && 8 >= b.version && b.version >= 4) window.external.AddFavorite(url,title);
    else if (b.type == 'Opera') {
        a.href = url;
        a.rel = "sidebar";
        a.title = url+','+title;
        return true;
    }
    else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
    else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
    return false;
} 