//jquery dependent function Showcase(contentValues, tnValues) { //variables var instance = this; this.buttons = {photoButton: "photo", avButton: "av"}; this.nowPlayingId = 'nowPlaying'; this.mediaPlayer = null; this.contentHeight = contentValues.contentHeight; this.contentWidth = contentValues.contentWidth; this.tnHeight = tnValues.tnHeight; this.tnWidth = tnValues.tnWidth; this.selectedList; this.selectedItem = 0; this.previousList; this.previousItem = 0; this.showcaseLists = new Array(); //constants this.tnDefinedHeight = 36; this.captionWidthOffset = 28; this.captionHeightOffset = 26; this.tnLeftMargin = 5; this.tnBotMargin = 10; this.navTop = 31; this.types = {646:'flv', 701:'mp4', 706:'mp3'}; this.defaultTn = {audio: '/docs/TEMPLATE/458/audio.png'}; //methods this.initShowcaseList = initShowcaseList; this.initMediaPlayer = initMediaPlayer; this.playMedia = playMedia; this.getItem = getItem; this.updateSelected = updateSelected; this.switcher = switcher; this.initButtons = initButtons; this.centerTn = centerTn; this.showCaption = showCaption; this.updateNowPlaying = updateNowPlaying; this.showAudioCaption = showAudioCaption; this.hideAudioCaption = hideAudioCaption; } function showAudioCaption() { } function hideAudioCaption() { } function updateNowPlaying(title) { $('#' + this.nowPlayingId + ' > h3').html(title); } function initButtons(moduleID) { var instance = this; function addButton() { $("#" + this.id).click(function(){ instance.switcher(this.id); }); } for (var button in instance.buttons) { $("#" + button).each(addButton); } // this.switcher(moduleID); $("#avButton > img:first").attr("src", "/docs/IO/19471/video_active.gif"); $("#photoButton > img:first").attr("src", "/docs/IO/19471/photos.gif"); } function showCaption(showcaseList, id, show) { var caption = $("#videoCaption"); if(show) { var captionObj = $("#" + id + " > .caption"); var object = this; var item = this.getItem(showcaseList, id, false); if(item.caption.title == null) caption.find("span.title").html(""); else caption.find("span.title").html(item.caption.title); if(item.caption.description == null) caption.find("span.description").html(""); else caption.find("span.description").html(item.caption.description); caption.show(); caption.find(".arrow > img").css("left", (item.index %5 * (this.tnLeftMargin + this.tnWidth+2)) + 22 + "px"); caption.css("top", (Math.floor(item.index/5) * (this.tnBotMargin + this.tnHeight+2)) + this.navTop + this.captionHeightOffset + "px"); } else { caption.hide(); } } function switcher(buttonID) { var object = this; switch(this.buttons[buttonID]) { case "photo": if(this.selectedList == "photoList") return; $("#videoHeader").hide(); $("#videoList").hide(); $("#audioHeader").hide(); $("#audioList").hide(); $("#avPlayer").empty(); $("#avPlayer").hide(); $("#avButton > img:first").attr("src", "/docs/IO/19471/video.gif"); $("#photoPlayer").show(); $("#photoHeader").show(); $("#photoList").show(); $("#photoCaption").show(); $("#photoButton > img:first").attr("src", "/docs/IO/19471/photos_active.gif"); var playable = false; if(this.showcaseLists["photoList"] == undefined) playable = this.initShowcaseList("photoList", false); if (playable) { var currentList = this.previousList; var currentItem = this.previousItem; this.previousList = this.selectedList; this.previousItem = this.selectedItem; this.playMedia(currentList, this[currentList][currentItem].id, true); } break; case "av": if(this.selectedList == "videoList" || this.selectedList == "audioList") return; $("#photoHeader").hide(); $("#photoList").hide(); $("#photoPlayer").hide(); $("#photoCaption").hide(); $("#photoButton > img:first").attr("src", "/docs/IO/19471/photos.gif"); var currentList = this.previousList; var currentItem = this.previousItem; this.previousList = this.selectedList; this.previousItem = this.selectedItem; this.updateSelected(currentList, currentItem); $("#avPlayer").show(); $("#avButton > img:first").attr("src", "/docs/IO/19471/video_active.gif"); this.initMediaPlayer(this.mediaPlayerURL); $("#videoHeader").show(); $("#videoList").show(); $("#audioHeader").show(); $("#audioList").show(); break; } } function updateSelected(showcaseListName, index) { //remove old selected $("#" + this.selectedList + " > div.selected").removeClass("selected"); this.selectedList = showcaseListName; this.selectedItem = index; $("#" + this[showcaseListName][index].id).addClass("selected"); } function getItem(showcaseList, id, updateSelected) { for (var i = 0; i < this[showcaseList].length; i++) { if(this[showcaseList][i].id == id) { if(updateSelected) this.updateSelected(showcaseList, i) return this[showcaseList][i]; } } return null; } function initShowcaseList(showcaseList, selectedList) { var object = this; object[showcaseList] = new Array(); function addMedia() { switch(showcaseList) { case "videoList": var type = $("#" + this.id + " > .type").find("p").html(); var parsedType = object.types[type]; var caption = $("#" + this.id + " > .caption"); var captionObj = {title: caption.find("h3").html(), description:caption.find("p").html()}; object[showcaseList].push({index: object[showcaseList].length, id: this.id, url: "/docs/IO/" + this.id + "/movie." + parsedType,caption: captionObj, previewImage:caption.find("img").attr("src"),title:caption.find('h3').html()}); $("#" + this.id + " > .thumbnail").mouseover(function(){object.showCaption(showcaseList,this.parentNode.id, true);}); $("#" + this.id).mouseout(function(){object.showCaption(showcaseList,this.id, false);}); $("#" + this.id + " > .thumbnail").click(function(){object.playMedia(showcaseList, this.parentNode.id);}); object.centerTn($("#" + this.id + " > .thumbnail > img:first").get(0)); break; case "audioList": var type = $('#' + this.id + " > .type").find("p").html(); var parsedType = object.types[type]; var caption = $("#" + this.id + " > .caption"); var captionObj = {title: caption.find("h3").html(), description:caption.find("p").html()}; object[showcaseList].push({index: object[showcaseList].length, id: this.id, url: "/docs/IO/" + this.id + "/audio." + parsedType,caption: captionObj, previewImage:$('#' + this.id + ' > .thumbnail > img:first').attr('src'),title:caption.find('h3 >span').html()}); //$("#" + this.id + " > .thumbnail").mouseover(function(){object.showCaption(showcaseList,this.parentNode.id, true);}); //$("#" + this.id).mouseout(function(){object.showCaption(showcaseList,this.id, false);}); var containerId = this.id; $("#" + this.id + " h3").click(function(){object.playMedia(showcaseList, containerId);}); break; case "photoList": var item = $("#" + this.id + " > .thumbnail > img:first"); object[showcaseList].push({index: object[showcaseList.length], id: this.id, url: item.attr("src"), attr: item.attr("alt")}); $("#" + this.id + " > .thumbnail").click(function(){object.playMedia(showcaseList, this.parentNode.id);}); object.centerTn($("#" + this.id + " > .thumbnail > img:first").get(0)); break; } } $("#" + showcaseList + " > div.showcaseTN").each(addMedia); if (object[showcaseList].length == 0) { return false; } //$("#" + showcaseList + " > .thumbnail > img:first").each(function(){object.centerTn(this)}); if(selectedList) { this.selectedList = showcaseList; this.updateSelected(this.selectedList, 0); } else { this.previousList = showcaseList; // $("#" + showcaseList).hide(); } switch(showcaseList) { case "videoList": $("#videoCaption > .arrow").hover(function(){$("#videoCaption").show();},function(){$("#videoCaption").hide();}); break; case 'audioList': $('#audioList .caption').hover(function(){$(this).find('p').show();}, function(){$(this).find('p').hide()}); break; } this.showcaseLists.push(showcaseList); return true; } function initMediaPlayer(mediaPlayerURL) { this.mediaPlayerURL = mediaPlayerURL; var so = new SWFObject(mediaPlayerURL,'mpl',this.contentWidth, this.contentHeight,'9.0.115'); so.addParam('allowscriptaccess','always'); so.addParam('allowfullscreen','true'); // so.addParam('wmode','transparent'); so.useExpressInstall("/media/expressinstall.swf"); so.addVariable('enablejs','true'); so.addVariable('height',this.contentHeight); so.addVariable('width',this.contentWidth); so.addVariable('showdigits','false'); so.addVariable('showvolume','false'); so.addVariable('displayheight', this.contentHeight); so.addVariable('image', this[this.selectedList][this.selectedItem].previewImage); so.addVariable('file', this[this.selectedList][this.selectedItem].url); so.write('avPlayer'); if(navigator.appName.indexOf("Microsoft") != -1) this.mediaPlayer = window["mpl"]; else this.mediaPlayer = document["mpl"]; this.updateNowPlaying(this[this.selectedList][this.selectedItem].title); } function playMedia(showcaseList, id) { var media = this.getItem(showcaseList, id, true); var object = this; switch(showcaseList) { case "videoList": this.mediaPlayer.loadFile({file:media.url,image:media.previewImage}); this.updateNowPlaying(media.title); break; case "audioList": if (media.previewImage == null) { media.previewImage = this.defaultTn.audio; } this.mediaPlayer.loadFile({file:media.url,image:media.previewImage}); this.updateNowPlaying(media.title); break; case "photoList": var img = new Image(); var x,y; img.src = media.url; /* needs to be fixed if(img.width - this.contentWidth >= 0) x = -(img.width - this.contentWidth)/2; else x= (this.contentWidth - img.width)/2; if(img.height - this.contentHeight >= 0 ) y = -(img.height - this.contentHeight)/2; else y = (this.contentHeight - img.height)/2; */ $("#photoPlayer").html(""); $("#photoPlayer > img:first").css({left: x, top: y}); $("#photoPlayer > img:first").show(); if(media.attr == null) $("#photoCaption").html(""); else $("#photoCaption").html(media.attr); break; } } function centerTn(img) { var imgobj= $(img); var tnHeight = this.tnDefinedHeight; var tnWidth = img.width/(img.height/tnHeight); if(tnWidth - this.tnWidth >= 0 ) imgobj.css("left", -(tnWidth - this.tnWidth)/2); else imgobj.css("left", (this.tnWidth - tnWidth)/2); if(tnHeight - this.tnHeight >= 0 ) imgobj.css("top", -(tnHeight - this.tnHeight)/2); else imgobj.css("top", (this.tnHeight - tnHeight)/2); } //$(document).ready(function(){ function run(){ var showcase = new Showcase({contentWidth: 480, contentHeight: 360}, {tnWidth:28, tnHeight:28}); var selected = true; var playable = false; if ($('#videoList').length != 0) { if (showcase.initShowcaseList("videoList", selected)) { playable = true; } selected = false } if ($('#audioList').length != 0) { if (showcase.initShowcaseList("audioList", selected)) { playable = true; } } //showcase.initShowcaseList("photoList", false); if (playable) { showcase.initMediaPlayer('/media/mediaplayer.swf'); } showcase.initButtons("avButton"); };