$(function() {

    $(".p-images").jCarouselLite({
	    btnNext: ".p-images-next",
	    btnPrev: ".p-images-prev",
	    visible: 6,
	    start: 0,
	    circular: false
    });

	$(".vote-next").jCarouselLite({
	    btnNext: ".vote-next-next",
	    btnPrev: ".vote-next-prev",
	    visible: 3,
	    start: 0,
	    circular: false
    });

    $(".rec-products").jCarouselLite({
	    btnNext: ".rec-products-next",
	    btnPrev: ".rec-products-prev",
	    visible: 7,
	    start: 0,
	    circular: false
    });

    $(".rec-view").jCarouselLite({
	    btnNext: ".rec-view-next",
	    btnPrev: ".rec-view-prev",
	    visible: 6,
	    start: 0,
	    circular: false
	  });

	  //Display the carousels until all images are loaded
		$('#product-carousel-ct-vote').css("visibility","visible");
	  $('#product-carousel-ct').css("visibility","visible");
	  $('#product-carousel-ct-rec').css("visibility","visible");
	$('#thumbs-carousel-ct').css("visibility","visible");


	  $('#love_it_not_logged').fancyZoom({width:270});
	  $('#add_to_site_link').fancyZoom();
	  $('#tell_a_friend_link').fancyZoom();
	  //$('#notify_link').fancyZoom({width:300});
	$('#login-review-link-bottom').fancyZoom({width:270});
    $('.request-login').fancyZoom({width:270});
	  $('#comp_fit').fancyZoom({width:300});

	  //Activate share this menu
	  activate_sharethis_menu();



    $("#add-to-wishlist-link").click(function(event){

        var selectedVariant = $('#product-variants').variants('option', 'variant')
        var buttonState = $("#variant-button").hasClass('enabled')

        if (buttonState){
           if($(this).parents("#zoom").length > 0){
               // we are in the popups here
               // show the toggle slides
               $("#notifyList").slideUp()
              $("#askModcloth").slideUp()
              $("#wishlistView").slideToggle()

               //setting the hidden fields on the create and add forms
               //with variant id
               $("#add-wishlist-variant").val(selectedVariant.id)
               $("#create-wishlist-variant").val(selectedVariant.id)

           }else{
			if(selectedVariant.id!='0'){
               	//we are on the details page here
                //show the popup
                $(this).fancyZoom('show')
                 // set the variant
                // an element should have unique id on a page
                $("#add-wishlist-variant").val(selectedVariant.id)
                $("#create-wishlist-variant").val(selectedVariant.id)
			}
			else{
				$('#outofstock_bubble').fadeOut('slow')
				$('#product-variants').variants('showError',"Please Select..");
			}
           }
        }else if(selectedVariant==''){
            //show required to select error where ever you are
            $('#product-variants').variants('showError',"Please Select..");

        }
    });


    // Handling Review Form

	$('#first_review_link').click(function(){
        if($('#review-form-container').is(":hidden")) {
            $('#review-form-container').slideDown('slow')
            $('#review-form-container').parent('#submit-review').css('margin-bottom', '57px')
        }
    });


});

	function validateReviewForm(){
		var radio_check=false;
		$('#label_product_rating, #label_product_review_txt, #label_fit_txt').css('color', '#4d4d4d');
		//$('#review_form_msg').show().css('background-color','none').html('&nbsp;');
		if ($('#product_star').val() <= 0) {
			$('#review_form_msg').css('background-color', 'silver').html('Please rate the product');
			$('#label_product_rating').css('color','red');
					return false;
		}
		
			if($('.radio').length==0)
				radio_check=true
			for(var i = 0; i < $('.radio').length; i++)
			{
				if(document.getElementsByName('review[fit]')[i].checked == true) 
				{
					radio_check=true
				}
			}
			if(radio_check==false)
			{
				$('#review_form_msg').css('background-color', 'silver').html('Please rate the fit of the product');
				$('#label_fit_txt').focus().css('color','red');
				return false;
			}
		
		
		if($('#product_review_txt').val() == ""){
			$('#review_form_msg').css('background-color', 'silver').html('Please review the product');
			$('#label_product_review_txt').focus().css('color','red');
					return false;
		}
	

		return true;
	}
	
	function validateCommentForm(){
		
		if($('#your-comment').val() == "" || $('#your-comment').val() == "Talk about the item here!"){
			$.jGrowl("Please enter a comment and submit", { life: 7000, theme: 'error_growl', header: 'Comment Error' });
			return false;
		}
	

		return true;
	}

    function starChange(num,el, rating_modifier){
	      document.getElementById(rating_modifier).style.width=num+'px';
	      document.getElementById(el).value=(num/20);
    }

    function init_popups(){
        $('.request-login').fancyZoom({width:270});

    }

    function remove_voting_links(review_element_id){
        $(review_element_id).find('span.voting-links').remove()
    }

