
hs.graphicsDir = '/templates/UrbanoNew/css/graphics/';

$(document).ready( function() {
	
		$("#foto-1").hover( function() {
			$(this).stop().animate({width:192,height:497,left: 15.5, top:2,opacity:0}, 200 );
			$("#foto-1-active").stop().animate({width:192,height:497,left:  15.5,top:2,opacity:1}, 200 );
		}, function() {
			$(this).stop().animate({width:173,height:447,left:25,top: 10,opacity:1}, 200 );
			$("#foto-1-active").stop().animate({width:173,height:447,left:25,top: 10,opacity:0.7}, 200 );
		});

		$("#foto-2").hover( function() {
			$(this).stop().animate({width:156,height:498,left: 242, top:2,opacity:0}, 200 );
			$("#foto-2-active").stop().animate({width:156,height:498,left: 242,top:2,opacity:1}, 200 );
		}, function() {
			$(this).stop().animate({width:140,height:448,left:250,top: 10,opacity:1}, 200 );
			$("#foto-2-active").stop().animate({width:140,height:448,left:250,top: 10,opacity:0.7}, 200 );
		});
		
		$("#foto-3").hover( function() {
			$(this).stop().animate({width:135,height:499,left: 393, top:2,opacity:0}, 200 );
			$("#foto-3-active").stop().animate({width:135,height:499,left: 393,top:2,opacity:1}, 200 );
		}, function() {
			$(this).stop().animate({width:121,height:449,left:400,top: 10,opacity:1}, 200 );
			$("#foto-3-active").stop().animate({width:121,height:449,left:400,top: 10,opacity:0.7}, 200 );
		});

		$("#foto-4").hover( function() {
			$(this).stop().animate({width:214,height:499,right: 240, top:2,opacity:0}, 200 );
			$("#foto-4-active").stop().animate({width:214,height:499,right: 240,top:2,opacity:1}, 200 );
		}, function() {
			$(this).stop().animate({width:193,height:449,right:250,top: 10,opacity:1}, 200 );
			$("#foto-4-active").stop().animate({width:193,height:449,right:250,top: 10,opacity:0.7}, 200 );
		});
		
		$("#foto-5").hover( function() {
			$(this).stop().animate({width:230,height:499,right: 14, top:2,opacity:0}, 200 );
			$("#foto-5-active").stop().animate({width:230,height:499,right: 14,top:2,opacity:1}, 200 );
		}, function() {
			$(this).stop().animate({width:207,height:449,right:25,top: 10,opacity:1}, 200 );
			$("#foto-5-active").stop().animate({width:207,height:449,right:25,top: 10,opacity:0.7}, 200 );
		});			
			

	$("#urbanoSearchBtn").click( function() {
		var articul = $("#urbanoCatSearch").val();
		
		if ( articul > 0 ) {
			$.ajax({
				url: '/shop.ajax.php',
				data: 'ajaxaction=search&art=' + articul,
				success: function(data) {
					if ( data > 0 ) {
						getTovar( data, 1 );
					} else {
						alert( "Товар по артиклку не найден" );
					}
				}
			});	
		} else {
			alert( "Введите артикул" );
		}
		return false;
	});


	$("#showinform").click( function() {
		$("#inSite").fadeOut( 'fast', function() {
			$("#inSiteForm").fadeIn( 'fast' );
		});
	});		
	
	$(".menuItem, .menuItemList").hover( function() {
		$(this).find(".headmenu").css( "visibility", "hidden" );
		$(this).find(".menuItemList").css( "display", "block" );
		
	}, function() {
		$(this).find(".headmenu").css( "visibility", "visible" );
		$(this).find(".menuItemList").css( "display", "none" );
	});
	
	$(".pagelist a, .pagelist").click( function() {
		var $list = $(this).parent().parent().find(".pagelistlist");
		
		if ( $list.hasClass( "activeList" ) ) {
			$list.css( "display", "none");
			$list.removeClass( "activeList" );
		} else {
			$list.css( "display", "block");
			$list.addClass( "activeList" );
		}
		return false;
	});
	
	$(".cartItemDescr, .cartItemDescr a").hover( function(e) {
		
		var text = $(this).parent().find(".urbanoCatalogItemInfoN").html();
		var offset = $(this).parent().offset();
		var x = offset.left - 30;
		var y = offset.top + 30;
		
		$(".urbanoCatalogItemInfoP").find(".col2").html( text );
		
		$(".urbanoCatalogItemInfoP").css({
			left: x,
			top: y,
			display: "block"
		});
		
	}, function() {
		$(".urbanoCatalogItemInfoP").css("display", "none");
		$(".urbanoCatalogItemInfoP").find(".col2").html( "" );
	});
	
	$(".urbanoCatalogItemInfo").hover( function(e) {
		
		var text = $(this).parent().find(".urbanoCatalogItemInfoN").html();
		var offset = $(this).parent().offset();
		var x = offset.left - 30;
		var y = offset.top + 140;
		
		$(".urbanoCatalogItemInfoP").find(".col2").html( text );
		
		$(".urbanoCatalogItemInfoP").css({
			left: x,
			top: y,
			display: "block"
		});
		
	}, function() {
		$(".urbanoCatalogItemInfoP").css("display", "none");
		$(".urbanoCatalogItemInfoP").find(".col2").html( "" );
	});
	
	$("#namemarker").click( function() {
		$img = $("#urbanoCatalogNameImg");
		
		if ( $(this).attr("class") == 'activeNamemarker' ) {
			$(this).attr("class", "");
			$("#urbanoCatalogNameList").fadeOut( "fast" );
			$(this).attr("src", $(this).attr("src").replace("-active", ""));
			$img.attr( "src", $img.attr("src").replace("-active", "") );
		} else {
			$(this).attr("class", "activeNamemarker");
			$("#urbanoCatalogNameList").fadeIn( "fast" );
			$(this).attr("src", $(this).attr("src").replace( ".jpg", "-active.jpg" ) );
			$img.attr( "src", $img.attr("src").replace(".jpg", "-active.jpg") );
		}
	});
	
	$('.onlyinstockCatalog').click(function(){
		document.onlyinstock.submit();
		return false;
	});
	
	$('.contactButton').click( function() {
		showBusyLayer();
		autoVertical("#popupContact");
		
		$("#feedbackForm").css( "display", "block" );
		$("#feedbackInfo").css( "display", "none" );
		$("#feedbackInfo").text( "" );
		
		$("#popupContact").css( "display", "block" );
	});
	$('#busy_layer, #rightTop, #rightTopT').click( function() {
		closePopup();
	});
	
	
	/*Кнопка "Заказать" в категории товаров*/
	$('.button-order').click( function(){
		var tempID = $(this).attr('rel'); //Идентификатор товара
		var thisButton = $(this);
		
		if ( tempID > 0 ) {
			$.ajax({
				url: '/shop.ajax.php',
				data: 'ajaxaction=getRyad&id_product=' + tempID,
				success: function(data) {
					showBusyLayer();
					
					autoVertical("#popupSizeraid");
					$("#popupSizeraidTable").html( data );
					$("#popupSizeraid").css("display", "block");
				}
			});
		} else {
			alert( 'Ошибка' );
		}
		return false;
	});

	/*Кнопка "Заказать" в категории товаров*/
	
	//Открываем подробно о товаре
	$(".urbanoCatalogItemFoto img").click( function() {
		var id = $(this).attr("rev");
		getTovar( id, 0 );
		return false;
	});
	//Открываем подробно о товаре

});

	function clickOrder() {
		var id = $("#roomMainHeadMyorder").attr( "id", "roomMainHeadMyorderA");
		$("#roomMainHeadMydataA").attr( "id", "roomMainHeadMydata");
		$("#roomMainHeadMydataText").css("display", "none");
		$("#roomMainHeadMyorderText").css("display", "block");
	}
	function clickData() {
		var id = $("#roomMainHeadMydata").attr( "id", "roomMainHeadMydataA");
		$("#roomMainHeadMyorderA").attr( "id", "roomMainHeadMyorder");
		$("#roomMainHeadMydataText").css("display", "block");
		$("#roomMainHeadMyorderText").css("display", "none");
	}

	function buyRyadPopup() {
		
		var id = $("#id_product_popup").val();
		
		if ( id > 0 ) {
			var ajax_str = '';
			var count_all   = 0;
			var count_false = 0;	
			
			$("#popupSizeraidTable").find(".sizebox_item").each(function( i ) {
				var value = $(this).val();
				
				count_all++;
				
				if ( value >= 0 ) {
					ajax_str += value + ',';
					if ( value == 0 ) {
						count_false++;
					}
				} else {
					ajax_str += '0,';
					count_false++;
				}				
			});
			
			if ( ajax_str != '' ) {
				if ( count_all != count_false ) {
					$.ajax({
						url: '/shop.ajax.php',
						data: 'ajaxaction=addfullcart&id_product=' + id + '&count=' + ajax_str,
						success: function(data) {
							if ( data != 0 ) {
								$(".urbanoPopup").css( "display", "none" );
									
								$("#popupAddText").html( data );
								autoVertical("#popupAdd");
								$("#popupAdd").css("display", "block");
								
								$("#productList").find(".urbanoCatalogItemBuy[rel=" + id +"]").css('display', 'none');
								$("#productList").find("#itemyes-" + id).css('display', 'block');
								$("#shop-cart").css( "display", "block" );
							} else {
								alert( data );
							}
						}
					});
				} else {
					alert( 'Вы не ввели количество размерных рядов' );
				}
			} else {
				alert( "Ошибка" );
			}
		} else {
			alert( "Ошибка" );
		}	
	}

