	
	var CATEG_CURRENT = '';
	var BRAND_SCROLL = 0;
	var BRAND_SCROLLER_ANIMATED = false;
	var PRODUCT_SCROLLER_PAGE = 0;
	var PRODUCT_SCROLLER_ANIMATED = false;
	
	$(function() {
		//$('.hp_image_hover img').css({opacity: .75});
		$('.product_box img, .collection_box img').css({opacity: .87});
		
		$('#hp_fashion_collection h1 a, #hp_beauty_collection h2 a').hover(
			function() {
				$(this).animate({ paddingTop: "250px", paddingBottom: "60px", opacity: .87}, 500);
			},
			function() {
				$(this).animate({ paddingTop: "290px", paddingBottom: "20px", opacity: .66 }, 250);
			}
		);
		
		$('.product_box img, .collection_box img').hover(
			function() {
				$(this).animate({ opacity: 1}, 250);
			},
			function() {
				$(this).animate({ opacity: .75 }, 50);
			}
		);
		
		//menu_hover(MENU_CURRENT);
		/*
		$('ul#envy_menu > li').hover(
			function () {
				if (this.id != MENU_SELECTED) {
					menu_hover(this.id);
					//$('#sub' + this.id).css('display', 'block');
				}
			}, 
			
			function () {
				//$('#submenu > ul:visible').css('display', 'none');
				//$('#sub' + this.id).css('display', 'none');
			}
		);
		
		/*
		$('p.section-header > a').click(
			function() {
				if (CATEG_CURRENT != this.id) {
					$('div.category_list > div:visible').slideUp('fast');
					$('#sub' + this.id).slideDown('fast');
					CATEG_CURRENT = this.id;
					return false;
				}
			}
		)
		*/
		
		$('#brands_down_scroller').click(
			function() {
				if (BRAND_SCROLLER_ANIMATED) return false;
				
				var y_pos = parseInt($("#brands_scroller_list").css('marginTop').replace('px', ''));
				var y_dim = parseInt($("#brands_scroller_list").css('height').replace('px', ''));
				y_dim = -(y_dim - 400);
				
				if (y_pos < y_dim) return false;
				
				BRAND_SCROLLER_ANIMATED = true;
				
				$("#brands_scroller_list").animate({ marginTop: "-=200px" }, 500, function() { BRAND_SCROLLER_ANIMATED = false } );
			}
		)
		
		$('#brands_up_scroller').click(
			function() {
				if (BRAND_SCROLLER_ANIMATED) return false;
				
				var y_pos = parseInt($("#brands_scroller_list").css('marginTop').replace('px', ''));
				var y_dim = parseInt($("#brands_scroller_list").css('height').replace('px', ''));
				
				if (y_pos >= 0) return false;
				
				BRAND_SCROLLER_ANIMATED = true;
				
				$("#brands_scroller_list").animate({ marginTop: "+=200px" }, 500, function() { BRAND_SCROLLER_ANIMATED = false } );
			}
		)
	});
	
	function menu_hover(menu_id) {
		if (menu_id == MENU_SELECTED) false;
		
		//$('#sub' + MENU_SELECTED).fadeOut(100); 
		$('#submenu > ul:visible').hide();
		//$('#' + menu_id).css('background', 'transparent url(http://img.envy.ro/img/new_envy/menu_bg_curent.jpg) repeat-x;');
		$('#sub' + menu_id).fadeIn(500);
		
		MENU_SELECTED = menu_id;
	}
	
	function product_scroller_left() {
		if (PRODUCT_SCROLLER_PAGE == 0) return false;
		if (PRODUCT_SCROLLER_ANIMATED) return false;
		
		var next_page = 'products_page_' + PRODUCT_SCROLLER_PAGE;
		PRODUCT_SCROLLER_PAGE--;
		var prev_page = 'products_page_' + PRODUCT_SCROLLER_PAGE;
		
		PRODUCT_SCROLLER_ANIMATED = true;
		
		$('#'+prev_page).show();
		
		$('#'+prev_page).animate(
			{ marginLeft: "+=810px"}, 
			1000, 
			function() {
				$('#'+next_page).hide();
				PRODUCT_SCROLLER_ANIMATED = false;
				$('#product_scroller_page').html(PRODUCT_SCROLLER_PAGE+1);
			}
		);
	}
	
	function product_scroller_right() {
		if (PRODUCT_SCROLLER_PAGE >= PRODUCT_SCROLLER_TOTAL-1) return false;
		if (PRODUCT_SCROLLER_ANIMATED) return false;
		
		var prev_page = 'products_page_' + PRODUCT_SCROLLER_PAGE;
		PRODUCT_SCROLLER_PAGE++;
		var next_page = 'products_page_' + PRODUCT_SCROLLER_PAGE;
		
		PRODUCT_SCROLLER_ANIMATED = true;
		
		if (!document.getElementById('products_page_'+PRODUCT_SCROLLER_PAGE)) {
			$.post(
					'http://www.envy.ro/get_products_data.html',
					{ page: PRODUCT_SCROLLER_PAGE, categories: PRODUCT_CATEGORY_IDS },
					function (products) {
						if (!document.getElementById('products_page_'+PRODUCT_SCROLLER_PAGE)) {
							var html = '';
							
							html += '<div id="products_page_'+PRODUCT_SCROLLER_PAGE+'" class="products_page">';
				
							for (var cnt = 0; cnt < products.length; cnt++) {
								html += '<div id="product_'+products[cnt].id+'" class="product_box">';
								html += '<p><a href="'+products[cnt].url+'" title="'+products[cnt].name+'" ><span class="product_box_img"><img src="'+products[cnt].image+'" alt="'+products[cnt].name+'" /></span>';
								html += '<span class="product_box_txt">'+products[cnt].name+'</span></a></p>';
								html += '</div>';
							}
							
							html += '<div style="clear:both"><!-- --></div></div>';
							
							$('#product_scroller').append(html);
						}
						else {
							$('#'+next_page).show();
						}
						
						$('#'+prev_page).animate(
							{ marginLeft: "-=810px"}, 
							1000, 
							function() {
								//$('#'+next_page).animate({ marginLeft: 0});
								$('#'+prev_page).hide();
								PRODUCT_SCROLLER_ANIMATED = false;
								$('#product_scroller_page').html(PRODUCT_SCROLLER_PAGE+1);
							}
						);
					}, 
					"json"
				);
		}
		else {
			$('#'+next_page).show();
			$('#'+prev_page).animate(
						{ marginLeft: "-=810px"}, 
						1000, 
						function() {
							//$('#'+next_page).animate({ marginLeft: 0});
							$('#'+prev_page).hide();
							PRODUCT_SCROLLER_ANIMATED = false;
							$('#product_scroller_page').html(PRODUCT_SCROLLER_PAGE+1);
						}
					);
		}
		
		return false;
	}

	function validate_envy_me_form() {
		if ($('#product').val() == '') {
			$('#invalid_alert').html('Introdu denumirea produsului!');
			$('#invalid_alert').slideDown('fast');
			$('#product').focus();
			return false;
		}
		
		if ($('#brand').val() == '') {
			$('#invalid_alert').html('Introdu marca produsului!');
			$('#invalid_alert').slideDown('fast');
			$('#brand').focus();
			return false;
		}
		
		if ($('#store').val() == '') {
			$('#invalid_alert').html('Introdu numele magazinului de unde ai cumparat produsului!');
			$('#invalid_alert').slideDown('fast');
			$('#store').focus();
			return false;
		}
		
		if ($('#price').val() == '' || isNaN($('#price').val())) {
			$('#invalid_alert').html('Introdu pretul produsului!');
			$('#invalid_alert').slideDown('fast');
			$('#store').focus();
			return false;
		}
		
		if ($('#photo').val() == '') {
			$('#invalid_alert').html('Selecteaza o poza cu tine purtand produsul!');
			$('#invalid_alert').slideDown('fast');
			$('#photo').focus();
			return false;
		}
		
		return true;
		
	}
	
	function validate_comment_form() {
		if ($('#CommentTitle').val() == '') {
			alert('Introdu titlul comentariului!');
			$('#CommentTitle').focus();
			return false;
		}
		
		if ($('#CommentBody').val() == '') {
			alert('Introdu comentariului!');
			$('#CommentBody').focus();
			return false;
		}
		
		return true;
	}