﻿

//debugger;


$(document).ready(function () {
    $("[id*='cmdSurveySubmit']").click(function () {

        if (alreadyClicked) {
            $("[id*='cmdSurveySubmit']").attr("disabled", true);
            alreadyClicked = false;
        }
        else {
            alreadyClicked = true;
        }

        //scroll to bottom of page so that can be sure 
        //to see the results message
        $('html, body').animate({
            scrollTop: $(document).height()
        },1500);       
    }
    );
})


$(document).ready(function () {
    $("a[id*='moveToFAQTop']").click(function () {
        $('html, body').animate({
            scrollTop: $("#FAQ").closest('div').offset().top
        },
        1500);
        return false;
    });
})

$(document).ready(function () {
    $("a[id*='faqLink']").click(function () {
        var curId = $(this).attr("id");
        //Get first 9 letters - e.g. faqLink08
        var num = curId.substring(7, 9);
        var name = "#divFaq";
        var finalStr = name.concat(num);

//        alert(finalStr);

//        var db = $("#faq01").offset().top.toString();
//        var aim = $(finalStr).offset().top.toString();
//        var faqtop = $("#FAQ").offset().top.toString();
//        var cur = $("html").scrollTop().toString();
//        alert(db + "___" + aim + "___" + faqtop + "___" + cur);

        $('html, body').animate({
            scrollTop: $(finalStr).offset().top
        },
        1500);
        return false;
    });
})


//Hover over the glassy buttons 
$(document).ready(function () {
    //alert("inREADYAAA");
    $("#GlassBtnDownloadNow").hover(function () {
        //$(this).parent().siblings().children('a').addClass("demoLink");
        $(this).attr("src", "images/Download_230_b1.png");
    }, function () {
        $(this).attr("src", "images/Download_230_b.png");
    });
})

//Hover over the glassy buttons 
$(document).ready(function () {
    //alert("inREADYAAA");
    $("#GlassBtnBuyProNow").hover(function () {
        //$(this).parent().siblings().children('a').addClass("demoLink");
        $(this).attr("src", "images/buyPro_230_b1.png");
    }, function () {
        $(this).attr("src", "images/buyPro_230_b.png");
    });
})

//Hover over the glassy buttons 
$(document).ready(function () {
    //alert("inREADYAAA");
    $("#GlassBtnBuyNow").hover(function () {
        //$(this).parent().siblings().children('a').addClass("demoLink");
        $(this).attr("src", "images/buyNow_230_b1.png");
    }, function () {
        $(this).attr("src", "images/buyNow_230_b.png"); 
    });
})

//Hover over the glassy buttons 
$(document).ready(function () {
    //alert("inREADYAAA");
    $("#GlassBtnBuy").hover(function () {
        //$(this).parent().siblings().children('a').addClass("demoLink");
        $(this).attr("src", "images/buy_230_b1.png");
    }, function () {
        $(this).attr("src", "images/buy_230_b.png");
    });
})

    /*
    When hover over the vid scrn shot then 
    (1) img border
    (2) underline text link 
    (3) lightbulb
    */
$(document).ready(function () {
    //alert("inREADYAAA");
    $("a[id*='quickMenuPick']").hover(function () {
        //alert("hover");
        //$(this).parent().siblings().children('a').addClass("demoLink");
        $(this).parent().siblings().children('a').css('text-decoration', 'underline');
    }, function () {
        $(this).parent().siblings().children('a').css('text-decoration', '');
    });
})

//Products.cs - When hover over product box shot, then undline info link
$(document).ready(function () {
    if ($("a[id*='ProdListBoxShotLink']").length > 0) {
        $("a[id*='ProdListBoxShotLink']").hover(function () {
            var curName = $(this).attr("id");
            var nextName = curName.replace("BoxShotLink", "InfoTextLink");
            $("#" + nextName).css('text-decoration', 'underline');
        }, function () {
            var curName = $(this).attr("id");
            var nextName = curName.replace("BoxShotLink", "InfoTextLink");
            $("#" + nextName).css('text-decoration', ''); ;
        });
    }
})

