﻿/** ###########################################################
##########     script for video information popups     ########
############################################################### */

var popup = {
    bindEvent: function(element) {
        jQuery(element).click(
            function(e) {
                var feature_name = jQuery(this).attr('id');
                if (feature_name == '') return;
                var more_link = jQuery(this).children("#moreLink");
                more_link.attr("href", "javascript:void(0);");
                jQuery.post("/Windows/Framework/Services/ILike.ashx", {
                    action: "ilikecount",
                    featureName: feature_name
                },
                function(data) {
                    if (data > 0) {
                        jQuery("#" + feature_name + " .popupContainer .popup_content #ilike #count").html(data);
                        jQuery("#" + feature_name + " .popupContainer .popup_content #ilike").show();
                        //adjust height of shadow relative to content
                        var shadow_height = jQuery("#" + feature_name + " .popupContainer .popup_content").height() + 19 + "px";
                        jQuery("#" + feature_name + " .popupContainer .popup_shadow").css("height", shadow_height);
                    }
                },
                "text");
                jQuery("#" + feature_name).children(".popupContainer").show(1,
                    function() {
                        //adjust height of shadow relative to content
                        var shadow_height = jQuery("#" + feature_name + " .popupContainer .popup_content").height() + 19 + "px";
                        jQuery("#" + feature_name + " .popupContainer .popup_shadow").css("height", shadow_height);
                      })
                      jQuery("#ClosePopup").width(jQuery(document).width() - 21).height(jQuery(document).height()).show();
            }
        );
    },
    downlevel: function() {
        jQuery(".videoList .imagelist .imagelistLeft a").attr("href", "javascript:void(0);");
        jQuery(".videoList .imagelist .imagelistRight a").attr("href", "javascript:void(0);");
    }
};

jQuery(document).ready(function() {
  popup.bindEvent('.win7_popup');
  popup.downlevel();
  jQuery("#ClosePopup").click(function() {
    jQuery(this).hide();
    jQuery(".popupContainer").hide();
  });
});

function closeVideoPopup(feature_name) {
  jQuery("#" + feature_name).children(".popupContainer").hide();
  jQuery("#ClosePopup").hide();
}

/** ###########################################################
##########     script for tutorials     #######################
############################################################### */

function onSilverlightError(sender, args) {

    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    }
    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n";

    errMsg += "Code: " + iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}

function onCloseTutorialPopup() {
    jQuery("#silverlightTutorialHost").html("");
}

function drawSilverlight(emulationId) {
    var objectHtml = "<object data=\"data:application/x-silverlight-2,\" type=\"application/x-silverlight-2\" width=\"950px\" height=\"600px\">";
    objectHtml += "<param name=\"source\" value=\"../windows-7/media/tutorials/ClientBin/MicrosoftWindows7.xap\"/>";
    objectHtml += "<param name=\"onerror\" value=\"onSilverlightError\" />";
    objectHtml += "<param name=\"background\" value=\"white\" />";
    objectHtml += "<param name=\"minRuntimeVersion\" value=\"2.0.31005.0\" />";
    objectHtml += "<param name=\"autoUpgrade\" value=\"true\" />";
    objectHtml += "<!--<param name=\"splashscreensource\" value=\"SplashScreen.xaml\"/>";
    objectHtml += "<param name=\"onSourceDownloadProgressChanged\" value=\"onSourceDownloadProgressChanged\" />-->";
    objectHtml += "<param name=\"initParams\" value=\"emulation=" + emulationId + ",lang=en\" />";
    objectHtml += "<a href=\"http://go.microsoft.com/fwlink/?LinkID=124807\" style=\"text-decoration: none;\">";
    objectHtml += "<img src=\"http://go.microsoft.com/fwlink/?LinkId=108181\" alt=\"Get Microsoft Silverlight\" style=\"border-style: none\"/>";
    objectHtml += "</a>";
    objectHtml += "</object>";
    objectHtml += "<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>";
    jQuery("#silverlightTutorialHost").html(objectHtml);
    $find('TutorialModalBehavior').show();
}

/** ###########################################################
##########     script for tour          #######################
############################################################### */

function onCloseTourPopup() {
    jQuery("#silverlightControlHost").html("");
}

function openTourPopup() {
    var objectHtml = "<object id=\"SGT\" data=\"data:application/x-silverlight-2,\" type=\"application/x-silverlight-2\" width=\"100%\" height=\"100%\">";
    objectHtml += "<param name=\"source\" value=\"features/ClientBin/SGTLoader.xap\"/>";
    objectHtml += "<param name=\"background\" value=\"white\" />";
    objectHtml += "<param name=\"minRuntimeVersion\" value=\"2.0.31005.0\" />";
    objectHtml += "<param name=\"autoUpgrade\" value=\"true\" />";
    objectHtml += "<param name=\"onload\" value=\"onLoad\" />";
    objectHtml += "<param name=\"windowless\" value=\"true\" />";
    objectHtml += "<param name=\"initParams\" value=\"LoaderResourceLocation=Resources/Loader.xap,";
    objectHtml += "FullMainUIXapLocation=Win7SGT.xap, SimplifiedMainUIXapLocation=SimplifiedWin7SGT.xap, MainUIResourceLocation=Resources/MainUI.xap,";
    objectHtml += "WelcomeVideoLocation=http://mediadl.microsoft.com/mediadl/www/w/windows/windows-7/FeatureVideos/WelcomeSetVideo.wmv,";
    objectHtml += "MediaVideoLocation=http://mediadl.microsoft.com/mediadl/www/w/windows/windows-7/FeatureVideos/MediaSetVideo.wmv,";
    objectHtml += "CafeVideoLocation=http://mediadl.microsoft.com/mediadl/www/w/windows/windows-7/FeatureVideos/CafeSetVideo.wmv,";
    objectHtml += "OfficeVideoLocation=http://mediadl.microsoft.com/mediadl/www/w/windows/windows-7/FeatureVideos/OfficeSetVideo.wmv\"/>";
    objectHtml += "<a href=\"http://go.microsoft.com/fwlink/?LinkID=124807\" style=\"text-decoration: none;\">";
    objectHtml += "<img src=\"/windows/windows-7/features/clientbin/downlevel.jpg\" alt=\"Get Microsoft Silverlight\" style=\"border-style: none\"/>";
    objectHtml += "</a>";
    objectHtml += "<div id=\"dlBottomContainer\"> </div>";
    objectHtml += "</object>";
    objectHtml += "<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>";
    jQuery("#silverlightControlHost").html(objectHtml);
    jQuery(".tourClose").css("display", "block");
    $find('TourModalBehavior').show();
}

//tour logic to support users without silverlight and without javascript
jQuery(document).ready(function() {
    jQuery("#videoTourList li.videoDownlevel").each(
    	function() {
    	    var listItem = this.id;
    	    jQuery("a", this).each(
    	        function() {
    	            this.href = "javascript:openVideoPopup('" + listItem + "');";
    	        });
        });
    	
    if (!Silverlight.isInstalled("2.0")) {
        jQuery("#win7TourTrigger a").each(
    	    function() {
    	        this.href = "http://go.microsoft.com/fwlink/?LinkID=124807";
    	    });
    }
    else {
        jQuery(".tourDownlevel").hide();
        jQuery("#tourThumb").attr("src", tourThumbNoBadge);
    }
});