﻿window.pemco = window.pemco || {};

$(function() {
    var pub = pemco.functions = {};

    pub.grabVotes = function(codename) {

        var data = { 'action': 'get_vote_for_selected_profile', 'title_nw_types_ads': codename };

        jQuery.ajax({
            type: "GET",
            url: "ajax/default.aspx",
            dataType: "json",
            data: data,
            success: function(response) {
                if (response) {
                    if (response.status == "Success") {
                        lastHash = window.location.hash.substr(1);

                        arrState = lastHash.split("/");

                        if (arrState[0] == "userprofiles") {
                            if (getFlashMovie("ProfileCarouselUser") != null)
                                getFlashMovie("ProfileCarouselUser").sentVotes(response.html);
                        }
                        else {
                            if (getFlashMovie("ProfileCarousel") != null)
                                getFlashMovie("ProfileCarousel").sentVotes(response.html);
                        }
                    }
                    else {
                        pemco.ajax.flash(response.message, response.status);
                    }
                }
            }
        ,
            error: function() { }
        });

        //return false; //Prevent Propagation
    };

    pub.voteForProfile = function(codename) {
        var data = { 'action': 'vote_for_selected_profile', 'title_nw_types_ads': codename };

        jQuery.ajax({
            type: "POST",
            url: "ajax/default.aspx",
            dataType: "json",
            data: data,
            success: function(response) {
                if (response) {

                    if (response.status == "Success") {
                        lastHash = window.location.hash.substr(1);

                        arrState = lastHash.split("/");

                        if (arrState[0] == "userprofiles") {
                            if (getFlashMovie("ProfileCarouselUser") != null)
                                getFlashMovie("ProfileCarouselUser").sentVotes(response.html);
                        }
                        else {
                            if (getFlashMovie("ProfileCarousel") != null)
                                getFlashMovie("ProfileCarousel").sentVotes(response.html);
                        }
                    }
                    else {
                        pemco.ajax.flash(response.message, "Oops!");
                    }
                }
            }
            ,
            error: function() { }
        });

    }

    pub.changeHash = function(strHash) {

        var currHash = window.location.hash.toString();

        if (currHash.indexOf("userprofiles") != -1) {
            pemco.bbq.changeHash("userprofiles/" + strHash);
        }
        else {
            pemco.bbq.changeHash("profiles/" + strHash);
        }
    };

    pub.profileBack = function(profileName) {
        pemco.bbq.changeHash("profiles", profileName);
    };
    
    pub.removeHash = function() {
        pemco.bbq.changeHash("profiles");
    };

    pub.call = function(func, data) {

    };

    /*
    pemco.runFN = function(name) {
    var parts = /^([\w\.]*)\.(\w*)$/.exec(name),
    scope = (new Function('return ' + parts[1]))(),
    fn = (new Function('return ' + parts[2]))(),
    args = Array.prototype.slice.call(arguments, 1);
    return fn.apply(scope, args);
    };
    */
    //getURL("javascript:pemco.ecard.popup('an example string', 'second param');");
    // pemco.runFN('pemco.ecard.popup', 'an example string', 'second param');

});



//Trading Card
$(function() {
    var pub = pemco.tradingcard = {};

    pub.popup = function(codename) {
        pemco.iframe.load('profile-rel-card iframe-form tradingcards-' + codename);
    };
});

$(function() {
    var pub = pemco.ecards = {};

    pub.popup = function(codename) {
        pemco.iframe.load('profile-rel-ecard iframe-form ecards-' + codename);
    }
});


///Ecard
