﻿var sCurrentCategory;
var sCurrentItemType;
var sCurrentItemName = null;
var sCurrentUrlLinkBack = null;
//var sCurrentUserNickname = null;
var sCurrentReactionClicked = null;
var sCurrentItemImagePath = null;
var fbUserAction = null;
var fbTitle = null;

sCurrentPage = 'navRewards';

function InitItemDetails(nItemID) {
    var sXID = 'fbcItem' + nItemID;
    //PopulateFacebookComments(sXID, true);
}

function PopulateAccess45Content() {
    var dCurrent = new Date();

    dCurrent = GetCurrentDateTime();

    switch (dCurrent.getMonth()) {
        case 9:
            switch (dCurrent.getDate()) {
                case 1:
                    jQuery('#headerPromotion').addClass('MOH_console');
                    break;
                case 2:
                    jQuery('#headerPromotion').addClass('MOH_PC');
                    break;
                case 3:
                    jQuery('#headerPromotion').addClass('MOH_oakley');
                    break;
                case 4:
                    jQuery('#headerPromotion').addClass('MOH_shirts');
                    break;
                case 5:
                    jQuery('#headerPromotion').addClass('justDance_wii');
                    break;
                case 6:
                    jQuery('#headerPromotion').addClass('speed_rental');
                    break;
                case 7:
                    jQuery('#headerPromotion').addClass('speed_starter');
                    break;
                case 8:
                    jQuery('#headerPromotion').addClass('speed_rental');
                    break;
                case 9:
                    jQuery('#headerPromotion').addClass('speed_starter');
                    break;
                case 10:
                    jQuery('#headerPromotion').addClass('MOH_oakley');
                    break;
                case 11:
                    jQuery('#headerPromotion').addClass('MOH_xbox');
                    break;
                case 12:
                    jQuery('#headerPromotion').addClass('MOH_oakley');
                    break;
                case 13:
                    jQuery('#headerPromotion').addClass('MOH_shirts');
                    break;
                case 14:
                    jQuery('#headerPromotion').addClass('MOH_console');
                    break;
                case 15:
                    jQuery('#headerPromotion').addClass('MOH_PC');
                    break;
                case 16:
                    jQuery('#headerPromotion').addClass('rabbids_caesar');
                    break;
                case 17:
                    jQuery('#headerPromotion').addClass('rabbids_indian');
                    break;
                case 18:
                    jQuery('#headerPromotion').addClass('rabbids_wallpaper');
                    break;
                case 19:
                    jQuery('#headerPromotion').addClass('rabbids_napoleon');
                    break;
                case 20:
                    jQuery('#headerPromotion').addClass('MMA_console');
                    break;
                case 21:
                    jQuery('#headerPromotion').addClass('MMA_game');
                    break;
                case 22:
                    jQuery('#headerPromotion').addClass('MMA_autographed');
                    break;
                case 23:
                    jQuery('#headerPromotion').addClass('MMA_clinch');
                    break;
                case 24:
                    jQuery('#headerPromotion').addClass('MMA_sweeps');
                    break;
                case 25:
                    jQuery('#headerPromotion').addClass('MMA_console');
                    break;
                case 26:
                    jQuery('#headerPromotion').addClass('MMA_game');
                    break;
                case 27:
                    jQuery('#headerPromotion').addClass('MMA_autographed');
                    break;
                case 28:
                    jQuery('#headerPromotion').addClass('MMA_clinch');
                    break;
                case 29:
                    jQuery('#headerPromotion').addClass('MMA_sweeps');
                    break;
                case 30:
                    jQuery('#headerPromotion').addClass('MMA_game');
                    break;
                case 31:
                    jQuery('#headerPromotion').addClass('rabbids_wii');
                    break;
                default:
                    break;
            }
            break;
        case 10:
            switch (dCurrent.getDate()) {
                case 1:
                    jQuery('#headerPromotion').addClass('creed_jitb');
                    break;
                case 2:
                    jQuery('#headerPromotion').addClass('creed_sweeps');
                    break;
                case 3:
                    jQuery('#headerPromotion').addClass('creed_avatar');
                    break;
                case 4:
                    jQuery('#headerPromotion').addClass('creed_shirts');
                    break;
                case 5:
                    jQuery('#headerPromotion').addClass('MOH_oakley');
                    break;
                case 6:
                    jQuery('#headerPromotion').addClass('MOH_shirts');
                    break;
                case 7:
                    jQuery('#headerPromotion').addClass('MOH_oakley');
                    break;
                case 8:
                    jQuery('#headerPromotion').addClass('MOH_PS3');
                    break;
                case 9:
                    jQuery('#headerPromotion').addClass('MOH_console');
                    break;
                case 10:
                    jQuery('#headerPromotion').addClass('creed_interview');
                    break;
                case 11:
                    jQuery('#headerPromotion').addClass('creed_poster');
                    break;
                case 12:
                    jQuery('#headerPromotion').addClass('creed_wallpaper');
                    break;
                case 13:
                    jQuery('#headerPromotion').addClass('creed_ringtone');
                    break;
                case 14:
                    jQuery('#headerPromotion').addClass('creed_console');
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}

function InitRewards() {
    switch($.query.get('sCategory')) {
        case 'All':
            sCurrentCategory = 'All';
            jQuery('#tabAll img').attr('src', '/Images/Rewards/tabAll_on.png');
            jQuery('#calloutCategory').html('<img src="/Images/Rewards/calloutAll.jpg" alt="All Stuff" />');
            break;
        case 'Games':
            sCurrentCategory = 'Games';
            jQuery('#tabGames img').attr('src', '/Images/Rewards/tabGames_on.png');
            jQuery('#calloutCategory').html('<img src="/Images/Rewards/calloutGames.jpg" alt="Games Stuff" />');
            jQuery('#headerPromotion').css('display', 'none');
            break;
        case 'Movies':
            sCurrentCategory = 'Movies';
            jQuery('#tabMovies img').attr('src', '/Images/Rewards/tabMovies_on.png');
            jQuery('#calloutCategory').html('<img src="/Images/Rewards/calloutMovies.jpg" alt="Movies Stuff" />');
            jQuery('#headerPromotion').css('display', 'none');
            break;
        case 'Music':
            sCurrentCategory = 'Music';
            jQuery('#tabMusic img').attr('src', '/Images/Rewards/tabMusic_on.png');
            jQuery('#calloutCategory').html('<img src="/Images/Rewards/calloutMusic.jpg" alt="Music Stuff" />');
            jQuery('#headerPromotion').css('display', 'none');
            break;
        case 'Causes':
            sCurrentCategory = 'Causes';
            jQuery('#tabCauses img').attr('src', '/Images/Rewards/tabCauses_on.png');
            jQuery('#calloutCategory').html('<img src="/Images/Rewards/calloutCauses.jpg" alt="Causes" />');
            jQuery('#headerPromotion').addClass('causes');
            jQuery('#headerPromotion').html('');
            jQuery('#headerItemTypeProducts').css('background', 'url("/Images/Rewards/headerProducts_Charity.png") no-repeat');
            break;
        case 'Promotion1':
            sCurrentCategory = 'Promotion1';
            jQuery('#calloutCategory').html('<img src="/Images/Rewards/calloutAll.jpg" alt="All Stuff" />');

            // Access 45 code to change the header image depending on the date
            //PopulateAccess45Content();

            break;
        case 'Promotion2':
            sCurrentCategory = 'Promotion2';
            jQuery('#calloutCategory').html('<img src="/Images/Rewards/calloutAll.jpg" alt="All Stuff" />');

            break;
        case 'Slurpee':
            sCurrentCategory = 'Slurpee';
            jQuery('#calloutCategory').html('<img src="/Images/Rewards/calloutAll.jpg" alt="All Stuff" />');
            break;
        case 'About':
            sCurrentCategory = 'About';
            jQuery('#tabAbout img').attr('src', '/Images/Rewards/tabAbout_on.png');
            jQuery('#calloutCategory').html('<img src="/Images/Rewards/calloutAll.jpg" alt="All Stuff" />');
            break;
        case '':
            sCurrentCategory = 'About';
            jQuery('#tabAbout img').attr('src', '/Images/Rewards/tabAbout_on.png');
            jQuery('#calloutCategory').html('<img src="/Images/Rewards/calloutAll.jpg" alt="All Stuff" />');
            break;
        default:
            break;
    }
    
    switch($.query.get('sItemType')) {
        case 'Products':
            sCurrentItemType = 'Products';
            jQuery('input:radio[@value="itemTypes"]')[0].checked = true;
            jQuery('#itemTypeImage').html('<div id="headerItemTypeProducts" class=""headerItemTypeName""></div>');
            break;
        case 'Downloads':
            sCurrentItemType = 'Downloads';
            jQuery('input:radio[@value="itemTypes"]')[1].checked = true;
            jQuery('#itemTypeImage').html('<div id="headerItemTypeDownloads" class=""headerItemTypeName""></div>');
            break;
        case 'Sweeps':
            sCurrentItemType = 'Sweeps';
            jQuery('input:radio[@value="itemTypes"]')[2].checked = true;
            jQuery('#itemTypeImage').html('<div id="headerItemTypeSweeps" class=""headerItemTypeName""></div>');
            break;
        default:
            break;
    }
    
    switch($.query.get('nSortOption')) {
        case 1:
            jQuery('#sortOptions').val('1').attr('selected','selected');
            break;
        case 2:
            jQuery('#sortOptions').val('2').attr('selected','selected');
            break;
        default:
            jQuery('#sortOptions').val('1').attr('selected','selected');
            break;
    }

    switch ($.query.get('bCauseItem')) {
        case 'True':
            jQuery('#facebookCommentShare').css('display', 'none');
            break;
        default:
            jQuery('#causeLeaderboard').css('display', 'none');
            break;
    }

    jQuery('a.seeAll').click(function(event) {
        location.href = 'ViewItemType.aspx?sItemType=' + jQuery(this).attr('name') + '&sCategory=' + sCurrentCategory;
    });
    
    jQuery('input:radio[@name="itemTypes"]').click(function() {
        location.href = 'ViewItemType.aspx?sItemType=' + jQuery(this).val() + '&sCategory=' + sCurrentCategory;
    });
    
    jQuery('#sortOptions').change(function() {
        location.href = 'ViewItemType.aspx?sItemType=' + sCurrentItemType + '&sCategory=' + sCurrentCategory + '&nSortOption=' + jQuery(this).val();
    });
    
    jQuery('#moduleTabsRewards a').hover(function() {
        jQuery('#' + jQuery(this).attr('id') + ' img').attr('src', '/Images/Rewards/' + jQuery(this).attr('id') + '_on.png');
    }, function() {
        if ((jQuery(this).attr('id')) != ('tab' + sCurrentCategory)) {
            jQuery('#' + jQuery(this).attr('id') + ' img').attr('src', '/Images/Rewards/' + jQuery(this).attr('id') + '_off.png');
        }
    });
    
//    jQuery('#facebookCommentsCount').click(function(event) {
//        jQuery('#moduleFacebookComments').css('display', 'block');
//        jQuery('#moduleFacebookComments').css('top', (GetScrollY() + 150));
//    });

    jQuery('#linkFullLegal').click(function (event) {
        jQuery('#modulePointSchedule').css('display', 'none');
        jQuery('#moduleLegalFull').css('display', 'block');
        jQuery('#moduleLegalFull').css('top', (GetScrollY() + 150));
    });
    
    jQuery('#closeLegalFull').click(function(event) {
        jQuery('#moduleLegalFull').css('display', 'none');
    });

    jQuery('#closePointSchedule').click(function (event) {
        jQuery('#modulePointSchedule').css('display', 'none');
    });
    
    jQuery('#amoe_rules').click(function(event) {
        jQuery('#moduleLegalFull').css('display', 'block');
    });

    jQuery('#linkPointSchedule').click(function (event) {
        jQuery('#moduleLegalFull').css('display', 'none');
        jQuery('#modulePointSchedule').css('display', 'block');
        jQuery('#modulePointSchedule').css('top', (GetScrollY() + 150));
    });
    
    jQuery('#amoe_link').click(function(event) {
        window.parent.location.href += '&bAMOE=True';
    });

    jQuery('.snickersCodeLocation').click(function (event) {
        jQuery('#modalSnickersCodeLocation').fadeIn("Fast");
    });

    jQuery('#modalSnickersCodeLocation').click(function (event) {
        jQuery('#modalSnickersCodeLocation').fadeOut("Fast");
    });
}

//----jquery code for rewards page

var currentSlideHolder = "#mathSlideHolder";
var currentButton = "#buttonSlurpeeMath";
var currentPagerClass = "mathPager";

function InitRewardsSlides() {
    $("#mathSlideHolder").cycle({ fx: 'scrollLeft', pager: "#slidePager", cleartypeNoBg: true, cleartype: true, timeout: 6000 });

    $("#buttonSlurpeeMath").click(function () {
        SwapRewardsSlides("#buttonSlurpeeMath", "#mathSlideHolder", "mathPager");
    });

    $("#buttonCodes").click(function () {
        SwapRewardsSlides("#buttonCodes", "#cheatSlideHolder", "codesPager");
    });

    $("#buttonProblem").click(function () {
        SwapRewardsSlides("#buttonProblem", "#helpSlideHolder", "helpPager");
    });
}

function SwapRewardsSlides(buttonId, slideHolderId, pagerClass) {
    if (buttonId == currentButton) {
        return;
    }
    $("#slidePager").html("");
    $("#slidePager").removeClass(currentPagerClass);
    $("#slidePager").addClass(pagerClass);
    currentPagerClass = pagerClass;
    $(currentSlideHolder).cycle('stop');
    $(buttonId).addClass("rewardsButtonSelected");
    $(currentButton).removeClass("rewardsButtonSelected");
    $(currentSlideHolder).fadeOut("fast", function () {
        $(slideHolderId).fadeIn("fast", function () {
            $(slideHolderId).cycle({ fx: 'scrollLeft', pager: "#slidePager", cleartypeNoBg: true, cleartype: true, timeout: 6000 });
        });
    });
    currentSlideHolder = slideHolderId;
    currentButton = buttonId;
}

function getCurrentItemImagePath(imagePath) {
    sCurrentItemImagePath = imagePath;
}

function setRewardsReactions(conf, title, contextId, barId, urlLinkback, rewardType) {
    var textReactions;
    var toolTipCopyGamesMovie = 'This item rates ';

    if (rewardType == "games") {
        textReactions = [
        {
            text: 'Level One',
            ID: 'Reactions_Rewards_Game_LevelOne',
            iconImgUp: '/Images/Gigya/emoticon-orange.png',
            iconImgOver: '/Images/Gigya/emoticon-orange.png',
            tooltip: toolTipCopyGamesMovie + 'Level One',
            feedMessage: setReactionsFeedMessage(title, 'Level One'), //global.js
            headerText: 'You recommend this post'
        }
        , {
            text: 'Bonus Round',
            ID: 'Reactions_Rewards_Game_BonusRound',
            iconImgUp: '/Images/Gigya/emoticon-red.png',
            iconImgOver: '/Images/Gigya/emoticon-red.png',
            tooltip: toolTipCopyGamesMovie + 'Bonus Round',
            feedMessage: setReactionsFeedMessage(title, 'Bonus Round'),
            headerText: 'You recommend this post'
        }
        , {
            text: 'High Score',
            ID: 'Reactions_Rewards_Game_HighScore',
            iconImgUp: '/Images/Gigya/emoticon-green.png',
            iconImgOver: '/Images/Gigya/emoticon-green.png',
            tooltip: toolTipCopyGamesMovie + 'High Score',
            feedMessage: setReactionsFeedMessage(title, 'High Score'),
            headerText: 'You recommend this post'
        }
        ];
    }
    else if (rewardType == "movies") {
        textReactions = [
        {
            text: 'Movie Night',
            ID: 'Reactions_Rewards_Movie_MovieNight',
            iconImgUp: '/Images/Gigya/emoticon-orange.png',
            iconImgOver: '/Images/Gigya/emoticon-orange.png',
            tooltip: toolTipCopyGamesMovie + 'Movie Night',
            feedMessage: setReactionsFeedMessage(title, 'Movie Night'),
            headerText: 'You recommend this post'
        }
        , {
            text: 'Must See',
            ID: 'Reactions_Rewards_Movie_MustSee',
            iconImgUp: '/Images/Gigya/emoticon-red.png',
            iconImgOver: '/Images/Gigya/emoticon-red.png',
            tooltip: toolTipCopyGamesMovie + 'Must See',
            feedMessage: setReactionsFeedMessage(title, 'Must See'),
            headerText: 'You recommend this post'
        }
        , {
            text: 'Mega Blockbuster',
            ID: 'Reactions_Rewards_Movie_SummerBlockbuster',
            iconImgUp: '/Images/Gigya/emoticon-green.png',
            iconImgOver: '/Images/Gigya/emoticon-green.png',
            tooltip: toolTipCopyGamesMovie + 'Mega Blockbuster',
            feedMessage: setReactionsFeedMessage(title, 'Mega Blockbuster'),
            headerText: 'You recommend this post'
        }
        ];
    }
    else if (rewardType == "music") {
        var toolTipCopyMusic = 'I say ';

        textReactions = [
        {
            text: 'Turn It On',
            ID: 'Reactions_Rewards_Music_TurnItOn',
            iconImgUp: '/Images/Gigya/emoticon-orange.png',
            iconImgOver: '/Images/Gigya/emoticon-orange.png',
            tooltip: toolTipCopyMusic + 'Turn It On',
            feedMessage: setReactionsFeedMessage(title, 'Turn It On'),
            headerText: 'You recommend this post'
        }
        , {
            text: 'Turn It Up',
            ID: 'Reactions_Rewards_Music_TurnItUp',
            iconImgUp: '/Images/Gigya/emoticon-red.png',
            iconImgOver: '/Images/Gigya/emoticon-red.png',
            tooltip: toolTipCopyMusic + 'Turn It Up',
            feedMessage: setReactionsFeedMessage(title, 'Turn It Up'),
            headerText: 'You recommend this post'
        }
        , {
            text: 'Double Platinum',
            ID: 'Reactions_Rewards_Music_DoublePlatinum',
            iconImgUp: '/Images/Gigya/emoticon-green.png',
            iconImgOver: '/Images/Gigya/emoticon-green.png',
            tooltip: toolTipCopyMusic + 'Double Platinum',
            feedMessage: setReactionsFeedMessage(title, 'Double Platinum'),
            headerText: 'You recommend this post'
        }
        ];
    }
    else if (rewardType == "slurpee") {
        var toolTipCopySlurpee = 'This item is ';

        textReactions = [
        {
            text: 'Cool',
            ID: 'Reactions_Rewards_Slurpee_Cool',
            iconImgUp: '/Images/Gigya/emoticon-orange.png',
            iconImgOver: '/Images/Gigya/emoticon-orange.png',
            tooltip: toolTipCopySlurpee + 'Cool',
            feedMessage: setReactionsFeedMessage(title, 'Cool'),
            headerText: 'You recommend this post'
        }
        , {
            text: 'Cooler',
            ID: 'Reactions_Rewards_Slurpee_Cooler',
            iconImgUp: '/Images/Gigya/emoticon-red.png',
            iconImgOver: '/Images/Gigya/emoticon-red.png',
            tooltip: toolTipCopySlurpee + 'Cooler',
            feedMessage: setReactionsFeedMessage(title, 'Cooler'),
            headerText: 'You recommend this post'
        }
        , {
            text: '28 Degrees',
            ID: 'Reactions_Rewards_Slurpee_28Degrees',
            iconImgUp: '/Images/Gigya/emoticon-green.png',
            iconImgOver: '/Images/Gigya/emoticon-green.png',
            tooltip: toolTipCopySlurpee + '28 Degrees',
            feedMessage: setReactionsFeedMessage(title, '28 Degrees'),
            headerText: 'You recommend this post'
        }
        ];
    }
    else {
        var toolTipCopyMisc = 'I say ';

        textReactions = [
        {
            text: 'This Will Work',
            ID: 'Reactions_Rewards_ThisWillWork',
            iconImgUp: '/Images/Gigya/emoticon-orange.png',
            iconImgOver: '/Images/Gigya/emoticon-orange.png',
            tooltip: toolTipCopyMisc + 'This Will Work',
            feedMessage: setReactionsFeedMessage(title, 'This Will Work'),
            headerText: 'You recommend this post'
        }
        , {
            text: 'Now We\'re Talking',
            ID: 'Reactions_Rewards_NowWeAreTalking',
            iconImgUp: '/Images/Gigya/emoticon-red.png',
            iconImgOver: '/Images/Gigya/emoticon-red.png',
            tooltip: toolTipCopyMisc + setReactionsFeedMessage(title, 'Now We\'re Talking'),
            feedMessage: 'Now We\'re Talking'
        }
        , {
            text: 'Awesomesauce',
            ID: 'Reactions_Rewards_Awesomesauce',
            iconImgUp: '/Images/Gigya/emoticon-green.png',
            iconImgOver: '/Images/Gigya/emoticon-green.png',
            tooltip: toolTipCopyMisc + 'Awesomesauce',
            feedMessage: setReactionsFeedMessage(title, 'Awesomesauce'),
            headerText: 'You recommend this post'
        }
        ];
    }

    //set global user nickname
    gigya.services.socialize.getUserInfo(conf, { callback: getUserInfoResponse });

    sCurrentItemName = title;
    sCurrentUrlLinkBack = urlLinkback;

    //var emptyUserAction = new gigya.services.socialize.UserAction();
    //emptyUserAction.setTitle('Reaction Click Test');

    //FB Default User Action
    fbUserAction = new gigya.services.socialize.UserAction(); //global
    //fbUserAction.setTitle(fbTitle); //leave null b/c set in feed message
    //fbUserAction.setLinkBack(sCurrentUrlLinkBack);

    var image = {
        type: 'image',
        src: sCurrentItemImagePath,
        href: sCurrentUrlLinkBack
    }

    fbUserAction = setUserAction('', '', sCurrentUrlLinkBack, '', image, sCurrentUrlLinkBack);

    // Step 3: Define the Reactions Plugin's params object
    var reactionParams = {
        barID: barId, //  Identifier of the content to which this reaction refers          
        containerID: 'gigyaReactions-rewards',  // Reactions Plugin DIV Container   
        reactions: textReactions,  // The reaction array from Step 1 
        userAction: fbUserAction,
        bodyText: 'Share it with your friends:', // optional - text that appears in the Share popup  
        showCounts: 'right', // optional - displays the counters on top of the buttons  
        cid: contextId,
        multipleReactions: false,
        onReactionClicked: reactionClickResponse,
        scope: 'external',
        privacy: 'public'
    };

    // Step 4: Load the Reactions Plugin:   
    gigya.services.socialize.showReactionsBarUI(conf, reactionParams);
}

function reactionClickResponse(response) {
    sCurrentReactionClicked = response.reaction.text;

    //Activity Feed Default User Action
    var afUserAction = new gigya.services.socialize.UserAction();
    var afTitle = 'Just rated ' + sCurrentItemName + ' as ' + response.reaction.text;
    afUserAction.setTitle(afTitle);
    afUserAction.setLinkBack(sCurrentUrlLinkBack);

    var afParams = {
        userAction: afUserAction,
        scope: 'internal',
        privacy: 'public'
    }

    gigya.services.socialize.publishUserAction(conf, afParams);
}
