﻿var sCurrentPageBOTB;

sCurrentPage = 'navEvents';

function ImposeMaxLength(oThis, nMaxLength) {
    return (oThis.value.length <= nMaxLength);
}

function InitPromotionBOTBHome() {
    sCurrentPageBOTB = 'navBOTBHome';
    TogglePageNavBOTB(sCurrentPageBOTB, 'on');
    PopulateFacebookComments('fbcBOTBPost', true);

    jQuery('#facebookCommentsCount').click(function (event) {
        jQuery('#moduleFacebookComments').css('display', 'block');
        jQuery('#moduleFacebookComments').css('top', (GetScrollY() + 150));
    });

    jQuery('#closeComments').click(function (event) {
        jQuery('#moduleFacebookComments').css('display', 'none');
    });
    
    //PopulateTwitterFeed(2, 200, true);
    
    // Load the Flash Home - Not visible in this phase
    //if (FlashDetect.installed) {
    //    var flashvars = {};
    //    var params = { bgcolor: "#ffffff", scale: "noscale", salign: "t", wmode: "transparent" };
    //    var attributes = { id: "flashBOTB" };
    //    swfobject.embedSWF("/Media/BOTB_intro_video.swf", "moduleFlashBOTB", "566", "256", "9", "", flashvars, params, attributes);
    //}
    //else {
    //    jQuery('#moduleFlashBOTB').html('<a href="http://www.adobe.com/go/EN_US-H-GET-FLASH" target="_blank"><img src="/Images/get_adobe_flash_player.png" alt="Get Adobe Flash Player" /></a>');
    //}
}

function InitPromotionBOTBEvents() {
    sCurrentPageBOTB = 'navBOTBEvents';
    TogglePageNavBOTB(sCurrentPageBOTB, 'on');

    if (jQuery('#BOTBEvents').length > 0) {
        jQuery('#BOTBEvents .accordianHeader').bind('click', function(event) {
            var id = jQuery(this).parents('.accordianPanel').attr('id');
            var n = parseInt(id.replace('accordianPanel', ''));

            jQuery('#BOTBEvents .accordianPanel.open').animate({ 'height': '36px' }, function() {
                jQuery(this).removeClass('open').addClass('closed');
                jQuery('#BOTBEvents #accordianPanel' + n).css('height', '36px').addClass('open').removeClass('closed').animate({ 'height': '169px' }, function() {
                    // No functionality needed at this point.
                });
            });
        });
    }
}

function InitPromotionBOTBEventDetails() {
    sCurrentPageBOTB = 'navBOTBEvents';
    TogglePageNavBOTB(sCurrentPageBOTB, 'on');
}

function InitPromotionBOTBBands() {
    sCurrentPageBOTB = 'navBOTBBands';
    TogglePageNavBOTB(sCurrentPageBOTB, 'on');
}

function InitPromotionBOTBBandDetails() {
    sCurrentPageBOTB = 'navBOTBBands';
    TogglePageNavBOTB(sCurrentPageBOTB, 'on');

    if (jQuery('.videoList').html().length == 0) {
        jQuery('.videoList').css('display', 'none');
    }

    PopulateFacebookComments('commentsBand' + jQuery.query.get('nBandID'), true);
    LoadCommentsFBML('commentsBand' + jQuery.query.get('nBandID'));

    jQuery('#facebookShareBand').click(function(event) {
        ShareFacebook('Bust out the leather pants. It\'s time for an encore.', 'Slurpee Battle of the Bands 2010', 'http://www.slurpee.com', 'http://www.slurpee.com/Images/Promotions/BOTB_2010/sharePoster.jpg', 'Battle of the Bands 2010 has launched. And this year\'s program is going to rock harder than ever before. There\'ll be concerts, music videos and more voting than all of Europe combined.');
    });
}

