﻿function setup() {
    core.init();
    mario.init();
}
var mario = {

    init: function() {
        this.ua = navigator.userAgent.toLowerCase();
        this.ws = "mario.asmx";
        this.maxH = 400;
        wonder.msgId = '';
    },
    getImage: function() {
        core.getData('mario.asmx/getImage', 'post', '', 'json', mario.showImage, '', '');
    },
    displayImage: function(i, w, h, t, te) {
        if (i.width > 0 && i.height > 0) {
            $('#picLightBox').css('backgroundImage', 'url(' + i.src + ')');
            if (i.height > (h - 50)) {
                $('#picLightBox').css('width', (i.width * ((h - 50) / i.height)) + 'px');
                $('#picLightBox').css('height', (h - 50) + 'px');
                $('#picLightBox').css('-webkit-background-size', (i.width * ((h - 50) / i.height)) + 'px ' + (h - 60) + 'px');
                $('#picLightBox').css('-moz-background-size', (i.width * ((h - 50) / i.height)) + 'px ' + (h - 60) + 'px');
                $('#picLightBox').css('-o-background-size', (i.width * ((h - 50) / i.height)) + 'px ' + (h - 60) + 'px');
                $('#picLightBox').css('background-size', (i.width * ((h - 50) / i.height)) + 'px ' + (h - 60) + 'px');
            } else {
                $('#picLightBox').css('width', i.width + 'px');
                $('#picLightBox').css('height', i.height + 'px');
                $('#picLightBox').css('-webkit-background-size', i.width + 'px ' + i.height + 'px');
                $('#picLightBox').css('-moz-background-size', i.width + 'px ' + i.height + 'px');
                $('#picLightBox').css('-o-background-size', i.width + 'px ' + i.height + 'px');
                $('#picLightBox').css('background-size', i.width + 'px ' + i.height + 'px');
            }
            //$('#picLoader').hide();
            //$('#picLightBox').show();
            core.loadModal(w, h, t, te);
        }
    },
    //OVERLAY
    highlightPic: function(elem) {
        $('#' + elem).show();
    },
    lowlightPic: function(elem) {
        $('#' + elem).hide();
    },
    loadPic: function(w, h, t, te, p,s) {
        $('#picLightBox').hide();
        $('#picLightBox').css('backgroundImage', 'url(\'\')');
        $('#picLightBox').html('');
        $('#picLoader').show();
        core.loadModal(w, h, t, te,s);
        $('<img/>').attr('src', 'http://getmehere.com/res/gallery/' + p).load(function() {
        $('#picLightBox').css('backgroundImage', 'url(\'http://getmehere.com/res/gallery/' + p + '\')');
            $('#picLightBox').css('width', (w - 15) + 'px');
            $('#picLightBox').css('height', (h - 55) + 'px');
            //$('#picLightBox').html('<img src="http://getmehere.com/res/gallery/' + p + '" alt="' + te + '"/>');
            $('#picLightBox').css('-webkit-background-size', (w - 15) + 'px ' + (h - 55) + 'px');
            $('#picLightBox').css('-moz-background-size', (w - 15) + 'px ' + (h - 55) + 'px');
            $('#picLightBox').css('-o-background-size', (w - 15) + 'px ' + (h - 55) + 'px');
            $('#picLightBox').css('background-size', (w - 15) + 'px ' + (h - 55) + 'px');
            $('#picLoader').hide();
            $('#picLightBox').show();
        });
    },
    //TRACKING
    trackDone: function() {

    },
    track: function(action, link) {
        core.getData('mario.asmx/setTrackForAction', 'post', '{ "a": "' + action + '", "m": "' + wonder.msgId + '" }', 'json', wonder.trackDone, '', '');
        if (link.length > 0) {
            var newWindow = window.open(link, '_blank');
            newWindow.focus();
        }
        return false;
    }
};