//Replace Buy image from all free products with 'FREE' image on product page
$(document).ready(function () {
    if ($("#ProdListBuyImgCS").length > 0) {
        $("#ProdListBuyImgCS").attr("src", "images/buy_2c_Free_1.png");
        if ($("#ProdListBuyTextLinkCS").length > 0) {
            $("#ProdListBuyTextLinkCS").hide();
        }
        if ($("#A2quickMenuPickCS").length > 0) {
            $("#A2quickMenuPickCS").attr("href", $("#A3quickMenuPickCS").attr("href"));
        }
    }
})


/*
Make the Left column stretch to the end
*/
$(document).ready(function () {

    if ($("div[id='divLeftCol']").length > 0) {

        var mainDivBaseH = ($("#AllContentsHome").height());
        var mainDivExtraH = $("#AllContentsHome").outerHeight() -
                            $("#AllContentsHome").innerHeight();
        var mainDivTop = $("#AllContentsHome").offset().top;

        var sideDivBaseH = ($("div[id='divLeftCol']").height());
        var sideDivExtraH = $("div[id='divLeftCol']").outerHeight() -
                            $("div[id='divLeftCol']").innerHeight();
        var sideDivTop = $("#divLeftCol").offset().top;

        var sideDivTgtH = mainDivBaseH - (mainDivExtraH - sideDivExtraH);

        if ($("#tabs-3").length > 0) {
            //issue caused by height not reported correctly in FAC page due to 
            //tabbed demo
            sideDivTgtH -= 478;
        }

        //On DCFCA page, MSFT log image
        if ($("#divMsftLogo").length > 0) {
            sideDivTgtH += ($("#divMsftLogo").height()+8);
        }

//        if ($("#divSupportEmailImage").length > 0) {
//            sideDivTgtH += $("#divSupportEmailImage").height();
//        }

        //add some space at the bottom 
        sideDivTgtH += 12;

        $("div[id='divLeftCol']").css('height', sideDivTgtH + "px");
    }
})



/*
When hover over the main text link then 
update images (light blue bulb) and border around video shot
*/
$(document).ready(function () {
    $("a[id*='demoLink']").hover(function () {
        $(this).parent().children('a').children('img').attr("src", "images/VidBul_1.png");
        /*$(this).parent().siblings().children('a').children('img').addClass("imgGreenHilite");*/
        /*$(this).addClass("demoLinkDown");*/
    }, function () {
        $(this).parent().children('a').children('img').attr("src", "images/VidBul_0.png");
        /*$(this).parent().siblings().children('a').children('img').removeClass("imgGreenHilite");*/
        /*$(this).removeClass("demoLinkDown");*/
    });
})
/*  --------------------------------------------------  -----------------------------------*/

//ColLinkMainPage

//Home.cs - make light bulbs light in video links when hover over links
$(document).ready(function () {
    if ($("a[id*=ColLinkMainPage]").length > 0) {
        $("a[id*='ColLinkMainPage']").hover(function () {
            $(this).children('img').attr("src", "images/VidBul_1.png");
        }, function () {
            $(this).children('img').attr("src", "images/VidBul_0.png");
        });
    }
})


/*
When hover over the vid scrn shot then 
(1) img border
(2) underline text link 
(3) lightbulb
*/
$(document).ready(function () {
    $("a[id*='demoScrnShotLink']").hover(function () {
        $(this).parent().siblings().children('a').children('img').attr("src", "images/VidBul_1.png");
        $(this).parent().siblings().children('a').removeClass("demoLink");
        $(this).parent().siblings().children('a').addClass("demoLinkDown");
    }, function () {
        $(this).parent().siblings().children('a').children('img').attr("src", "images/VidBul_0.png");
        $(this).parent().siblings().children('a').removeClass("demoLinkDown");
        $(this).parent().siblings().children('a').addClass("demoLink");
    });

})

$(function () {
    $.superbox();
});