function buyPopup( id ) {
	if ( id > 0 ) {
		var ajax_str = '';
		var count_all   = 0;
		var count_false = 0;
		$("#descrTextRaid").find("input").each(function( i ) {
			var value = $(this).val();
			
			count_all++;
			
			if ( value >= 0 ) {
				ajax_str += value + ',';
				if ( value == 0 ) {
					count_false++;
				}
			} else {
				ajax_str += '0,';
				count_false++;
			}
		});

		if ( ajax_str != '' ) {
			if ( count_all != count_false ) {
				$.ajax({
					url: '/shop.ajax.php',
					data: 'ajaxaction=addfullcart&id_product=' + id + '&count=' + ajax_str,
					success: function(data) {
						if ( data != 0 ) {
						
							autoVertical("#popupAdd", 1 );
							$("#popupAdd").css("display", "block");
						
							$("#buyButtonBlock").html( data );
							$("#productList").find(".urbanoCatalogItemBuy[rel=" + id +"]").css('display', 'none');
							$("#productList").find("#itemyes-" + id).css('display', 'block');
							$("#shop-cart").css( "display", "block" );
						}
					}
				});
			} else {
				alert( 'Вы не ввели количество размерных рядов' );
			}
		} else {
			alert( "Ошибка" );
		}
	} else {
		alert('Ошибка');
	}
}