function InitPromotionBOTBHowTo() {
    sCurrentPageBOTB = 'navBOTBHowTo';
    TogglePageNavBOTB(sCurrentPageBOTB, 'on');

    // Load the Flash How-To
    if (FlashDetect.installed) {
        var flashvars = { };
        var params = { bgcolor: "#ffffff", scale: "noscale", salign: "t", wmode: "transparent" };
        var attributes = { id: "flashBOTB" };
        swfobject.embedSWF("/Media/BOTB_how_it_works.swf", "moduleFlashBOTB", "566", "409", "9", "", flashvars, params, attributes);
    }
    else {
        jQuery('#moduleFlashBOTB').html('<a href="http://www.adobe.com/go/EN_US-H-GET-FLASH" target="_blank"><img src="/Images/get_adobe_flash_player.png" alt="Get Adobe Flash Player" /></a>');
    }
}

function LoadFlashSong(sFileName, sFileNumber, sDiv) {
    // Load the Flash carousel
    if (FlashDetect.installed) {
        var flashvars = { fileName: sFileName };
        var params = { bgcolor: "#0094E2", scale: "scale", salign: "t", wmode: "transparent" };
        var attributes = { id: "flashSong" + sFileNumber };

        swfobject.embedSWF("/Media/FLVthumbLoader.swf", sDiv, "160", "120", "9", "", flashvars, params, attributes);
    }
    else {
        jQuery('#' + sDiv).html('<a href="http://www.adobe.com/go/EN_US-H-GET-FLASH" target="_blank"><img src="/Images/get_adobe_flash_player.png" alt="Get Adobe Flash Player" /></a>');
    }
}

function InitPromotionBOTBLogin() {
    sCurrentPageBOTB = 'navBOTBEnter';
    TogglePageNavBOTB(sCurrentPageBOTB, 'on');

    jQuery('#modalBOTBEventTip').click(function(event) {
        jQuery('#containerModalBOTBEventTip').css('display', 'block');
    });

    jQuery('#containerModalBOTBEventTip').click(function(event) {
        jQuery(this).css('display', 'none');
    });
}

function InitPromotionBOTBFans() {
    sCurrentPageBOTB = 'navBOTBFans';
    TogglePageNavBOTB(sCurrentPageBOTB, 'on');
}

function InitPromotionBOTB() {
    var sXID = 'fbcBOTB_2010';
    
    // Turn the current page nav on
    TogglePageNavBOTB(sCurrentPageBOTB, 'on');

    // Set the rollovers for the nav images
    jQuery('#navigationBOTB img').hover(function() {
        if (this.id.length > 0) TogglePageNavBOTB(this.id, 'on');
    }, function() {
        if (this.id.length > 0) TogglePageNavBOTB(this.id, 'off');
    });

    jQuery('#facebookShare').click(function(event) {
        ShareFacebook('Bust out the leather pants. It\'s time for an encore.', 'Slurpee Battle of the Bands 2010', 'http://www.slurpee.com/events/promotions/botb_2010', 'http://www.slurpee.com/Images/Promotions/BOTB_2010/sharePoster.jpg', 'Battle of the Bands 2010 has launched. And this year\'s program is going to rock harder than ever before. There\'ll be concerts, music videos and more voting than all of Europe combined.');
    });

    jQuery('#facebookShareBOTBHome').click(function (event) {
        ShareFacebook('Behind the Scenes of the Music Video Shoots', 'Slurpee Battle of the Bands 2010', 'http://www.slurpee.com/events/promotions/botb_2010', 'http://www.slurpee.com/Images/Promotions/BOTB_2010/sharePoster.jpg', 'You have seen the music videos. Now see how they were made. Oh yeah, we filmed the film teams. That is called a dose of your own medicine. But like all Slurpee stuff, it tastes darn good.');
    });
    
    jQuery('#linkFullLegal').click(function(event) {
        jQuery('#moduleLegalFull').css('display', 'block');
        jQuery('#moduleLegalFull').css('top', (GetScrollY() + 150));
    });

    jQuery('#closeLegalFull').click(function(event) {
        jQuery('#moduleLegalFull').css('display', 'none');
    });

    jQuery('.BOTBModal .modalHeader').click(function (event) {
        jQuery('#containerFlashBOTBSong').html('<div id="moduleFlashBOTBSong"></div>');
        jQuery('.BOTBModal').css('display', 'none');
    });
}