$(function () {

    $('#moveToProductDesc').click(function () {
        $('html, body').animate({
            scrollTop: $("#ProdDesc").closest('div').offset().top - 8
        },
        1500);
        return false;
    });

    $('#moveToSampleResults').click(function () {
        $('html, body').animate({
            scrollTop: $("#SampleResults").closest('div').offset().top - 8
        },
        1500);
        return false;
    });

    $('#moveToScreenShots').click(function () {
        $('html, body').animate({
            scrollTop: $("#ScreenShots").closest('div').offset().top - 8
        },
        1500);
        return false;
    });

    $('#moveToVideoDemos').click(function () {
        $('html, body').animate({
            scrollTop: $("#VideoDemos").closest('div').offset().top - 8
        },
        1500);
        return false;
    });

    $('#moveToDemos').click(function () {
        $('html, body').animate({
            scrollTop: $("#Demos").closest('div').offset().top - 8
        },
        1500);
        return false;
    });

    $('#moveToSupport').click(function () {
        $('html, body').animate({
            scrollTop: $("#Support").closest('div').offset().top - 8
        },
        1500);
        return false;
    });

    $('#moveToVersionInfo').click(function () {

        $('html, body').animate({
            scrollTop: $("#VersionInfo").closest('div').offset().top - 8
        },
        1500);
        return false;
    });

    $('#moveToGallery').click(function () {
        $('html, body').animate({
            scrollTop: $("#Gallery").closest('div').offset().top - 8
        },
        1500);
        return false;
    });


});


//Gallery icon - when hover over then underline link to 
//               show to user that is same link
$(document).ready(function () {
    if ($('#PosterGalleryIcon').length > 0) {
        $('#PosterGalleryIcon').hover(function () {
            //alert("in PosterGalleryIcon");
            //$(this).parent().siblings().children('a').addClass("demoLink");
            $(this).parent().siblings().children('a').css('text-decoration', 'underline');
        }, function () {
            $(this).parent().siblings().children('a').css('text-decoration', '');
        });
    }
})

$(document).ready(function () {
    if ($('#EdgeCalibrationIcon').length > 0) {
        $('#EdgeCalibrationIcon').hover(function () {
            //$(this).parent().siblings().children('a').addClass("demoLink");
            $(this).parent().siblings().children('a').css('text-decoration', 'underline');
        }, function () {
            $(this).parent().siblings().children('a').css('text-decoration', '');
        });
    }
})

//Tutorial icon - when hover over then underline link to 
//               show to user that is same link
$(document).ready(function () {
    if ($('#CubicSplineTutorial').length > 0) {
        $('#CubicSplineTutorial').hover(function () {
            //alert("in PosterGalleryIcon");
            //$(this).parent().siblings().children('a').addClass("demoLink");
            $(this).parent().siblings().children('a').css('text-decoration', 'underline');
        }, function () {
            $(this).parent().siblings().children('a').css('text-decoration', '');
        });
    }
})

$(document).ready(function () {
    if ($('#CubicSplineSampleWb').length > 0) {
        $('#CubicSplineSampleWb').hover(function () {
            //alert("in PosterGalleryIcon");
            //$(this).parent().siblings().children('a').addClass("demoLink");
            $(this).parent().siblings().children('a').css('text-decoration', 'underline');
        }, function () {
            $(this).parent().siblings().children('a').css('text-decoration', '');
        });
    }
})

//Arrow Down for Product Menu Hover  -- Disable for now. Don't know if is worth having.
$(document).ready(function () {
    //alert("first line");
    $('#productsDropDown_DISABLED').parent().hover(function () {
        $("#arrowImg").removeClass("hide");
    }, function () {
        $("#arrowImg").addClass("hide");
    });
})


//------  PRODUCT SUMMARY PAGE  ----------------------------------------

$(document).ready(function () {

    var hoverIds = ['ProdSumLink00DigitalPhotoSw', 'ProdSumLink01DigitalPhotoSw', 'ProdSumLink00DataFitSw',
                    'ProdSumLink01DataFitSw', 'ProdSumLink00GeneralSw', 'ProdSumLink01GeneralSw'];

    for (var i = hoverIds.length - 1; i > -1; i--) {
        var id = "#" + hoverIds[i];
        var prodIndex = Math.floor(i / 2);

        $(id).bind('mouseenter',{prodGroupId:prodIndex, isHighlight:true},
                SetProdSummaryHighlight)
            .bind('mouseleave', { prodGroupId: prodIndex, isHighlight: false },
                SetProdSummaryHighlight);
    }
})


