﻿window.addEvent('domready', function() {
    var searchConnections = $('searchConnections');
    if (searchConnections) {
        new OverText(searchConnections, { 'positionOptions': { 'offset': { x:30, y:5 }}});
        searchConnections.addEvent('keydown', function(e) {
            if (e.key == "enter") {
                if (searchConnections.value.length == 0) {
                    alert('Please enter your connection');
                    return;
                }
                window.location.href = 'discover/?q=' + escape(searchConnections.value);
            }
        });
        new Autocompleter.Ajax.Json(searchConnections, '/data/partners.aspx', { postVar: 'q' });
    }
    
    var searchAccounting = $('searchAccounting');
    if (searchAccounting) {
        new OverText(searchAccounting, { 'positionOptions': { 'offset': { x:30, y:5 }}});
        searchAccounting.addEvent('keydown', function(e) {
            if (e.key == "enter") {
                if (searchAccounting.value.length == 0) {
                    alert('Please enter your accounting package');
                    return;
                }
                window.location.href = 'discover/?accounting=' + escape(searchAccounting.value);
            }
        });
        new Autocompleter.Ajax.Json(searchAccounting, '/data/systems.aspx', { postVar: 'q' });
    }

    integrationImage = $('integrationBanner');
    if (integrationImage) {
        integrationImage.addEvents({
            'mouseenter': function() {
                showPlay();
            },
            'mouseleave': function() {
                hidePlay();
            }
        });
    }
});

var integrationImage;
var play;
var playTimer;
function showPlay() {
    $clear(playTimer);
    if (!play) {
        var position = integrationImage.getPosition();
        play = new Element('img', { 'src': '/images/v3/play.png', 'styles': { 'position': 'absolute', 'z-index': '100', 'cursor': 'pointer', 'top': (position.y + 135), 'left': (position.x + 428) }}).inject($(document.body));
        play.addEvents({
            'mouseenter': function() { showPlay(); },
            'mouseleave': function() { hidePlay(); },
            'click': function() { openVideo(); }
        });
    }
}
function hidePlay() {
    playTimer = setTimeout(doHidePlay, 50);
}
function doHidePlay() {
    if (play) {
        play.destroy();
        play = null;
    }
}
function openVideo() {
    doHidePlay();

    var popup = '<iframe title="YouTube video player" width="600" height="450" src="https://www.youtube.com/embed/zrwcIJ3baBA?rel=0" frameborder="0" allowfullscreen></iframe>';
    new StickyWin.Modal({
        content: popup,
        maskOptions: { style: { 'background-color':'#d6e1b9', 'opacity':.6 }},
        //closeClassName: 'closer',
        destroyOnClose: true
    });
}

