var productID = "";

$(document).ready(function() {
    productID = $("span.hiddenFamilyCode").html(); //$.query.get('id');
    loadOtherProducts();
    addAdditionalModelsListeners();
    loadFancyBox();
    loadAccessoriesAccordion();
});

function loadAccessoriesAccordion() {
    $("div#accessoriesBox a.butAccessories").click(function() {
        $(this).nextAll("div.itemWrapper").first().slideToggle();
        $(this).nextAll("a.accessoiresFix").first().toggleClass("faqSectionActive");
        return false;
    });
    $("div#accessoriesBox a.accessoiresFix").click(function() {
        $(this).nextAll("div.itemWrapper").first().slideToggle();
        $(this).toggleClass("faqSectionActive");
        return false;
    });
}

function loadFancyBox(){
    $("a.fancyBox").attr('rel', 'gallery').fancybox();
    $("a#pictureGalleryLink").click(function(){
        $("a.fancyBox:first-child").trigger('click');
        return false;
    });

}

function addAdditionalModelsListeners() {
    $("div.additionalModels img").click(function() {
        var split = $(this).attr("id").split("_");
        if (split.length >= 2) {
            var famID = split[1];
            var famVariation = split[2];
            var bigLink = "/_img/products/img_" + famID + "_family_" + famVariation + "_big.jpg";
            $("img#mainPic").attr("src", bigLink);
        }
    });
}

function hideUnnecessaryModelColumns(hasValAPP,hasValBatt,hasValBattRech,hasValIntCal,hasValIPRating,hasValE)
{
	if (!hasValAPP)
		$("th.APP, td.APP").hide();
	if (!hasValBatt)
		$("th.Battery, td.Battery").hide();
	if (!hasValBattRech)
		$("th.RechargableBattery, td.RechargableBattery").hide();
	if (!hasValIntCal)
		$("th.CAL_INT, td.CAL_INT").hide();
	if (!hasValIPRating)
		$("th.IPrated, td.IPrated").hide();
	if (!hasValE)
		$("th.EForApprovedModels, td.EForApprovedModels").hide();
}

function loadOtherProducts() {
    $.ajax({
        type: "POST",
        url: websService + "/OtherProductsYouMightLike",
        data: '{"selectedFamilyID":"' + productID + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(json) {
            res = eval('(' + json.d + ')');

            $("div#wrapperCarrousel").show();

            var compareURL = loadSlider(res, "Carousel", "../", true); //from slider.js

            if (res == null || res.length == 0) {
                $("div#wrapperCarrousel").hide();
                $("a#relatedProdAnchorLink").hide();                
            }

            if (res.length > 4)
                $("a#CarouselNext, a#CarouselPrevious").show();
            if (res.length <= 3) {
                $("div#butCompare").show();
                $("div#butCompare a").attr("href", compareURL);
            }

        }
    });
}

//------ opens Pop-Up "Buy now" (rmi) ------
function openBuyNowPopUp(URL, popWidth, popHeight) {
    var XPos = (screen.width / 2) - (popWidth / 2);
    var YPos = (screen.height / 2) - (popHeight / 2);
    var CenteredPos = "left=" + XPos + ",top=" + YPos;
    window.open(URL, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,status=1,width=' + popWidth + ',height=' + popHeight + ',resizable=1,' + CenteredPos);
    return false;
}



