jQuery(document).ready(function() {

// Remove Borders from li's ,etc...

jQuery("#nav li ul li:last-child").css("border-bottom","0");

// Equal heights for the footer panels (left and right)

var footer_left;
footer_left = jQuery("#about").height();

var footer_right;
footer_right = jQuery("#contact").height();

    if(footer_left > footer_right){
        jQuery('#contact').height(footer_left);
    }
    else if(footer_right > footer_left){
        jQuery('#about').height(footer_right - 40);						
    };

});

function silentAlert(message) {
    $.jGrowl(message.replace('\r\n', '<br />'), { closer: false });
}

function showNotification(message, timeOut) {
    timeOut = timeOut || 3000;

    if (window.webkitNotifications) { // Feature detection
        if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED
            var notification = window.webkitNotifications.createNotification('/Content/Images/favicon.ico',
                'Maestroo notification', message);
            notification.show();
            setTimeout(function () {
                notification.cancel();
            }, timeOut);
            return;
        } else {
            window.webkitNotifications.requestPermission();
        }
    }

    $.jGrowl(message.replace('\r\n', '<br />'), { closer: false, life: timeOut });
}

/*
var MyApp = {

    addPlaceholders: function (props) {

        // default configuration
        var config = {
            'class': 'placeholder' // apply CSS classes to an input displaying a placeholder
        };

        // if any properties were supplied, apply them to the config object
        for (var key in props) {
            if (config.hasOwnProperty(key)) {
                config[key] = props[key];
            }
        }

        // create a basic form for testing support
        var testform = $('<form><input type="text"></form>');

        // extend jQuery.support() for testing "placeholder" attribute support
        $.extend($.support, {
            placeHolder: !!($('input', testform)[0].placeholder !== undefined || $('input', testform)[0].placeHolder !== undefined)
        });

        // create placeholders by using "value" attribute
        if (!$.support.placeHolder) {
            $('input[placeholder]').each(function () {
                var placeholder = $(this).attr('placeholder');
                $(this).bind({
                    'focus': function () {
                        if ($(this).val() === placeholder) {
                            $(this).val('');
                            $(this).removeClass(config['class']);
                        }
                        $(this).attr('data-focused', 'yes');
                    },
                    'blur': function () {
                        if ($(this).val() === '') {
                            $(this).val(placeholder);
                            $(this).addClass(config['class']);
                        }
                        $(this).removeAttr('data-focused');
                    }
                });
                // only add placeholder on load when value is empty or placeholder or input is not focused (focus is preserved while reloading/XHR)
                if ((($(this).val() === '') || ($(this).val() === placeholder)) && (!$(this).attr('data-focused'))) {
                    $(this).val(placeholder);
                    $(this).addClass(config['class']);
                }
            });
        }

    },
    clearJumpList: function () {
        var isInSiteMode = ((typeof(window.external.msIsSiteMode) != 'undefined') && window.external.msIsSiteMode());

        if (!isInSiteMode) {
            return;
        }

        window.external.msSiteModeClearJumpList();
        window.external.msSiteModeShowJumpList();
    },
    updateJumpList: function (canSkip) {
        var isInSiteMode = ((typeof (window.external.msIsSiteMode) != 'undefined') && window.external.msIsSiteMode());

        if (!isInSiteMode) {
            return;
        }

        window.external.msSiteModeClearJumpList();

        window.external.msSiteModeCreateJumpList('Song');

        if (canSkip) {
            window.external.msSiteModeAddJumpListItem('Skip To Next',
            '/Room/NextSong',
            '/Content/Images/favicon.ico');
        }

        window.external.msSiteModeAddJumpListItem('Vote 1 Star',
            '/Room/VoteOnCurrentSong?value=1',
            '/Content/Images/icons/1_star.ico');
        window.external.msSiteModeAddJumpListItem('Vote 2 Stars',
            '/Room/VoteOnCurrentSong?value=2',
            '/Content/Images/icons/2_star.ico');
        window.external.msSiteModeAddJumpListItem('Vote 3 Stars',
            '/Room/VoteOnCurrentSong?value=3',
            '/Content/Images/icons/3_star.ico');
        window.external.msSiteModeAddJumpListItem('Vote 4 Stars',
            '/Room/VoteOnCurrentSong?value=4',
            '/Content/Images/icons/4_star.ico');
        window.external.msSiteModeAddJumpListItem('Vote 5 Stars',
            '/Room/VoteOnCurrentSong?value=5',
            '/Content/Images/icons/5_star.ico');

        window.external.msSiteModeShowJumpList();
    }
};
*/

var socket;

$(document).ready(function () {
    if (window.external) {
    /* disable IE9 extensions for now. not important and it bugs in Safari  
        try{
        
        MyApp.addPlaceholders();
        }
        catch(err){
        }
        */
    }

    if (typeof (io) == "undefined") {
        //    alert("Can not connect to realtime server, please contact support");
        //    only show error in room (room.js)

    } else {

        socket = io.connect(nodeUrl, { secure: false, rememberTransport: false, transports: ['websocket', 'flashsocket', 'xhr-polling', 'jsonp-polling'] });

        if (typeof (room) != "undefined") {
            socket.on('connect', function (data) {
                socket.emit('checkin', { user: user, room: room.toLowerCase() });
            });

        }
    }


});




function addLeadingZero(value) {
    // hack: ugly but no time to find padding functions in javascript
    if (value == 0)
        return "00";

    if (value < 10)
        return "0" + value;

    return value;
}


String.prototype.startsWith = function (t, i) {
    if (i == false) {
        return
        (t == this.substring(0, t.length));
    } else {
        return (t.toLowerCase() == this.substring(0, t.length).toLowerCase());
    }
}