function PopulateAndShowModal(sModalHeader, sModalSubHeader, sModalCopy, sFileName, bLoadVideo, bSixToFour) {
    jQuery('#modalGeneral.BOTBModal .copy.header').html(sModalHeader);
    jQuery('#modalGeneral.BOTBModal .copy.subHeader').html(sModalSubHeader);
    jQuery('#modalGeneral.BOTBModal .copy.body').html(sModalCopy);
    jQuery('#modalGeneral.BOTBModal').css('display', 'block');
    jQuery('#modalGeneral.BOTBModal').css('top', (GetScrollY() + 150));

    if (bLoadVideo) {
        if (sFileName.length > 0) {
            if (FlashDetect.installed) {
                var flashvars = { fileName: "BOTB_2010/" + sFileName };
                var params = { bgcolor: "#0094E2", scale: "scale", salign: "t", wmode: "transparent", allowfullscreen: "true" };
                var attributes = { id: "flashSong" };

                // The video doesn't refresh unless we reset the Flash container
                jQuery('#containerFlashBOTBSong').html('<div id="moduleFlashBOTBSong"></div>');
                if (bSixToFour) {
                    swfobject.embedSWF("/Media/BOTB_2010/final_six/" + sFileName, "moduleFlashBOTBSong", "380", "260", "9", "", flashvars, params, attributes);
                }
                else {
                    if (sFileName == 'BOTB_song7_10.f4v') {
                        swfobject.embedSWF("/Media/BOTB_2010/hollerbacks_hometown_videos.swf", "moduleFlashBOTBSong", "380", "260", "9", "", flashvars, params, attributes);
                    }
                    else if (sFileName == 'BOTB_song11_10.f4v') {
                        swfobject.embedSWF("/Media/BOTB_2010/leviware_hometown_videos.swf", "moduleFlashBOTBSong", "380", "260", "9", "", flashvars, params, attributes);
                    }
                    else {
                        swfobject.embedSWF("/Media/BOTB_video.swf", "moduleFlashBOTBSong", "380", "260", "9", "", flashvars, params, attributes);
                    }
                }
            }
            else {
                jQuery('#' + sDiv).html('<a href="http://www.adobe.com/go/EN_US-H-GET-FLASH" target="_blank"><img src="/Images/get_adobe_flash_player.png" alt="Get Adobe Flash Player" /></a>');
            }
            jQuery('#containerFlashBOTBSong').css('display', 'block');
            jQuery('#modalGeneral.BOTBModal .shareFacebook').html('<a href="Javascript:ShareFacebook(\'' + sModalHeader + '\', \'<br />' + sModalHeader + ' is rocking in Slurpee Battle of the Bands 2010\', \'http://www.slurpee.com/events/promotions/botb_2010\', \'http://www.slurpee.com/images/promotions/botb_2010/sharePoster.jpg\', \'Check out their ' + sModalCopy + ' performance\');"><img src="/Images/Promotions/BOTB_2010/facebookShareBandSong.png" alt="Share This Video" /></a>');
        }
        else {
            jQuery('#containerFlashBOTBSong').css('display', 'none');
        }
    }
    else {
        jQuery('#containerFlashBOTBSong').css('display', 'none');
    }
}

function ShowSaveModal() {
    jQuery('#modalSave.BOTBModal').css('display', 'block');
    jQuery('#modalSave.BOTBModal').css('top', (GetScrollY() + 150));
}

function TogglePageNavBOTB(sPage, sState) {
    // Never turn the current page nav off
    if ((sPage != sCurrentPageBOTB) || (sState == "on")) {
        jQuery('#' + sPage).attr('src', '/Images/Promotions/BOTB_2010/' + sPage + '_' + sState + '.png');
    }
}
