$(document).ready(function(){

	
	$(".pokupki_dost").click(function() {
		
		var curr_index = $(this).attr("href");
		
		$(".cat_wrap").hide();
		if (curr_index == '#fragment-2') {
			$(".cat_wrap.second").show();
		} else if (curr_index == "#fragment-1") {
			$(".cat_wrap.first").show();
		}
		
	});
	
	$(".inp_label").click(function(){
		$(this).find('label').css("top","-99999px");
		$(this).find('input').focus();

	});
	$("inp_label input").focus(function(){
		$(this).find('label').css("top","-99999px");
		$(this).find('input').focus();
	});
	
	
	$(".inp_label input").blur(function(){

		if ($(this).val() == '') {
			$(this).next().css("top","0px");
		}
	});
	$(".inp_label input").keydown(function(event){
		if (event.keyCode == '0xD') {
			$(".inp_label.pass label").css("top","-99999px");
		}
	});
	$(".inp_label input").dblclick(function(){
		$(".inp_label.pass label").css("top","-99999px");

	});

	$(".pass_radio").click(function() {
		
		if($(this).attr("id") == "zadat-pass") {
			$("#pass_enter").show();
		} else {
			$("#pass_enter").hide();
		}
		
	});
	
	$(".town-radio").click(function() {
		
		if($(this).attr("id") == "radio1") {
			$("#town-wrap").hide();
		} else {
			$("#town-wrap").show();
		}
		
	});
	
	var sb_height = $(".sidebar.sr").height();
	var content_height = $("#content").height();
	var bottom_h = $(".bottom").height();
	if (sb_height < content_height + bottom_h) {
		$(".sidebar").css("height", content_height + bottom_h + "px");
	}

	$('#top_menu').pngFix();
	$('#top_bg').pngFix();
	$('#logo').pngFix();
	$('#header_right').pngFix();
	$('#slide').pngFix();
	$('.bottom').pngFix();
	
	
	$('#brand_wrap_white .item').hide().show();
	
	$("#brend_select").change( function () {
		var selected = $("#brend_select option:selected");
		window.location = selected.val();
	});
	
	
	/*это табы
	$("#link_f").click(function(){
		$(".pol_M").hide();
		$(".pol_F").show();
		
		
		$("#link_f").css("text-decoration", "none");
		$("#link_m").css("text-decoration", "underline");
		$("#link_n").css("text-decoration", "underline");
		
	});

	$("#link_m").click(function(){
		$(".pol_M").show();
		$(".pol_F").hide();
		
		$("#link_m").css("text-decoration", "none");
		$("#link_f").css("text-decoration", "underline");
		$("#link_n").css("text-decoration", "underline");
	});
	
	$("#link_n").click(function(){
		$(".pol_M").hide();
		$(".pol_F").hide();
		$(".pol_N").show();
		
		$("#link_m").css("text-decoration", "underline");
		$("#link_f").css("text-decoration", "underline");
		$("#link_n").css("text-decoration", "none");
	});
	*/
	
	
	/*if($('#cat_img_cart').width() > 229) {
	$('#cat_img_cart').css("width","230px").css("cursor","pointer");
	
	$('#cat_img_cart').zoom1().click(function(){
		$(this).zoom2().fadeIn().click(function(){
			$(this).hide(); return false; 
		});
	});
	}
	
	$("#cat_img_cart").oneTime(100, function() {
		if($('#cat_img_cart').width() > 229) {
		$('#cat_img_cart').css("width","230px").css("cursor","pointer");
		
		$('#cat_img_cart').zoom1().click(function(){
			$(this).zoom2().fadeIn().click(function(){
				$(this).hide(); return false; 
			});
		});
		}
	});*/
	
	$('#cat_img_cart').css("cursor","pointer");
	

	
	// обработки для корзины
	$(".korzina").click(function(){

		var id = $(this).attr('id');
		var korzina = '#' + id;
		var korzina_loader = '.korzina_loader_' + id;

		$( korzina ).hide();
		$( korzina_loader ).show();

		$.post("/protect/price.php",{
			type: 'add',
			id: id
		}, function(xml){
			$("message",xml).each(function(id){
				message = $("message",xml).get(id);
				$("#korzina_kol").html( $("kol",message).text() );
				$( korzina_loader ).hide();
				$( korzina ).animate({ opacity: "show" }, "slow");
				window.location = '/korzina/';
			});
		});
	});

	$(".korzina_delete").click(function(){
		var uid = $(this).attr('id');
		var sum = $( '#sum_' + uid ).text();
		var kol = $( '#kol_' + uid ).val();

		$("#tr_" + uid ).animate({ opacity: "hide" }, "slow");

		$.post("/protect/price.php",{
			type: 'delete',
			uid: uid,
			sum: sum,
			kol: kol
		}, function(xml){
			$("message",xml).each(function(id){
				message = $("message",xml).get(id);

				$("#korzina_kol").html( $("kol",message).text() );
				$("#tr_" + uid ).remove();
				$("#korzinaS_sum").html( $("sum",message).text() );
			});
		});

		return false;
	});
	
	$("#radio2").click(function() {
		if ($(this).val() == "on" || $(this).val() == "2") {
			$("#town-wrap").show();
		}
	});
	
	$("#radio1").click(function() {
		$("#town-wrap").hide();
	});
	
	$("#pass3").click(function() {
		if ($(this).val() == "on" || $(this).val() == "2") {
			$("#pass-wrap").show();
		}
	});
	
	$("#pass2").click(function() {
			$("#pass-wrap").hide();
	});
	
	$(".why-need").mouseover(function() {
	
		$(this).next().show();
	
	});
	$(".why-need").mouseout(function() {
	
		$(this).next().hide();
	
	});
	

});

function hideLabel(wrap) {
	$(wrap).find('label').css("top","-99999px");
	$(wrap).find('input').focus();
}