function getTovar( id, type ) {
	if ( id > 0 ) {
	
	showBusyLayer();
	autoVertical("#popupAjax");
	$("#popupAjax").css( "display", "block" );
		$.ajax({
			url: "/shop.ajax.php?ajaxaction=getTovar",
			type: "POST",
			data: { id : id, type:type },
			dataType: "html",
			success: function( data ){
				$("#popupAjax").html( data );
				$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
			}
		});
	} else {
		alert( "Ошибка" );
	}
	return false;
}

function urbano_feedback() {
	var name = $("#urbano_fb_name").val();
	var text = $("#urbano_fb_text").val();
	var phone = $("#urbano_fb_phone").val();
	var email = $("#urbano_fb_email").val();
	var city = $("#urbano_fb_city").val();

	if ( name != '' && text != '' && phone != '' && email != '' && city != '' ) {
		$.ajax({
			url: "/shop.ajax.php?ajaxaction=feedback",
			type: "POST",
			data: {
				name : name, 
				text: text,
				phone: phone,
				city: city,
				email: email
			},
			dataType: "html",
			success: function( data ){
				$("#feedbackForm").css( "display", "none" );
				$("#feedbackInfo").css( "display", "block" );
				$("#feedbackInfo").html( data );
				
				$("#urbano_fb_name").val("");
				$("#urbano_fb_text").val("");
				$("#urbano_fb_email").val("");
				$("#urbano_fb_phone").val("");
				$("#urbano_fb_city").val("");
			}
		});
	} else {
		alert( "Необходимо заполнить все поля!" );
	}
}


