﻿function maskEmail(account, linktext) {
    var username = account;
    var hostname = "sonos";

    document.write("<a href=\"" + "mail" + "to:" + username + "@" + hostname + ".com" + "\">" + linktext + "</a>");
}

function embedVideoPlayer(file, height, width, image, GA_id, sharelink, divID) 
{
    jwplayer(divID).setup({
        'id': 'playerID',
        'width': width,
        'height': height,
        'file': "http://videos.sonos.com" + file,
        'image': image,
        'modes': [
		    { type: 'flash', src: '/js/player.swf' },
		    { type: 'html5',
		        config: {
		            'file': "http://videos.sonos.com" + file,
		            'provider': 'video'
		        }
		    },
		    { type: 'html5',
		        config: {
		            'file': "http://videos.sonos.com" + file.replace(".mp4", ".ogv"),
		            'provider': 'video'
		        }
		    }],
        'controlbar': 'over',
        'controlbar.idlehide': 'true',
        'skin': '/videos/glow.zip',
        'title': GA_id,
        'events': { onPlay: function (event) { $('#playerText').hide(); }, onComplete: function () { $('#playerText').show(); } },
        'plugins': {
            'gapro-2': {
                'idstring': '||title||',
                'trackstarts': true,
                'trackpercentage': true,
                'trackseconds': true
            },
            'sharing-2': {
                link: sharelink
            }
        }
    });
}

function embedVideo(file, height, width, image, GA_id, sharelink) 
{
    embedVideoPlayer(file, height, width, image, GA_id, sharelink, 'mediaplayer');
}

function popupVideo(file, width, height, image, GA_id, sharelink, clickedElement) 
    {
        $.fancybox({
            'content': '<div id="video"></div>',
            'hideOnContentClick': false,
            'autoScale': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'overlayOpacity': 0.7,
            'overlayColor': '#000',
            'scrolling': false,
            'titleShow': false,
            'autoDimensions': false,
            'width': width < 768 ? width : 768, 'height': height < 432 ? height : 432,
            'file': "http://videos.sonos.com" + file,
            
            'padding': 5,
            'title': GA_id,
            'onComplete': function () {
                jwplayer('video').setup({
                
                    'id': 'playerID',
                    'width': width < 768 ? width : 768,
                    'height': height < 432 ? height : 432,
                    'flashplayer': "/js/player.swf",
                    'image': image,
                    'levels': [
                            { file: "http://videos.sonos.com" + file + '?autostart=true' },
                            { file: "http://videos.sonos.com" + file.replace(".mp4", ".ogv") + '?autostart=true' }
                        ],
                    'controlbar': "over",
                    'controlbar.idlehide': "true",
                    'skin': '/videos/glow.zip',
                    'events': { onPlay: function (event) { $('#playerText').hide(); }, onComplete: function () { $('#playerText').show(); } },
                    'plugins': {
                        'gapro-2': {
                            'idstring': '||title||',
                            'trackstarts': true,
                            'trackpercentage': true,
                            'trackseconds': true
                        },
                        'sharing-2': {
                            link: sharelink
                        }
                    }
                });
                jwplayer('video').play();
                return false;
            },
            'onCleanup': function () {
                jwplayer('video').remove();
            }
        });
    }

    // when a key is pressed in the search box
    function handleSearchKeyDown(e) {
        var KeyPressed;

        if (window.event) {
            KeyPressed = window.event.keyCode;
        }
        else {
            KeyPressed = e.which;
        }

        if (KeyPressed == 13) {
            $('#btnSearchGo').click();
            return false;
        }
        else {
            $('#txtSearch').removeClass('RedborderTextbox');
        }

    }



    function gaqPusher(type, category, action, tracker) {
        _gaq.push([type, category, action, tracker]);
    }

    function mobileVideo(file, GA_id) {

        
        /*$('#videoContainer').show();
        jwplayer('videoContainer').setup({
            'file': file,
            'modes': [
            //{type: 'flash', src: '/js/player.swf'},
		    {type: 'html5',
		    config: {
		        'file': file,
		        'provider': 'video'
		    }
		},
		    { type: 'html5',
		        config: {
		            'file': file.replace(".mp4", ".ogv"),
		            'provider': 'video'
		        }
		    }],
            'width': 320,
            'height': 270,
            'title': GA_id,
            //'autostart': "true",
            'events': { onReady: function () {
                $('#videoContainer_jwplayer_display_image').trigger('click');
                //$('#videoContainer_video').load(); 
                $('#videoContainer_video').trigger('click');}
            }, onComplete: function () { },
            'plugins': {
                'gapro-2': {
                    'idstring': '||title||',
                    'trackstarts': true,
                    'trackpercentage': true,
                    'trackseconds': true
                }
            }
        });   */     
    }


