﻿//###############################################################################################################################
//Company:          Webize Interactive Media
//Programmer:       Ryan McDaniel
//Creation Date:    03/30/2011
//Description:      This file will store all functions related to the display and overlays of different portfolio resources. 
//                  Resources can appear on multiple pages.
//###############################################################################################################################

//include any dependent javascript files (path is relative to the file which is including this file)
IncludeJS("/js/modernizr-1.6.min.js");

function CreateOverlays() {
    var isLoaded = false;
    $("img[rel]").overlay({ mask: '#000', effect: 'apple', top: '0%', onLoad: function() { isLoaded = true; }, onClose: function() { var player = document.getElementById(this.getTrigger().attr('rel') + 'p'); if ((player) && (isLoaded == true)) { if (navigator.appName == 'Microsoft Internet Explorer') { player.sendKillToFlash(); } } var myVideo = document.getElementById(this.getTrigger().attr('rel') + 'v'); if (myVideo) { StopVideo(myVideo); } isLoaded = false; } });
    $("img[rel]").mouseenter(function() { $(this).fadeTo(300, .3); });
    $("img[rel]").mouseout(function() { $(this).fadeTo(300, 1); });

    $("img.swap-video").click(function(event) {
        var placeHolderID = $(this).attr('rel') + 'd';                  //where the <video> tag or <object> tag will be written to
        var objPlaceHolder = document.getElementById(placeHolderID);    //the object reference to the div where the markup will be written
        var videoID = $(this).attr('rel') + 'v';                        //the id for the HTML 5 <video> tag
        var videoName = $(this).attr('video');                          //the name of the video without the extension
        var flashVideoID = $(this).attr('rel') + 'p';                   //the id for the <object> tag used to display the flash fallback
        var posterPath = $(this).attr('poster');                        //the path and name of the image to use for the poster attribute in the <video> tag
        var videoMarkup = "";                                           //string to build markup for HTML 5 <video> tag or <object> tag

        //Modernizr.video will check the browser for HTML 5 support
        if (Modernizr.video) {
            //create <video> tag markup
            var codecs = { 'mp4': 'video/mp4', 'ogv': 'video/ogg; codecs="theora, vorbis"' };
            var codecType, sourceTag = '';

            sourceTags = '';
            for (codecType in codecs) {
                sourceTags += "<source src='videos/" + videoName + codecType + "' type='" + codecs[codecType] + "'>";
            }

            videoMarkup = '<video id="' + videoID + '" autoplay poster="' + posterPath + '" controls width="640px" height="480px">' + sourceTags + '</video>'
        }
        else {
            //create <object> tag markup
            videoMarkup += '<object id="' + flashVideoID + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="640" height="480">';
            videoMarkup += '<param name="movie" value="videos/player.swf" />';
            videoMarkup += '<param name="quality" value="high" />';
            videoMarkup += '<param name="allowFullScreen" value="true" />';
            videoMarkup += '<param name="FlashVars" value="videoSource=rtmp://webizefvs.cdnetworks.net/webizefvs/flashstream/mp4:csmg/' + videoName + 'mp4" />';
            videoMarkup += '<embed type="application/x-shockwave-flash" src="videos/player.swf" FlashVars="videoSource=rtmp://webizefvs.cdnetworks.net/webizefvs/flashstream/mp4:csmg/' + videoName + 'mp4" allowFullScreen="true" quality="high" width="640" height="480" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
            videoMarkup += '</object>';
        }

        objPlaceHolder.innerHTML = videoMarkup;
    });
}

function StopVideo(myVideo) {
    //myVideo will be HTMLUnknownElement if HTML5 is not supported, so if currentTime is undefined, skip this
    if (myVideo.currentTime) {
        myVideo.currentTime = 0.0;
        myVideo.pause();
    }
}

//This function will dynamically build a <script> tag to include another javascript file.
function IncludeJS(jsPath) {
    var script = document.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.setAttribute("src", jsPath);
    document.getElementsByTagName("head")[0].appendChild(script);
}