function SetProdSummaryHighlight(e)
{
    //prodGroupId - 0 for Digital Photo, 1 for Data Fit, 2 for general
    var imgIds = ['DigitalPhotoSwIcon', 'DataFitSwIcon', 'GeneralSwIcon'];
    var linkIds = ['ProdSumLink01DigitalPhotoSw', 'ProdSumLink01DataFitSw', 'ProdSumLink01GeneralSw'];
    //var prodListIds = ['DigitalPhotoImg', 'DigitalPhotoImg', 'DigitalPhotoImg'];

    //Underline link
    var objExp = "[id='" + linkIds[e.data.prodGroupId.valueOf()] + "']";

    if ($(objExp).length > 0) {
        var decorate = "none";
        if (e.data.isHighlight) { decorate = "underline" }
        $(objExp).css('text-decoration', decorate);
    }

    //border of image
    var objExp = "[id='" + imgIds[e.data.prodGroupId] + "']"; 
    if ($(objExp).length > 0) {
        var borderWidth = "1px";
        if (e.data.isHighlight) { borderWidth = "2px" }

        $(objExp).css('border-width', borderWidth);
        var margin = "1px";
        if (e.data.isHighlight) { margin = "0px"; }
        $(objExp).css('margin', margin);
    }
}


//-------------------  END PRODUCT SUMMARY PAGE CODE ---------------


//+++++++++++++++++++++  product summary page side links to jump to page top +++++++++

//$(document).ready(function () {
//    if ($("#divToTopProdPage1").length > 0) {

//        var groupTop = $("#DigitalPhotoGroupHeader").offset().top;
//        var groupHeight = $("#DigitalPhotoGroupHeader").height();
//        var divHeight = $("#divToTopProdPage1").height();

//        //        console.log("groupTop:" + groupTop + " groupH:" + groupHeight +
//        //            " divHeight:" + divHeight);
//        var numProd = 3;

//        var newtop = groupTop + groupHeight - divHeight + 218 * numProd;
//        var newleft = $("#divToTopProdPage1").offset().left

//        $("#divToTopProdPage1").offset({ top: newtop, left: newleft });
//    };
//})

//$(document).ready(function () {
//    if ($("#divToTopProdPage2").length > 0) {

//        var groupTop = $("#DataFitGroupHeader").offset().top;
//        var groupHeight = $("#DataFitGroupHeader").height();
//        var divHeight = $("#divToTopProdPage2").height();

//        //        console.log("groupTop:" + groupTop + " groupH:" + groupHeight +
//        //            " divHeight:" + divHeight);
//        var numProd = 2;

//        var newtop = groupTop + groupHeight - divHeight + 218 * numProd;
//        var newleft = $("#divToTopProdPage2").offset().left

//        $("#divToTopProdPage2").offset({ top: newtop, left: newleft });
//    };
//})

//$(document).ready(function () {
//    if ($("#divToTopProdPage3").length > 0) {

//        var groupTop = $("#GeneralGroupHeader").offset().top;
//        var groupHeight = $("#GeneralGroupHeader").height();
//        var divHeight = $("#divToTopProdPage3").height();

//        //        console.log("groupTop:" + groupTop + " groupH:" + groupHeight +
//        //            " divHeight:" + divHeight);
//        var numProd = 3;

//        var newtop = groupTop + groupHeight - divHeight + 218 * numProd;
//        var newleft = $("#divToTopProdPage3").offset().left

//        $("#divToTopProdPage3").offset({ top: newtop, left: newleft });
//    };
//})

$(window).load(function () {
    if ($("#divToTopProdPage1").length > 0) {
        UpdateLinkToTop();
    };
})

$(window).scroll(function () {
    if ($("#divToTopProdPage1").length > 0){
        UpdateLinkToTop();
      }
})

