//adaugare cos
$j(".buyNow").live("click", function() {
    
    var product_id = $j(this).attr("rel");
    
    if($j("#impachetareCadou").attr("checked")) {
        product_id += ", " + $j("#impachetareCadouProductId").val() ;
    }
    
    new Ajax.Request
	(
		'/default/cart/add/shop/' + module + '/id/' + product_id,
		{
			method: 'get',
			onSuccess: function(transport) { 
			
			    var successURL = webroot + "messages/product-add-success/";
                ALERT_show('', successURL);
                
                //update cart info 
                updateCartInfo();
			    
			}
		}
	);
    
    return false;
});



$j(document).ready(function() {
    $j("#buyNow").find("img").hover(
        function() {
            this.src = this.src.replace("2", "1");
        },
        
        function() {
            this.src = this.src.replace("1", "2");
        }
    );
});

$j(document).ready(function () {
    $j("#impachetareCadou").siblings("a").toggle(
        function () {
            $j(this).prev(":checkbox").attr("checked", "checked");
            $j(this).find("img").attr("src", webroot + "img/product/bifa-2.gif");
        }, 
        function() {
            $j(this).prev(":checkbox").attr("checked", "");
            $j(this).find("img").attr("src", webroot + "img/product/bifa-1.gif");
        }
    );
});

$j(document).ready(function() {
    if($j(".sizeBlock > a").size() == 1) {
        $j(".sizeBlock").find("a").trigger("click");
    }  else if($j(".sizeBlock > a").size() == 0) {
        $j("#buyNow").parent("div").html("<div style='margin:40px auto; text-align:center; font-weight:bold;'>Produs Indisponibil</div>");
    }
});

function adaugaGiftCardCos(counter)
{
   productId = $('giftCardSelect_' + counter).value;
   location.href= '/cart/add/id/' + productId + '/quantity/1'; 
}

function displayAssociationLink(categories_id)
{
	$('association_' + categories_id).style.display = 'block';
	$('association1_' + categories_id).style.display = 'block';
}

function closeAssociationLink(categories_id)
{
	$('association_' + categories_id).style.display = 'none';
	$('association1_' + categories_id).style.display = 'none';
}

function openProductLink(categories_id)
{
	location.href= '/product/description/id/' + categories_id;
}


//select manu
$j("#productListingAjax > a").live("click", function() {
    var url = $j(this).attr("href") + "/ajax/true";
    
    $j("#beautyProductsAjax").html("<img class='loadingAnimation' src='" + webroot + "img/loadingAnimation.gif' alt='Loading...' />");
    $j("#beautyProductsAjax").load(url, initManufacturer);
    
    $j(this).addClass("VioletText Bold").siblings().removeClass("VioletText Bold");
    
    $j.scrollTo(0, 500);
    
    return false;
});

function initManufacturer()
{
    if($j.beautyAutoClick.secondClick) {
        //default select
        $j("#beautyProductsAjax").find("a:nth(" + $j.beautyAutoClick.secondClick + ")").trigger("click");
        $j.beautyAutoClick.secondClick = false;
    } else {
        $j("#beautyProductsAjax").find("a:first").trigger("click");
    }
}

//////////////////////////////////


//select product
$j("#beautyProductsAjax > a").live("click", function() {
    var url = $j(this).attr("href") + "/ajax/true";
    
    $j("#productDescriptionAjax").html("<img class='loadingAnimation' src='" + webroot + "img/loadingAnimation.gif' alt='Loading...' />");
    $j("#productDescriptionAjax").load(url, initDescription);
    
    $j(this).addClass("VioletText Bold").siblings().removeClass("VioletText Bold");
    
    return false;
});


  



function updateAssociation()
{
    var currentCategory = $F("currentCategory");
    var url = webroot + "category/category-images/categoryId/" + currentCategory + "/ajax/true";
    
    $j("#categoryAssociation").html("<img class='loadingAnimation' src='" + webroot + "img/loadingAnimation.gif' alt='Loading...' />");
    $j("#categoryAssociation").load(url);
}

function initDescription(transport)
{        
    tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
    ALERT_init('a.alertbox, area.alertbox, input.alertbox');
    
    $j("#buyNow").find("img").hover(
        function() {
            this.src = this.src.replace("2", "1");
        },
        
        function() {
            this.src = this.src.replace("1", "2");
        }
    );
    
    $j("#impachetareCadou").siblings("a").toggle(
        function () {
            $j(this).prev(":checkbox").attr("checked", "checked");
            $j(this).find("img").attr("src", webroot + "img/product/bifa-2.gif");
        }, 
        function() {
            $j(this).prev(":checkbox").attr("checked", "");
            $j(this).find("img").attr("src", webroot + "img/product/bifa-1.gif");
        }
    );
    
    if($j(".sizeBlock > a").size() == 1) {
        $j(".sizeBlock").find("a").trigger("click");
    } else if($j(".sizeBlock > a").size() == 0) {
        $j("#buyNow").parent("div").html("<div style='margin:40px auto; text-align:center; font-weight:bold;'>Produs Indisponibil</div>");
    }
    
    
    $j(".rounded").corner();
    
}
