var Category = new Class({ initialize: function( obj ) { this.id = obj.id; this.name = obj.name; if ( obj.videos != null ) { this.videos = obj.videos; this.videocount = obj.videos.length; } else { this.videos = []; this.videocount = 0; } this.subcategories = $H(obj.subcategories); this.subcategories.each(function (subCat) { if ( subCat.videos ) { this.subcategories[subCat.id].videocount = subCat.videos.length; } }, this); this.wrap = $('section_'+this.id); this.headerWrap = $('header_'+this.id); this.leftButton = $('leftButton_'+this.id); this.rightButton = $('rightButton_'+this.id); this.contentWrap = $('content_'+this.id); this.sliderWrap = $('slider_'+this.id); this.leftButton.addEvent( 'click', function () { this.slide('left'); }.bind(this) ) this.rightButton.addEvent( 'click', function () { this.slide('right'); }.bind(this) ) this.itemWidth = 234; this.slideLength = 932; this.slideStepLength = 150; this.selectedSubcat; this.update(); }, toggleContent : function () { this.contentWrap.toggleClass('contentCollapsed'); this.headerWrap.toggleClass('headerCollapsed'); }, collapseContent : function () { this.contentWrap.addClass('contentCollapsed'); this.headerWrap.addClass('headerCollapsed'); }, update : function ( subCat ) { this.updateHeader(subCat); this.updateContent(subCat); this.selectedSubcat = subCat; }, updateHeader : function ( subCat ) { this.headerWrap.set('html', ''); if ( subCat ) { this.headerWrap.adopt( new Element('p', { 'class' : 'title' }).adopt([ new Element('a', { 'html' : this.name+' > ', 'events' : { 'click' : function () { this.update(); }.bind(this) } }), new Element('b', { 'class' : 'subcat activeSubcat', 'html' : this.subcategories[subCat].name }) ])); } else { this.headerWrap.adopt( new Element('p', { 'class' : 'title', 'html' : this.name, 'events' : { 'click' : function () { this.toggleContent(); }.bind(this) } }) ); } this.subcategories.each(function ( s, k ) { if ( s.id != subCat ) { this.headerWrap.adopt( new Element('p', { 'class' : 'subcat' }).adopt( new Element('a', { 'html' : s.name, 'events' : { 'click' : function () { this.update(s.id); }.bind(this) } }) )); } },this); if ( this.headerWrap.hasClass('headerCollapsed') ) { this.toggleContent(); } }, updateContent : function ( subCat ) { this.sliderWrap.set('html', ''); if ( subCat ) { var v = this.subcategories[subCat].videos; var videocount = this.subcategories[subCat].videocount; } else { var v = this.videos; var videocount = this.videocount; } this.sliderWrap.setStyle('width', (this.itemWidth*videocount)+'px'); if ( videocount > 4 ) { this.enableButton('right'); } else { this.disableButton('right'); } this.maxRight = -this.itemWidth*(videocount-4); v.each(function (id) { this.sliderWrap.adopt( videos[id].getSliderItem(this.id) ); }, this); this.sliderWrap.setStyle('left', '0px'); this.pos = 0; this.disableButton('left'); }, slide : function ( dir ) { if ( this.interval == undefined ) { if ( !this.pos ) { this.pos = 0; } this.start = this.pos; this.stop = (dir == 'left')? this.start+this.slideLength : this.start-this.slideLength; if ( dir == 'right' && this.stop < this.maxRight ) { this.stop = this.maxRight; } else if ( dir == 'left' && this.stop > 0 ) { this.stop = 0; } if ( isNaN(parseInt(this.id)) ) { this.interval = window.setInterval('categories.'+this.id+'.intervalFunc(\''+dir+'\')',1); } else { this.interval = window.setInterval('categories['+this.id+'].intervalFunc(\''+dir+'\')',1); } } }, slideTo : function ( videoId, tween ) { var position = false; if ( this.videos.contains(videoId) ) { position = indexOf(videoId); if ( this.videocount-position < 2 ) { position = this.videocount-3; } } else { this.subcategories.each(function ( subCat ) { if ( subCat.videos.contains(videoId) ) { position = indexOf(videoId); if (subCat.videocount-position < 2) { position = subCat.videocount-3; } } }); } if (tween && this.interval == undefined && position) { if ( !this.pos ) { this.pos = 0; } this.start = this.pos; this.stop = (position)*(-this.itemWidth); var dir = (this.start < this.stop)? 'left' : 'right'; if ( isNaN(parseInt(this.id)) ) { this.interval = window.setInterval('categories.'+this.id+'.intervalFunc(\''+dir+'\')',1); } else { this.interval = window.setInterval('categories['+this.id+'].intervalFunc(\''+dir+'\')',1); } } else if ( position ) { this.stop = -this.itemWidth*position; this.sliderWrap.setStyle('left', this.stop+'px'); this.pos = this.stop; this.updateButtons(); } }, checkPosition : function () { if ( this.pos > -this.slideStepLength || this.pos < this.maxRight+this.slideStepLength ) { return 'end'; } var diff = Math.abs(Math.abs(this.pos) - Math.abs(this.stop)); if ( diff < this.slideStepLength ) { return 'stop'; } return 'continue'; }, intervalFunc : function ( dir ) { this.pos = (dir == 'left')? this.pos+this.slideStepLength : this.pos-this.slideStepLength; this.sliderWrap.setStyle('left', this.pos+'px'); var status = this.checkPosition(); if ( status != 'continue' ) { this.pos = this.stop; this.interval = window.clearInterval(this.interval); this.sliderWrap.setStyle('left', this.stop+'px'); this.updateButtons(status); } }, updateButtons : function ( status ) { if ( !status ) { var status = this.checkPosition(); } if ( status == 'end' ) { if (this.pos == 0) { this.disableButton('left'); this.enableButton('right'); } else { this.disableButton('right'); this.enableButton('left'); } } else { this.enableButton('both'); } }, disableButton : function ( position ) { if (position == 'left' || position == 'both') { this.leftButton.removeClass('left'); this.leftButton.addClass('leftDisabled'); this.leftButton.setProperty('disabled', 'true'); } if (position == 'right' || position == 'both') { this.rightButton.removeClass('right'); this.rightButton.addClass('rightDisabled'); this.rightButton.setProperty('disabled', 'true'); } }, enableButton : function ( position ) { if (position == 'left' || position == 'both') { this.leftButton.removeClass('leftDisabled'); this.leftButton.addClass('left'); this.leftButton.removeProperty('disabled'); } if (position == 'right' || position == 'both') { this.rightButton.removeClass('rightDisabled'); this.rightButton.addClass('right'); this.rightButton.removeProperty('disabled'); } }, addVideo : function ( video, subCat ) { if (subCat) { this.subcategories[subCat].videos.push(video.id); this.subcategories[subCat].videocount++; this.updateContent(subCat); } else { this.videos.push(video.id); this.videocount++; this.updateContent(); } } }); var Player = new Class({ initialize: function() { this.categoryId; this.subcategoryId; this.playingId; this.status = 'closed'; this.selectedTab = 'info'; this.menuItems; this.content; }, getElements : function () { this.wrap = $('playerWrap'); this.tabWrap = $('tabWrap'); this.tabMenu = $('tabMenu'); this.menuItems = $H({ 'info' : $('tabMenuItemInfo'), 'comments' : $('tabMenuItemComments'), 'gmap' : $('tabMenuItemMap'), 'playlist' : $('tabMenuItemPlaylist'), 'close' : $('tabMenuItemClose') }); this.infoWrap = $('tabInfo'); this.infoElements = $H({ 'title' : $('tabInfoTitle'), 'duration' : $('tabInfoDuration'), 'description' : $('tabInfoDescription'), 'articleLink' : $('tabInfoArticleLink'), 'rating' : $('tabInfoRating'), 'share' : $('tabInfoShare'), 'facebook' : $('tabInfoShareFacebook'), 'kudos' : $('tabInfoShareKudos'), 'delicious' : $('tabInfoShareDelicious'), 'twitter' : $('tabInfoShareTwitter'), 'linkedin' : $('tabInfoShareLinkedin'), 'myspace' : $('tabInfoShareMyspace'), 'link' : $('tabInfoPermaLink') }); this.commentsWrap = $('tabComments'); this.mapWrap = $('tabMap'); this.playlistWrap = $('tabPlaylist'); }, update : function ( selected ) { if ( !selected ) { var selected = this.selectedTab; } else { this.selectedTab = selected; } this.updateMenu(); this.updateContent(); }, updateMenu : function () { if ( this.playingId && videos[this.playingId] ) { var v = videos[this.playingId]; this.menuItems.each(function ( e, eId ) { if ( this.selectedTab == eId ) { e.addClass('active'); e.removeEvents('click'); } else { e.removeClass('active'); e.addEvent('click', function () { this.update(eId); }.bind(this)); } }, this); if ( v.articleUrl ) { this.menuItems['comments'].setStyle('display', 'block'); } else { this.menuItems['comments'].setStyle('display', 'none'); } if (v.lat && v.lng) { this.menuItems['gmap'].setStyle('display', 'block'); } else { this.menuItems['gmap'].setStyle('display', 'none'); } } }, updateContent : function () { if ( this.playingId && videos[this.playingId] ) { var v = videos[this.playingId]; if ( this.selectedTab == 'info') { this.infoWrap.setStyle('display', 'block'); this.commentsWrap.setStyle('display', 'none'); this.mapWrap.setStyle('display', 'none'); this.playlistWrap.setStyle('display', 'none'); this.infoElements.each(function (ie) { ie.removeEvents('click'); }); this.infoElements.title.set('html', v.title); this.infoElements.duration.set('html', v.duration); this.infoElements.description.set('html', v.description); if ( v.articleUrl ) { this.infoElements.articleLink.setStyle('display', 'block'); this.infoElements.articleLink.setProperty('href', v.articleUrl); } else { this.infoElements.articleLink.setStyle('display', 'none'); } this.infoElements.rating.set('html', v.rating+' anbefalinger '); if ( v.rated ) { this.infoElements.rating.adopt( new Element('span', { 'class' : 'rated', 'html' : 'Din anbefaling er registrert' } ) ); } else { this.infoElements.rating.adopt( new Element('a', { 'html' : 'Gi en anbefaling' } ).addEvent('click', function () { rateVideo(this.id); }.bind(v) ) ); } this.infoElements.share.addEvent( 'click', function () { this.toggleShare(); }.bind(this) ); this.infoElements.facebook.addEvent( 'click', function () { shareVideo('facebook', this.id); }.bind(v) ); this.infoElements.kudos.addEvent('click', function () { shareVideo('kudos', this.id); }.bind(v) ); this.infoElements.delicious.addEvent('click', function () { shareVideo('delicious', this.id); }.bind(v) ); this.infoElements.twitter.addEvent('click', function () { shareVideo('twitter', this.id); }.bind(v) ); this.infoElements.linkedin.addEvent('click', function () { shareVideo('linkedIn', this.id); }.bind(v) ); this.infoElements.myspace.addEvent('click', function () { shareVideo('myspace', this.id); }.bind(v) ); this.infoElements.link.set('html', archiveUrl+'&id='+v.id); } else if ( this.selectedTab == 'comments' ) { this.infoWrap.setStyle('display', 'none'); this.commentsWrap.setStyle('display', 'block'); this.mapWrap.setStyle('display', 'none'); this.playlistWrap.setStyle('display', 'none'); this.commentsWrap.html = ''; var aid = v.articleUrl.replace('http:/\/'+httpUrl+'.no/article', ''); aid = aid.replace('http:/\/www.'+httpUrl+'.no/article', ''); /*var end = aid.indexOf("/", 1); end = aid.indexOf("/", end+1); end = aid.indexOf("/", end+1); aid = aid.substring(0, end);*/ var commentsWrap = this.commentsWrap; var foo = new Request({ url : '/templates/scripts/video/ajaxProxy.php?action=comments&id='+aid, onComplete : function( r ){ commentsWrap.set('html',r); } }); foo.send(); } else if ( this.selectedTab == 'gmap' ) { this.infoWrap.setStyle('display', 'none'); this.commentsWrap.setStyle('display', 'none'); this.mapWrap.setStyle('display', 'block'); this.playlistWrap.setStyle('display', 'none'); this.mapWrap.html = ''; if ( GBrowserIsCompatible() ) { if ( v.lat && v.lng ) { map = new GMap2(this.mapWrap); var mapZoom = 9; var mapType = G_NORMAL_MAP; var baseIcon = new GIcon(); baseIcon.image = 'http://dev.eddainteraktiv.no/video/gui/graphics/icon_map_marker.png'; baseIcon.iconSize = new GSize(33, 33); baseIcon.iconAnchor = new GPoint(15, 15); var icon = new GIcon(baseIcon); var point = new GLatLng(v.lat, v.lng); var marker = new GMarker(point, icon); map.setCenter(point, mapZoom, mapType); map.addControl(new GSmallMapControl()); map.addOverlay(marker); } } } else if ( this.selectedTab == 'playlist' ) { this.infoWrap.setStyle('display', 'none'); this.commentsWrap.setStyle('display', 'none'); this.mapWrap.setStyle('display', 'none'); this.playlistWrap.setStyle('display', 'block'); this.playlistWrap.set('html', ''); this.playlistWrap.adopt(Playlist.getHtml()); } } }, updateRating : function ( id, rating ) { if (this.playingId == id) { this.infoElements.rating.set('html', videos[id].rating+' anbefalinger '); if ( videos[id].rated ) { this.infoElements.rating.adopt( new Element('span', { 'class' : 'rated', 'html' : 'Din anbefaling er registrert' } ) ); } else { this.infoElements.rating.adopt( new Element('a', { 'html' : 'Gi an anbefaling' } ).addEvent('click', function () { rateVideo(id); } ) ); } } }, play : function ( videoId, categoryId ) { this.stop(); if (this.categoryId && this.categoryId != categoryId) { this.setClose(); } if ( categoryId ) { this.categoryId = categoryId; } else { this.categoryId = videos[videoId].categoryId; if ( !categories[this.categoryId] ) { var found = false; categories.each(function (cat) { if (cat.subcategories[this.categoryId]) { this.categoryId = cat.id; found = true; } }); if ( !found ) { this.categoryId = defaultCategory; } } } if ( this.categoryId ) { this.movePlayer(); this.playingId = videoId; this.open(); } else { alert('Kan ikke spille av video! Feil i kategorisering'); } }, playList : function ( list, categoryId ) { /*if ( categoryId && this.categoryId != categoryId ) { if ( this.categoryId ) { this.setClose(); } } if ( this.status == 'closed' ) { if ( categoryId ) { this.categoryId = categoryId; } else { this.categoryId = videos[list[0]].categoryId; } this.movePlayer(); this.open(); } this.scrollTo(false); this.wrap.setStyles({display : 'block',height : 'auto'}); this.status = 'open';*/ this.stop(); this.playingId = list[0]; NettTv.API.play(list); }, stop : function () { if ( this.playingId ) { videos[this.playingId].setNotPlaying(); NettTv.API.stop(); this.playingId = null; } }, movePlayer : function () { if ( this.categoryId == 'search' ) { this.wrap = $('playerWrap_'+this.categoryId); this.tabWrap.inject( $('playerWrap_'+this.categoryId), 'bottom' ); } else { this.wrap = $('playerWrap_'+this.categoryId); this.tabWrap.inject( $('playerWrap_'+this.categoryId), 'bottom' ); } }, open : function ( play ) { scrollToElement(this.wrap, -39); if ( this.status == 'closed' ) { this.tweenPos = 0; this.tweenEnd = 400; this.wrap.setStyle('display', 'block'); if ( this.categoryId == 'search' ) { SearchResult.contentWrap.addClass('play'); } else if ( this.categoryId == 'playlist' ) { Playlist.contentWrap.addClass('play'); } else { categories[this.categoryId].contentWrap.addClass('play'); } this.interval = window.setInterval('Player.intervalFunc(\'open\')', 1); this.status = 'open'; } else { this.setOpen(); } }, close : function () { if (this.status == 'open') { this.tweenPos = 400; this.tweenEnd = 0; this.interval = window.setInterval('Player.intervalFunc(\'close\')', 1); } }, setOpen : function (_this) { if (!_this) { _this = this; } scrollToElement(_this.wrap, -39); _this.wrap.setStyles({display : 'block', height : 'auto'}); _this.status = 'open'; NettTv.API.play(_this.playingId, 'player_'+this.categoryId, 'portal'); }, setClose : function (_this) { NettTv.API.stop(); if (!_this) { _this = this; } _this.wrap.setStyles({display : 'none', height : '0px'}); if ( _this.categoryId == 'search' ) { SearchResult.contentWrap.removeClass('play'); } else { categories[_this.categoryId].contentWrap.removeClass('play'); } if (_this.playingId) { videos[_this.playingId].setNotPlaying(); _this.playingId = false; } _this.categoryId = null; _this.status = 'closed'; }, toggleShare : function () { this.infoElements.share.toggleClass('expanded'); }, intervalFunc : function ( action ) { this.tweenPos = ( action == 'open' )? this.tweenPos+40 : this.tweenPos-40; var diff = Math.abs(this.tweenPos-this.tweenEnd); if ( diff > 60 && this.tweenPos <= 400 ) { this.wrap.setStyle('height', this.tweenPos+'px'); } else { this.interval = window.clearInterval(this.interval); if ( action == 'open' ) { this.setOpen(this); } else { this.setClose(this); } } } }); var SearchResult = new Class({ initialize: function(videos, text) { this.id = 'search'; this.currentPage = 1; }, setElements : function () { if (!this.wrap) { this.wrap = $('section_search'); this.headerWrap = $('header_search'); this.contentWrap = $('content_search'); this.containerWrap = $('container_search'); this.topWrap = $('searchListTop'); this.listWrap = $('searchList'); this.bottomWrap = $('searchListBottom'); } }, toggleContent : function () { this.contentWrap.toggleClass('collapsed'); this.headerWrap.toggleClass('collapsed'); }, update : function ( videos, text ) { this.videos = videos; this.videocount = videos.length; this.text = text; this.setElements(); this.updateTop(); this.updateList(); this.updateBottom(); this.wrap.setStyle('display', 'block'); }, updateTop : function () { this.topWrap.set('html', '
Ditt søk på "'+this.text+'" ga '+this.videocount+' treff
'); }, updateList : function () { this.listWrap.set('html', ''); var i = 0; this.videos.each(function (id) { if (i < 10*this.currentPage && i >= (this.currentPage*10)-10) { var item = videos[id].getSearchResultItem(this.id); if ( i%5 == 0 ) { item.setStyle('clear', 'left'); } this.listWrap.adopt(item); } i++; }, this); scrollTo(this.wrap, -39); }, updateBottom : function () { this.bottomWrap.set('html', ''); if (this.videocount > 10) { var pageCount = Math.ceil(this.videocount/10); if (this.currentPage == 1) { this.bottomWrap.adopt(this.buttonPrev = new Element('b', { 'class' : 'previous', 'html' : 'Forrige' })); } else { this.bottomWrap.adopt(this.buttonPrev = new Element('a', { 'class' : 'previous', 'html' : 'Forrige', 'events' : { 'click' : function () { this.previousPage(); }.bind(this) } })); } this.bottomWrap.adopt(pageLinks = new Element('div', { 'class' : 'pageLinks' })); for (var i=1; i<=pageCount; i++) { if (i == this.currentPage) { pageLinks.adopt(new Element('b', { 'class' : 'page', 'html' : i })); } else { pageLinks.adopt(new Element('a', { 'class' : 'page', 'html' : i, 'events' : { 'click' : function (e) { var nr = e.target.get('html'); this.nextPage(nr); }.bind(this)} })); } } if (this.currentPage == pageCount) { this.bottomWrap.adopt(this.buttonNext = new Element('b', { 'class' : 'next', 'html' : 'Neste' })); } else { this.bottomWrap.adopt(this.buttonNext = new Element('a', { 'class' : 'next', 'html' : 'Neste', 'events' : { 'click' : function () { this.nextPage(); }.bind(this) } })); } } }, previousPage : function () { this.currentPage--; this.updateList(); this.updateBottom(); }, nextPage : function (nr) { if (nr) { this.currentPage = parseInt(nr); } else { this.currentPage++; } this.updateList(); this.updateBottom(); }, setView : function ( type ) { if ( type == 'grid' ) { this.containerWrap.addClass('grid') } else { this.containerWrap.removeClass('grid') } this.videos.each(function (id) { videos[id].searchResultItem.toggleClass('clearfix'); }); } }); var Video = new Class({ initialize: function( obj ) { this.id = obj.id; this.categoryId = obj.categoryId; this.title = obj.title; this.description = obj.description; if (obj.images) { this.sliderImage = obj.images[6].url; this.searchImage = obj.images[6].url; this.playlistImage = obj.images[6].url; } this.images = obj.images; this.duration = obj.duration;//( obj.duration == 0 )? '? min' : Math.round((obj.duration)/0.6)/100 +' min'; this.articleUrl = obj.articleUrl; this.rating = ( obj.rating == undefined )? 0 : obj.rating; this.lat = ( obj.mapkey )? parseFloat( obj.mapkey.substr(0, obj.mapkey.indexOf(',')) ) : false; this.lng = ( obj.mapkey )? parseFloat( obj.mapkey.substr(obj.mapkey.indexOf(',')+1, obj.mapkey.length) ) : false; this.link = archiveUrl+'?id='+this.id; this.rated; this.formatDuration(); this.setHtmlElements(); }, formatDuration : function () { if ( !this.duration || this.duration == 0 ) { this.duration = '? min'; } else { var min = Math.floor(this.duration/60); var sec = this.duration - (min*60); if ( sec < 10 ) { sec = '0'+sec; } this.duration = min+':'+sec+' min'; } }, setHtmlElements : function () { this.tabMap = new Element('div', { 'class' : 'map' } ); this.tabInfo = new Element('div', { 'class' : 'info' }); this.tabComments = new Element('div', { 'class' : 'comments' }); this.sliderItems = $H({}); /*this.playlistItem = new Element('div', { 'class' : 'playlistItem clearfix'}).adopt([ new Element('a', { 'events' : { 'click' : function () { Playlist.play(this.id) }.bind(this) } }).adopt([ new Element('div', { 'class' : 'playlistImage' }).adopt(new Element('img', { 'src' : this.playlistImage })), new Element('div', { 'class' : 'text' }).adopt([ new Element('p', { 'class' : 'title', 'html' : this.title }), new Element('p', { 'class' : 'duration', 'html' : this.duration }) ]) ]), new Element('div', { 'class' : 'moveItem' }).adopt([ new Element('div', { 'class' : 'moveItemUp', 'events' : { 'click' : function () { Playlist.moveUp(this.id); }.bind(this) } }), new Element('div', { 'class' : 'moveItemDown', 'events' : { 'click' : function () { Playlist.moveDown(this.id); }.bind(this) } }) ]), new Element('div', { 'class' : 'removeItem', 'html' : ' ', 'events' : { 'click' : function () { Playlist.remove(this.id); }.bind(this) } }) ]);*/ this.searchResultItem = new Element('div', { 'class' : 'item clearfix' } ).adopt([ new Element('a', { 'events' : { 'click' : function () { Player.play(this.id, 'search'); }.bind(this) } }).adopt( new Element('img', { 'class' : 'image', 'src' : this.searchImage }) ), new Element('div', { 'class' : 'text' }).adopt([ new Element('a', { 'class' : 'title', 'html' : this.title, 'events' : { 'click' : function () { Player.play(this.id, 'search'); }.bind(this) } }), new Element('ul', { 'class' : 'icons' }).adopt([ this.searchResultRating = new Element('li', { 'class' : 'rating', 'html' : this.rating }), new Element('li', { 'class' : 'duration', 'html' : this.duration }) ]) ]) ]); new Element('a', { 'events' : { 'click' : function () { Player.play(this.id, 'search'); }.bind(this) } }).adopt([ new Element('img', { 'class' : 'image', 'src' : this.searchImage }), new Element('div', { 'class' : 'text' }).adopt([ new Element('p', { 'class' : 'title', 'html' : this.title }), new Element('ul', { 'class' : 'icons' }).adopt([ this.searchResultRating = new Element('li', { 'class' : 'rating', 'html' : this.rating }), new Element('li', { 'class' : 'duration', 'html' : this.duration }) ]) ]) ]) }, updateRating : function ( r ) { if ( !this.rated ) { this.rated = true; this.rating = r; Player.updateRating(this.id, r); this.sliderItems.each(function ( si ) { si.ratingElement.set('html', ''+this.rating+''); }, this); } }, drawMap : function () { if ( GBrowserIsCompatible() ) { if ( this.lat && this.lng ) { map = new GMap2(this.tabMap); var mapZoom = 9; var mapType = G_NORMAL_MAP; var baseIcon = new GIcon(); baseIcon.image = 'http://dev.eddainteraktiv.no/video/gui/graphics/icon_map_marker.png'; baseIcon.iconSize = new GSize(33, 33); baseIcon.iconAnchor = new GPoint(15, 15); var icon = new GIcon(baseIcon); var point = new GLatLng(this.lat, this.lng); var marker = new GMarker(point, icon); map.setCenter(point, mapZoom, mapType); map.addControl(new GSmallMapControl()); map.addOverlay(marker); } } }, getSliderItem : function ( categoryId ) { //if ( !this.sliderItems[categoryId] ) { var plb; var rel; this.sliderItems[categoryId] = new Element('div', { 'class' : 'sliderItem' } ).adopt([ new Element('a', { 'events' : { 'click' : function () { Player.play(this.id, categoryId); }.bind(this) } }).adopt([ new Element('div', { 'class' : 'image' }).adopt( new Element('img', { 'src' : this.sliderImage }) ), new Element('p', { 'class' : 'title', 'html' : this.title }) ]), new Element('ul', { 'class' : 'icons' }).adopt([ rel = new Element('li', { 'class' : 'rating', 'html' : ''+this.rating+'' }), new Element('li', { 'class' : 'duration', 'html' : this.duration }), plb = new Element('li', { 'class' : 'playlist', 'title' : 'Legg i spilleliste', 'events' : { 'click' : function () { Playlist.add(this.id); }.bind(this) } }) ]) ]); this.sliderItems[categoryId].playlistButton = plb; this.sliderItems[categoryId].ratingElement = rel; //} return this.sliderItems[categoryId]; }, getPlaylistItem : function ( itemClass ) { //this.playlistItem.addClass(itemClass); if (itemClass == 'dark') { //this.playlistItem.removeClass('light'); } else { //this.playlistItem.removeClass('dark'); } this.playlistItem = new Element('div', { 'class' : 'playlistItem clearfix '+itemClass}).adopt([ new Element('a', { 'events' : { 'click' : function () { Playlist.play(this.id) }.bind(this) } }).adopt([ new Element('div', { 'class' : 'playlistImage' }).adopt(new Element('img', { 'src' : this.playlistImage })), new Element('div', { 'class' : 'text' }).adopt([ new Element('p', { 'class' : 'title', 'html' : this.title }), new Element('p', { 'class' : 'duration', 'html' : this.duration }) ]) ]), new Element('div', { 'class' : 'moveItem' }).adopt([ new Element('div', { 'class' : 'moveItemUp', 'events' : { 'click' : function () { Playlist.moveUp(this.id); }.bind(this) } }), new Element('div', { 'class' : 'moveItemDown', 'events' : { 'click' : function () { Playlist.moveDown(this.id); }.bind(this) } }) ]), new Element('div', { 'class' : 'removeItem', 'html' : ' ', 'events' : { 'click' : function () { Playlist.remove(this.id); }.bind(this) } }) ]); return this.playlistItem; }, getSearchResultItem : function () { this.searchResultItem = new Element('div', { 'class' : 'item clearfix' } ).adopt([ new Element('a', { 'events' : { 'click' : function () { Player.play(this.id, 'search'); }.bind(this) } }).adopt( new Element('img', { 'class' : 'image', 'src' : this.searchImage }) ), new Element('div', { 'class' : 'text' }).adopt([ new Element('a', { 'class' : 'title', 'html' : this.title, 'events' : { 'click' : function () { Player.play(this.id, 'search'); }.bind(this) } }), new Element('ul', { 'class' : 'icons' }).adopt([ this.searchResultRating = new Element('li', { 'class' : 'rating', 'html' : this.rating }), new Element('li', { 'class' : 'duration', 'html' : this.duration }) ]) ]) ]); return this.searchResultItem; }, setPlaying : function () { this.sliderItems.each(function (si) { si.addClass('playing'); }); if ( this.searchResultItem ) { this.searchResultItem.addClass('playing'); } if ( this.playlistItem ) { this.playlistItem.addClass('playing'); } }, setNotPlaying : function () { this.sliderItems.each(function (si) { si.removeClass('playing'); }); if ( this.searchResultItem ) { this.searchResultItem.removeClass('playing'); } if ( this.playlistItem ) { this.playlistItem.removeClass('playing'); } }, setInPlaylist : function () { this.sliderItems.each(function ( si ) { si.playlistButton.addClass('added'); si.playlistButton.removeEvents('click'); si.playlistButton.set('title', 'Ligger i spilleliste'); }); }, setNotInPlaylist : function () { this.sliderItems.each(function ( si ) { si.playlistButton.removeClass('added'); si.playlistButton.addEvent('click', function () { Playlist.add(this.id); }.bind(this)); si.playlistButton.set('title', 'Legg i spilleliste'); }, this); } }); var Playlist = new Class({ initialize: function() { this.videos = {}; this.list = [] this.playingId; }, update : function () { if (Player.selectedTab == 'playlist') { Player.update('playlist'); } }, add : function ( id ) { this.list.push(id); videos[id].setInPlaylist(); this.update(); }, addList : function ( list ) { list.each(function ( id ) { this.list.push(id); }, this); }, remove : function ( id ) { var position = this.list.indexOf(id); if (position > -1) { videos[id].setNotInPlaylist(); this.list.remove(id); } this.update(); }, moveUp : function ( id ) { var position = this.list.indexOf(id); if (position > 0) { var a = this.list[position-1]; var b = id; this.list[position-1] = b; this.list[position] = a; this.update(); } }, moveDown : function ( id ) { var position = this.list.indexOf(id); if (position < this.list.length-1) { var a = this.list[position+1]; var b = id; this.list[position+1] = b; this.list[position] = a; this.update(); } }, play : function ( id ) { if ( id ) { Player.play( id ); } else if ( this.list.length > 0 ) { Player.playList( this.list ); } this.update(); }, getHtml : function () { if (this.list.length < 1) { var html = new Element('div', { 'class' : 'playlist' } ).adopt( new Element('p', { 'class' : 'empty', 'html' : 'Ingen videoer i spillelisten' } ) ); } else { var html = new Element('div', { 'class' : 'playlist' } ).adopt( new Element('div', { 'class' : 'playlistTop' } ).adopt([ new Element('p', { 'class' : 'playMyList', 'html' : 'Din spilleliste Spill av' })//, //new Element('p', { 'class' : 'shareMyList', 'html' : 'Del spillelisten min' }) ]) ); this.list.each(function (id) { var position = this.list.indexOf(id); var itemClass = 'light'; if (Player.playingId == id) { itemClass = 'playing'; } else if (position%2 == 0) { itemClass = 'dark'; } html.adopt(videos[id].getPlaylistItem(itemClass)); }, this); } return html; }, clear : function () { this.list = []; this.update(); } }); var Lesernes = new Class({ initialize: function(obj) { this.id = obj.id; this.videocount = obj.videocount; this.wrap = $('section_'+this.id); this.headerWrap = $('header_'+this.id); this.leftButton = $('leftButton_'+this.id); this.rightButton = $('rightButton_'+this.id); this.contentWrap = $('content_'+this.id); this.sliderWrap = $('slider_'+this.id); if ( this.videocount <= 4 ) { this.disableButton('right'); } else { this.leftButton.addEvent( 'click', function () { this.slide('left'); }.bind(this) ) this.rightButton.addEvent( 'click', function () { this.slide('right'); }.bind(this) ) } $('title_'+this.id).addEvent( 'click', function() { this.toggleContent(); }.bind(this) ); this.itemWidth = 234; this.slideLength = 932; this.slideStepLength = 150; this.maxRight = -this.itemWidth*(this.videocount-4); }, toggleContent : function () { this.contentWrap.toggleClass('contentCollapsed'); this.headerWrap.toggleClass('headerCollapsed'); }, collapseContent : function () { this.contentWrap.addClass('contentCollapsed'); this.headerWrap.addClass('headerCollapsed'); }, slide : function ( dir ) { if ( this.interval == undefined ) { if ( !this.pos ) { this.pos = 0; } this.start = this.pos; this.stop = (dir == 'left')? this.start+this.slideLength : this.start-this.slideLength; if ( dir == 'right' && this.stop < this.maxRight ) { this.stop = this.maxRight; } else if ( dir == 'left' && this.stop > 0 ) { this.stop = 0; } this.interval = window.setInterval('lesernes.'+this.id+'.intervalFunc(\''+dir+'\')',1); } }, checkPosition : function () { if ( this.pos > -this.slideStepLength || this.pos < this.maxRight+this.slideStepLength ) { return 'end'; } var diff = Math.abs(Math.abs(this.pos) - Math.abs(this.stop)); if ( diff < this.slideStepLength ) { return 'stop'; } return 'continue'; }, intervalFunc : function ( dir ) { this.pos = (dir == 'left')? this.pos+this.slideStepLength : this.pos-this.slideStepLength; this.sliderWrap.setStyle('left', this.pos+'px'); var status = this.checkPosition(); if ( status != 'continue' ) { this.pos = this.stop; this.interval = window.clearInterval(this.interval); this.sliderWrap.setStyle('left', this.stop+'px'); this.updateButtons(status); } }, updateButtons : function ( status ) { if ( !status ) { var status = this.checkPosition(); } if ( status == 'end' ) { if (this.pos == 0) { this.disableButton('left'); this.enableButton('right'); } else { this.disableButton('right'); this.enableButton('left'); } } else { this.enableButton('both'); } }, disableButton : function ( position ) { if (position == 'left' || position == 'both') { this.leftButton.removeClass('left'); this.leftButton.addClass('leftDisabled'); this.leftButton.setProperty('disabled', 'true'); } if (position == 'right' || position == 'both') { this.rightButton.removeClass('right'); this.rightButton.addClass('rightDisabled'); this.rightButton.setProperty('disabled', 'true'); } }, enableButton : function ( position ) { if (position == 'left' || position == 'both') { this.leftButton.removeClass('leftDisabled'); this.leftButton.addClass('left'); this.leftButton.removeProperty('disabled'); } if (position == 'right' || position == 'both') { this.rightButton.removeClass('rightDisabled'); this.rightButton.addClass('right'); this.rightButton.removeProperty('disabled'); } } }); var site = 'os'; var httpUrl = 'http://lokalavisen.no'; var archiveUrl = 'http://lokalavisen.no/video'; var defaultCategory = '1'; var Player = new Player(); var Playlist = new Playlist(); var SearchResult = new SearchResult(); function rateVideo (id) { var rateId = new Date().getTime()+'-'+id; var jr = new Request.JSON({ url: '/templates/scripts/video/ajaxProxy.php', onComplete: function (r) { updateRating(id, r.rating); //return r.rating; } }).get({ 'rateId':rateId, 'action':'rate', 'id':id }); return parseInt(videos[id].rating)+1; } function getMostRatedLink () { return archiveUrl+'&categoryId=mostrated'; } function updateRating (id, rating) { if ( videos[id] ) { videos[id].updateRating(rating); } else { loadVideo(id, updateRating, rating); } } function runSearch () { var text = $('searchText').value; var jr = new Request.JSON({ url: '/templates/scripts/video/ajaxProxy.php', onComplete: function (v) { //SearchResult.update(v, text); updateSearchResult(v,text); } }).get({ 'action' : 'search', 'text': text }); } function updateSearchResult ( result, searchText ) { result = $H(result); var list = []; result.each(function ( video, id ) { if ( !videos[id] ) { videos[id] = new Video(video); } list.push(id) }); categories.each(function (c) { c.collapseContent(); }); lesernes.each(function (l) { l.collapseContent(); }); SearchResult.update(list, searchText); } function loadVideo (id, callback, callbackValue) { if ( String(id) != "" && String(id) != "null" ) { if (videos[id]) { if (typeof callback === 'function') { if (callbackValue) { callback(id, callbackValue); } else { callback(id); } } } else { var jr = new Request.JSON({ url: '/templates/scripts/video/ajaxProxy.php', onComplete: function (v) { if (v) { videos[id] = new Video(v); if (typeof callback === 'function') { if (callbackValue) { callback(id, callbackValue); } else { callback(id); } } } else { alert("Fant ikke video!"); } } }).get({ 'action' : 'load', 'id': id }); } } } /* function shareVideo ( site, id ) { if ( video = videos[id] ) { var u = encodeURIComponent(video.link); var t = encodeURIComponent(video.title); var d = encodeURIComponent(video.description); switch ( site ) { case 'facebook': window.open('http://www.facebook.com/sharer.php?u='+u+'&t='+t, 'sharer', 'toolbar=0,status=0,width=626,height=436'); break; case 'kudos': t = encodeURIComponent( video.title.replace(/^\s*|\s*$/g,'') ); window.open('http://www.kudos.no/giKudos.php?tittel='+t+ '&url='+u, 'kudos', 'toolbar=yes,width=1000,height=700'); break; case 'delicious': window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+u+'&title='+t, 'delicious', 'toolbar=no,width=700,height=400'); break; case 'tips': window.open('/templates/scripts/tips.php?type=1&Url='+video.link+'&Title='+video.title+'&Summary='+video.description, 'Tips', 'height=550,width=305', false); break; case 'twitter': window.open('http://twitter.com/home?status='+video.title+' '+video.link, 'twitter', 'height=550,width=700', false); break; case 'linkedIn': window.open('http://www.linkedin.com/shareArticle?mini=true&url='+u+'&title='+t+'&summary='+d, 'Linkedin', 'height=550,width=600', false); break; case 'myspace': window.open('http://www.myspace.com/index.cfm?fuseaction=postto&t='+t+'&c='+d+'&u='+u, 'MySpace', 'height=550,width=600', false); break; default: break; } } else { loadVideo(id, shareVideo, site); } } */ function getVideoUrl ( id ) { if ( videos[id] ) { return videos[id].link; } else { loadVideo(id, getVideoUrl); } } function getVideoRating ( id ) { if ( videos[id] ) { return videos[id].rating; } else { loadVideo(id, getVideoRating); } } function addVideoToCategoryList (id) { if (!videos[id].categoryId) { if (!categories[defaultCategory]) { return false; } categories[defaultCategory].addVideo(id); return true; } var cId = videos[id].categoryId if (categories[cId]) { categories[cId].addVideo(id); return true; } categories.each(function (cat) { if (cat.subcategories[cId]) { cat.addVideo(id, cId); return true; } }); if (!categories[defaultCategory]) { return false; } categories[defaultCategory].addVideo(id); return true; } function videoInCategoryList (id) { /*if (!videos[id]) { return false; } var cId = videos[id].categoryId; if (categories[cId] && categories[cId].videos.contains(id)) { return true; } if (categories.mostseen && categories.mostseen.videos.contains(id)) { return true; } if (categories.mostrated && categories.mostrated.videos.contains(id)) { return true; } categories.each(function (cat) { if (cat.subcategories) { cat.subcategories.each(function (subCat) { if (subCat.videos.contains(id)) { return true; } }); } }); return false;*/ categories.each(function (c, cId) { if ( c.videos.contains(id) ) { return cId; } else if ( c.subcategories ) { c.subcategories.each(function (s, sId) { if ( s.videos.contains(id) ) { return sId; } }); } }); return false; } function startEvent (id) { if (!videos[id]) { loadVideo(id, startEvent); } else { videos[id].setPlaying(); Player.update('info'); } } function nextEvent () { if ( Player.playingId ) { videos[Player.playingId].setNotPlaying(); } var id = NettTv.API.getActive(); Player.playingId = id; startEvent(id); } function scrollToElement ( el, offset ) { var position = 0; if ( offset ) { position += offset; } if ( el.offsetParent ) { while ( el.offsetParent ) { position += el.offsetTop; el = el.offsetParent; } } else if ( el.y ) { position += el.y; } window.scrollTo(0, position); } function showCategory ( id ) { categories.each(function (c) { if ( id != c.id ) { c.collapseContent(); } if ( c.subcategories && c.subcategories[id] ) { c.update(id); } }); lesernes.each(function (l) { if ( id != l.id ) { l.collapseContent(); } else if ( l.subcategories[id] ) { l.update(id); } }); } function playVideo ( id ) { if ( videos[id] ) { Player.play(id); } else { loadVideo(id, playVideo); } } function init (playId, categoryId) { videos = $H(videos); videos.each(function (obj, key) { videos[key] = new Video(obj); }); categories = $H(categories); categories.each(function (obj, key) { categories[key] = new Category(obj); }); lesernes = $H(lesernes); lesernes.each(function (obj, key) { lesernes[key] = new Lesernes(obj); }); NettTv.API.addHook('play', startEvent); NettTv.API.addHook('next', nextEvent); Player.getElements(); if ( playId ) { playVideo(playId); } else if ( categoryId && categoryId != 'false' ) { showCategory(categoryId); } } //---- COMMENT FUNCTIONS ----// function clrOnFocus(obj,defText){ if(obj.value == defText) obj.value = ""; } function restoreIfBlank(obj,defText){ if(obj.value == "") obj.value = defText; } function clrOnSubmit(){ if(document.artcom.Title.value == "tittel") document.artcom.Title.value = ""; if(document.artcom.Comment.value == "Skriv din mening her..") document.artcom.Comment.value = ""; if(document.artcom.Name.value == "Ditt navn") document.artcom.Name.value = ""; document.artcom.ArtTitle.value = document.title; document.artcom.submit(); } function anmeldPopup(Form){ Form.Title.value = document.title; window.open('about:blank','anmeld','width=500px,height=360px'); Form.submit(); } function shareVideo (shareSite, id) { if (videos[id]) { var u = encodeURIComponent(videos[id].link); var t = encodeURIComponent(videos[id].title); var d = encodeURIComponent(videos[id].description); switch ( shareSite ) { case 'facebook': window.open('http://www.facebook.com/sharer.php?u='+u+'&t='+t, 'sharer', 'toolbar=0,status=0,width=626,height=436'); break; case 'kudos': t = encodeURIComponent( video.title.replace(/^\s*|\s*$/g,'') ); window.open('http://www.kudos.no/giKudos.php?tittel='+t+ '&url='+u, 'kudos', 'toolbar=yes,width=1000,height=700'); break; case 'delicious': window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+u+'&title='+t, 'delicious', 'toolbar=no,width=700,height=400'); break; case 'tips': window.open('/templates/scripts/tips.php?type=1&Url='+u+'&Title='+t+'&Summary='+d, 'Tips', 'height=550,width=305', false); break; case 'twitter': window.open('http://twitter.com/home?status='+t+' '+u, 'twitter', 'height=550,width=700', false); break; case 'linkedIn': window.open('http://www.linkedin.com/shareArticle?mini=true&url='+u+'&title='+t+'&summary='+d, 'Linkedin', 'height=550,width=600', false); break; case 'myspace': window.open('http://www.myspace.com/index.cfm?fuseaction=postto&t='+t+'&c='+d+'&u='+u, 'MySpace', 'height=550,width=600', false); break; default: break; } } else { alert('Kan ikke dele video! Prøv igjen senere!'); } } function getMostRatedLink () { return archiveUrl+'&categoryId=mostrated'; }