function onPage( value ) {
	if ( value == 10 || value == 20 || value == 40 || value == 60 || value == 1000 ) {
		$("#onpage_value").val( value )
		document.onpage.submit();
	}
}

function changeTab() {
	$(".descrTextLinkTab").click( function() {
		var id = $(this).attr("id");
		
		$("#descrTextList li").attr("id", "");
		$(".descrTextListTab").css( "display", "none" );
		
		if ( id == "descrTextLinkTab1" ) {
			$("#descrTextListTab1").css( "display", "block" );
		} else if ( id == "descrTextLinkTab2" ) {
			$("#descrTextListTab2").css( "display", "block" );
			$("#dostavkaScroll").jScrollPane();
			$(".jScrollPaneContainer").css("width", "380px");
		} else if ( id == "descrTextLinkTab3" ) {
			$("#descrTextListTab3").css( "display", "block" );	
			$("#oplataScroll").jScrollPane();
			$(".jScrollPaneContainer").css("width", "380px");
		}	
		$(this).parent().attr("id", "actionList");
		return false;
	});
}

function nextItem( id ) {
	if ( id > 0 ) {
		$next = $("#productList #urbanoItem-" + id).next();
		var id_next = $next.attr("id").replace("urbanoItem-", "");
		getTovar(id_next, 0);
		$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
	} else {
		alert( 'Ошибка' );
	}
}

function prevItem( id ) {
	if ( id > 0 ) {
		$prev = $("#productList #urbanoItem-" + id).prev();
		var id_prev = $prev.attr("id").replace("urbanoItem-", "");
		getTovar(id_prev, 0);
		$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
	} else {
		alert( 'Ошибка' );
	}
}

function closePopup() {
	hideBusyLayer();
	$(".urbanoPopup").css( "display", "none" );
}

function autoVertical( id, type ) {
	var scrollTop = $(document).scrollTop();
	
	var top = 0;
	top = $(id).css("top").replace("px", "");
	
	if ( type == 1 ) {
		var topmargin = scrollTop + 220;
	} else {
		var topmargin = scrollTop + 120;
	}
	
	$( id ).css({
		top: topmargin,
		left: ($(window).width() - $( id ).outerWidth())/2
	});
}

function setShortImg( id ) {
	var rel = $( id ).attr("rel");
	var href = $( id ).attr("href");
	if ( rel != '' && href != '' ) {
		$("#fullImg img").attr("src", rel );
		$("#fullImg a").attr("href", href );
		$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
	} else {
		alert();
	}
}

function getOrder( id ) {
	if ( id > 0 ) {
		
		showBusyLayer();
		autoVertical("#popupAjaxCart");
	
		$.ajax({
			url: "/shop.ajax.php?ajaxaction=getOrder",
			type: "POST",
			data: {
				id : id
			},
			dataType: "html",
			success: function( data ){
				$("#popupAjaxCart").html( data );
				$("#popupAjaxCart").css( "display", "block");
			}
		});	
	
	} else {
		alert( 'Ошибка' );
	}
}