function UpdateLinkToTop() {
    if ($("#divToTopProdPage1").length > 0) {

        var tp = $(window).scrollTop() + $(window).height()
            - $("#divToTopProdPage1").height()
            - 16;
        }

        var newleft = $("#divToTopProdPage1").offset().left;

        $("#divToTopProdPage1").offset({ top: tp, left: newleft });
    }

//    function GetPadding(elementName) {
//        var ptop = $("#" + elementName).css('padding-top');
//        var pbot = $("#" + elementName).css('padding-bottom');

//        var allVertPad = parseInt(ptop, 10) + parseInt(pbot, 10);
//    }
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    //LinkToTopProdPage1

    $(document).ready(function () {

        if ($("#LinkToTopProdPage1").length > 0) {

            $("#LinkToTopProdPage1").bind("click",function(){

                $('html, body').animate(
                {
                    scrollTop: 0
                    }, 1500);

            }
            )
        }
    }
    )


    //===========  Homepage 3 big links==========================


    $(document).ready(function () {

        var pics = ['DigitalPhotoSwPic', 'DataFitSwPic', 'GeneralSwPic'];
        var links = ['DigitalPhotoSwSeeLink', 'DataFitSwSeeLink', 'GeneralSwSeeLink'];
        
        for (var i = 0; i < pics.length; i++) {
            if ($("#" + pics[i]).length > 0) {
                $("#" + pics[i])
                    .bind('mouseenter', { 
                        picToHighlight: pics[i], 
                        picBorderColor: i, 
                        linkToHighlight: links[i],
                        isHighlight: true
                    }, HighlightPicAndLink)
                    .bind('mouseleave', {
                        picToHighlight: pics[i],
                        picBorderColor: i,
                        linkToHighlight: links[i], 
                        isHighlight: false
                    }, HighlightPicAndLink)
                }
                if ($("#" + links[i]).length > 0) {
                    $("#" + links[i])
                    .bind('mouseenter', {
                        picToHighlight: pics[i],
                        picBorderColor: i,
                        linkToHighlight: links[i],
                        isHighlight: true
                    }, HighlightPicAndLink)
                    .bind('mouseleave', {
                        picToHighlight: pics[i],
                        picBorderColor: i,
                        linkToHighlight: links[i],
                        isHighlight: false
                    }, HighlightPicAndLink)
                }
        }
    })

function HighlightPicAndLink(e) {

    //(1) Highlight pic with extra border
    //(2) Underline

    if ($("#" + e.data.picToHighlight).length > 0) {

        var cols = ['#4488FF', '#008F00', '#FF8844'];
        var col = cols[e.data.picBorderColor];

        if (e.data.isHighlight) {
            $("#" + e.data.picToHighlight).css('border-width', "2px");
            $("#" + e.data.picToHighlight).css('border-color', col);
            $("#" + e.data.picToHighlight).css('margin', "0px");
        }
        else {
            $("#" + e.data.picToHighlight).css('border-width', "0px");
            $("#" + e.data.picToHighlight).css('margin', "2px");
        } //end if pic exists
    }
    //look at link...
    if ($("#" + e.data.linkToHighlight).length > 0) {

        var decoration = "none";
        if (e.data.isHighlight) { decoration = "underline"; }

        $("#" + e.data.linkToHighlight).css("text-decoration", decoration);
    }

}
//===========  END Homepage 3 big links==========================


    $(document).ready(function () {

    if($("#prodMenuItem").length>0)
    {
        var l=$("#prodMenuItem").offset().left + $("#prodMenuItem").width() + 16;
        $("#prodArrowDown").offset({left: l, top:$("#prodMenuItem").offset().top +8});
    }

})

//Hide the breadcrumb for home page because nothing there but 'home'
$(document).ready(function () {
    if (typeof hideBreadCrumbMenu !== 'undefined') {
        for (var i = 0; i < 3; i++) {
            var numNoSpace = $.trim(i.toString());
            var divId = "divSitemap" + (numNoSpace);
            if ($("#" + divId).length > 0) { $("#" + divId).hide(); }
        }
    }
})

/*  ------------------------TABS----------------  -----------------------------------*/

$(document).ready(function () {
    // Tabs
    $('#tabs').tabs();
})
/*  --------------------------------------------------  -----------------------------------*/

