﻿/**
* ASC COMMON SCRIPT FILE
*/

getFloPlayerKey = function (loc) {
    if (loc.indexOf('4u2review.net') != -1){
        return '#@fb15558012fe0a119ea';
    }
    if (loc.indexOf('americansnuffco.com') != -1){
        return '#@039c6f0aadf85ea41a2';
    }
    if (loc.indexOf('americansnuffcompany.com') != -1) {
        return '#@f835179573a3b759456';
    }
}

resroot = location.protocol + '//' + location.host + '/';
var intTimer = 0;
var timerID;
var timeoutID;
var isHovering = false;
var runFour = 0;
var lastState = '';
var runThis = ''
var showClose = true;
var showBack = false;

/**
* Add a script to the page.  This needs to be called within a script block in the HEAD element.
* @param {String} _sSRC Location of script. '{G}' is replace with global root path + 'script/'
*/
addScript = function(_sSRC) {
    _sSRC = _sSRC.replace('{G}', resroot + 'js/');
    document.write('<script type="text/javascript" src="' + _sSRC + '"></' + 'script>');
}

/**
* Add a script to the page.  This needs to be called within a script block in the HEAD element.
* @param {String} _sHREF Location of stylesheet. '{G}' is replace with global root path + 'css/'
*/
addCSS = function(_sHREF) {
    _sHREF = _sHREF.replace('{G}', resroot + 'css/');
    document.write('<link rel="stylesheet" type="text/css" href="' + _sHREF + '"/>');
}

$(window).scroll(function() {
    if ($.browser.msie == true) {
        $('#sb-overlay').attr('style', 'height:' + $(window).height() + 'px !important;background-color: rgb(233, 233, 233); filter: alpha(opacity=80);');
    }
    else {
        $('#sb-overlay').attr('style', 'height:' + $(window).height() + 'px !important;background-color: rgb(233, 233, 233); opacity: 0.8;');
    }
});

goBack = function () {
    $.History.go(lastState);
}

bindMainHandler = function () {
    $.History.bind(function (state) {
        eval("self.frames['sb-player']." + runThis);
    });
}

bindHistoryState = function (ref, func) {
    $.History.bind(ref, function (state) {
        var t = false;
    });
    lastState = ref;
    runThis = func;
};

try {
    Shadowbox.init({
        viewportPadding: 0,
        overlayOpacity: .8,
        overlayColor: '#e9e9e9',
        animate: false,
        animateFade: false,
        displayNav: true
    });
} catch (err) { };

function disableSelection(target) {
    if (typeof target.onselectstart != "undefined") //IE
        target.onselectstart = function() { return false }
    else if (typeof target.style.MozUserSelect != "undefined") //FF
        target.style.MozUserSelect = "none"
    else
        target.onmousedown = function() { return false }
    target.style.cursor = "default"
}

function setCookie(name, value) {
    var days = 1;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
    //alert(value);
}

function getCookie(name) {
    name = 'ASC';
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return Number(c.substring(nameEQ.length, c.length));
    }
    return null;
}


function hidePreloader() {
    $('.ajaxLoader').fadeOut();
    $('.btnContinue').fadeIn();
}

function flickrFixRosemary() {
    setTimeout("$('.flickrFix1').hide();$('.flickrFix2').hide();$('.flickrFix3').hide();", 400);
}

function checkPreloader() {
    if ($('.ajaxLoader').css('display') == 'block') {
        $('.ajaxLoader').fadeOut();
        $('.btnContinue').fadeIn();
    }
}

function calltoJS(val) {
    alert(val);
}

function scrollToTop() {
    setTimeout('$("html, body").scrollTop(0)', 0);
}

if (this.ASC == null) {
    this.ASC = {};
    this.ASC.Lounge = {};
};

NavFooter = function () {
    this.openTerms = function (_a) {
        Shadowbox.open({
            content: '/TermsConditions.aspx'+_a,
            player: 'iframe',
            height: 580,
            width: 845
        });
    }
    this.openPolicies = function () {
        Shadowbox.open({
            content: '/Policies.aspx',
            player: 'iframe',
            height: 580,
            width: 845
        });
    }
    this.openEEO = function () {
        showClose = false;
        Shadowbox.open({
            content: '/EEO.aspx',
            player: 'iframe',
            height: 515,
            width: 452
        });
    }
}
this.ASC.NavFooter = new NavFooter();

NavMain = function () {
    this.openContactUs = function () {
        Shadowbox.open({
            content: '/ContactUs.aspx',
            player: 'iframe',
            height: 580,
            width: 810
        });
    }
    this.openTradePartners = function () {
        showClose = false;
        Shadowbox.open({
            content: '/TradePartners.aspx',
            player: 'iframe',
            height: 580,
            width: 740
        });
    }
}
this.ASC.NavMain = new NavMain();

WaitingRoom = function () {
    this.openProducts = function () {
        $('.txt-popup-general').hide();
        Shadowbox.open({
            content: '/OurProducts.aspx',
            player: 'iframe',
            height: 588,
            width: 452
        });
    };
    this.openSupplier = function () {
        $('.txt-popup-general').hide();
        Shadowbox.open({
            content: 'WaitingRoom/Supplier.aspx',
            player: 'iframe',
            height: 551,
            width: 420
        });
    };
    this.openFacilities = function () {
        $('.txt-popup-general').hide();
        Shadowbox.open({
            content: 'WaitingRoom/Facilities.aspx',
            player: 'iframe',
            height: 551,
            width: 752
        });
    };
    this.openTracker = function () {
        $('.txt-popup-general').hide();
        Shadowbox.open({
            content: 'WaitingRoom/Performance.aspx',
            player: 'iframe',
            height: 551,
            width: 753
        });
    };
    this.openVisions = function () {
        $('.txt-popup-general').hide();
        Shadowbox.open({
            content: 'WaitingRoom/VisionAndValues.aspx',
            player: 'iframe',
            height: 551,
            width: 403
        });
    };
    this.openCorporate = function () {
        $('.txt-popup-general').hide();
        showBack = false;
        Shadowbox.open({
            content: 'WaitingRoom/Corporate.aspx',
            player: 'iframe',
            height: 578,
            width: 271,
            options: {
                onClose: function () {
                    showBack = false;
                } 
            }
        });
    };

    this.runRotation = function (clearInt) {
        if (runFour == 4) { return; }
        if (!Shadowbox.isOpen() && !isHovering) {
            if (intTimer == 0) {
                $("#hvrSupplier").fadeIn();
                timeoutID = setTimeout('$("#hvrSupplier").fadeOut();', 350);
            }
            if (intTimer == 1) {
                $("#hvrFacilities").fadeIn();
                timeoutID = setTimeout('$("#hvrFacilities").fadeOut();', 350);
            }
            if (intTimer == 2) {
                $("#hvrTracker").fadeIn();
                timeoutID = setTimeout('$("#hvrTracker").fadeOut();', 350);
            }
            if (intTimer == 3) {
                $("#hvrVisions").fadeIn();
                timeoutID = setTimeout('$("#hvrVisions").fadeOut();', 350);
            }
            if (intTimer == 4) {
                $("#hvrCorporate").fadeIn();
                timeoutID = setTimeout('$("#hvrCorporate").fadeOut();', 350);
            }
        }
        if (clearInt == true) { clearInterval(timerID); }
        if (runFour < 4) {
            timerID = setInterval('ASC.WaitingRoom.runRotation(true)', 800);
        }
        if (intTimer < 4) { intTimer++; }
        else if (intTimer == 4) {
            runFour++;
            intTimer = 0;
        }
        else {
            intTimer = 0;
        }
    };

    this.rotateTo = function (el) {
        //clearTimeout(timeoutID);
        clearInterval(timerID);
        $(".hoverAreas > div").hide();
        $(el.id).show();
        $(".bub" + el.id.substring(4)).show();
        isHovering = true;
    }

    this.rotateReset = function (el) {
        if (typeof el != 'undefined') {
            $('#' + el.parentNode.id).hide();
            $(".bub" + el.parentNode.id.substring(3)).hide();
        }
        isHovering = false;
    }

    this.checkRotation = function () {
        $(".bubSupplier").hide();
        $(".bubFacilities").hide();
        $(".bubTracker").hide();
        $(".bubVisions").hide();
        clearInterval(timerID);
        if (!Shadowbox.isOpen() && !isHovering) {
            setTimeout('ASC.WaitingRoom.runRotation(false);', 700);
        }
        setTimeout('ASC.WaitingRoom.checkRotation();', 10000);
    }
}
this.ASC.WaitingRoom = new WaitingRoom();

Lounge = function() {
    this.openTestimonials = function() {
        Shadowbox.open({
            content: 'Lounge/Testimonials.aspx',
            player: 'iframe',
            height: 440,
            width: 870
        });
    };
    this.openMemphis = function() {
        Shadowbox.open({
            content: 'Lounge/WallPhotos.aspx?a=61',
            player: 'iframe',
            height: 575,
            width: 792
        });
    };
    this.openClarksville = function() {
        Shadowbox.open({
            content: 'Lounge/WallPhotos.aspx?a=60',
            player: 'iframe',
            height: 575,
            width: 792
        });
    };
    this.openWinston = function() {
        Shadowbox.open({
            content: 'Lounge/WallPhotos.aspx?a=62',
            player: 'iframe',
            height: 575,
            width: 792
        });
    };
    this.openScrapBook = function () {
        Shadowbox.open({
            content: 'Lounge/Scrapbook.aspx',
            player: 'iframe',
            height: 580,
            width: 845
        });
    };
    this.runRotation = function(clearInt) {
        if (runFour == 4) { return; }
        if (!Shadowbox.isOpen() && !isHovering) {
            if (intTimer == 0) {
                $("#hvrTestimonials").fadeIn();
                timeoutID = setTimeout('$("#hvrTestimonials").fadeOut();', 350);
            }
            if (intTimer == 1) {
                $("#hvrMemphisTN").fadeIn();
                timeoutID = setTimeout('$("#hvrMemphisTN").fadeOut();', 350);
            }
            if (intTimer == 2) {
                $("#hvrClarksvilleTN").fadeIn();
                timeoutID = setTimeout('$("#hvrClarksvilleTN").fadeOut();', 350);
            }
            if (intTimer == 3) {
                $("#hvrWinstonSalemNC").fadeIn();
                timeoutID = setTimeout('$("#hvrWinstonSalemNC").fadeOut();', 350);
            }
            if (intTimer == 4) {
                $("#hvrScrapBook").fadeIn();
                timeoutID = setTimeout('$("#hvrScrapBook").fadeOut();', 350);
            }
        }
        if (clearInt == true) { clearInterval(timerID); }
        if (runFour < 4) {
            timerID = setInterval('ASC.Lounge.runRotation(true)', 800);
        }
        if (intTimer < 4) { intTimer++; }
        else if (intTimer == 4) {
            runFour++;
            intTimer = 0;
        }
        else {
            intTimer = 0;
        }
    };

    this.rotateTo = function(el) {
        //clearTimeout(timeoutID);
        clearInterval(timerID);
        $("#hoverAreas > div").hide();
        $(el.id).show();
        $(".bub" + el.id.substring(4)).show();
        isHovering = true;
    }

    this.rotateReset = function(el) {
        if (typeof el != 'undefined') {
            $('#' + el.parentNode.id).hide();
            $(".bub" + el.parentNode.id.substring(3)).hide();
        }
        isHovering = false;
    }    
    
}
this.ASC.Lounge = new Lounge();



Reception = function() {

this.openProducts = function() {
    $('.txt-popup-general').hide();
        Shadowbox.open({
            content: '/OurProducts.aspx',
            player: 'iframe',
            height: 577,
            width: 702
        });
    };
    this.openNews = function () {
        Shadowbox.open({
            content: '/Homepage/News.aspx',
            player: 'iframe',
            height: 595,
            width: 710
        });
    }
    this.openCareers = function () {
        $('.txt-popup-general').hide();
        Shadowbox.open({
            content: 'Homepage/Careers.aspx',
            player: 'iframe',
            height: 580,
            width: 420
        });
    };
    this.openTour = function () {
        Shadowbox.open({
            content: '/Homepage/FieldTour.aspx',
            player: 'iframe',
            height: 500,
            width: 870
        });
    }    
    this.runRotation = function(clearInt) {
        if (runFour == 4) { return; }
        if (!Shadowbox.isOpen() && !isHovering) {
            if (intTimer == 0) {
                $("#hvrAbout").fadeIn();
                timeoutID = setTimeout('$("#hvrAbout").fadeOut();', 350);
            }
            if (intTimer == 1) {
                $("#hvrHistory").fadeIn();
                timeoutID = setTimeout('$("#hvrHistory").fadeOut();', 350);
            }
            if (intTimer == 2) {
                $("#hvrPeople").fadeIn();
                timeoutID = setTimeout('$("#hvrPeople").fadeOut();', 350);
            }
            if (intTimer == 3) {
                $("#hvrProducts").fadeIn();
                timeoutID = setTimeout('$("#hvrProducts").fadeOut();', 350);
            }
            if (intTimer == 4) {
                $("#hvrTrade").fadeIn();
                timeoutID = setTimeout('$("#hvrTrade").fadeOut();', 350);
            }
            if (intTimer == 5) {
                $("#hvrContact").fadeIn();
                timeoutID = setTimeout('$("#hvrContact").fadeOut();', 350);
            }
            if (intTimer == 6) {
                $("#hvrCareers").fadeIn();
                timeoutID = setTimeout('$("#hvrCareers").fadeOut();', 350);
            }
            if (intTimer == 7) {
                $("#hvrNews").fadeIn();
                timeoutID = setTimeout('$("#hvrNews").fadeOut();', 350);
            }
            if (intTimer == 8) {
                $("#hvrTour").fadeIn();
                timeoutID = setTimeout('$("#hvrTour").fadeOut();', 350);
            }
        }
        if (clearInt == true) { clearInterval(timerID); }
        if (runFour < 4) {
            timerID = setInterval('ASC.Reception.runRotation(true)', 800);
        }
        if (intTimer < 8) { intTimer++; }
        else if (intTimer == 8) {
            runFour++;
            intTimer = 0;
        }
        else {
            intTimer = 0;
        }
    };

    this.rotateTo = function(el) {
        //clearTimeout(timeoutID);
        clearInterval(timerID);
        $("#hoverAreas > div").hide();
        $(el.id).show();
        $(".bub" + el.id.substring(4)).show();
        isHovering = true;
    }

    this.rotateReset = function(el) {
        if (typeof el != 'undefined') {
            $('#' + el.parentNode.id).hide();
            $(".bub" + el.parentNode.id.substring(3)).hide();
        }
        isHovering = false;
    }
}
this.ASC.Reception = new Reception();


History = function () {
    this.openCopy = function (id) {
        $('.txt-popup-inner-history')[0].innerHTML = $('.' + id.className)[0].innerHTML;
        $('.txt-popup-history').css('visibility', 'visible');
        $('#sb-overlay-alt').remove();
        if ($.browser.msie) {
            $('body').append('<div id="sb-overlay-alt" onclick="closePopup();" style="z-index:3;width:100%;height:100%;position:absolute;left:0px;top:0px;background-color: rgb(233, 233, 233); filter: alpha(opacity=80);"></div>');
        }
        else {
            $('body').append('<div id="sb-overlay-alt" onclick="closePopup();" style="z-index:3;width:100%;height:100%;position:absolute;left:0px;top:0px;background-color: rgb(233, 233, 233); opacity: 0.8;"></div>');
        }
    }
    this.openTimeline = function () {
        Shadowbox.open({
            content: '<div class="historySplash"><img src="images/history/bg_history_splashscreen.jpg" onclick="window.location = \'/Timeline.aspx\';" title="Click To View Our History Timeline"/></div>',
            player: 'html',
            height: 577,
            width: 700
        });
        $('.btnTimeline').fadeIn();
    }
    this.runRotation = function (clearInt) {
        if (runFour == 4) {
            //$(".museum_left_case_mask").remove();
            $('.museum_left_case')[0].src = resroot + 'images/history/spacer.gif';
            $('.museum_right_case')[0].src = resroot + 'images/history/spacer.gif';
            clearTimeout(timeoutID);
            return;
        }
        if (!Shadowbox.isOpen() && !isHovering) {
            //$(".museum_left_case_mask").fadeOut();
            $('.museum_left_case')[0].src = resroot + 'images/history/spacer.gif';
            $('.museum_right_case')[0].src = resroot + 'images/history/spacer.gif';
            if (intTimer == 0) {
                $("#hvrTimeline").toggleClass("hoverTimeline");
                setTimeout('$("#hvrTimeline").toggleClass("hoverTimeline");', 700);
            }
            if (intTimer == 1) {
                $("#hvrTobacco").toggleClass("hoverTobacco");
                setTimeout('$("#hvrTobacco").toggleClass("hoverTobacco");', 700);
            }
            if (intTimer == 2) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_garrett_painting_ovr.jpg';
            }
            if (intTimer == 3) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_garrett_gal_poster_ovr.jpg';
            }
            if (intTimer == 4) {
                $('.museum_right_case')[0].src = resroot + 'images/history/btn_history_tin_tags_ovr.jpg';
            }
            //if (intTimer == 5) {
            //    $('.museum_right_case')[0].src = resroot + 'images/history/btn_history_bull_sign_ovr.jpg';
            //}
            if (intTimer == 5) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_beef_bladder_ovr.jpg';
            }
            if (intTimer == 6) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_cabin_tins_ovr.jpg';
            }
            if (intTimer == 7) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_price_book_ovr.jpg';
            }
            if (intTimer == 8) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_thermometer_ovr.jpg';
            }
            if (intTimer == 9) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_dental_snuff_ovr.jpg';
            }
            if (intTimer == 10) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_pocket_canister_ovr.jpg';
            }
            if (intTimer == 11) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_snuff_can_ovr.jpg';
            }
            if (intTimer == 12) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_paper_fan_ovr.jpg';
            }
            if (intTimer == 13) {
                $('.museum_left_case')[0].src = resroot + 'images/history/btn_history_patents_ovr.jpg';
            }
            if (intTimer == 14) {
                $('.museum_right_case')[0].src = resroot + 'images/history/btn_history_cutter_ovr.jpg';
            }
            if (intTimer == 15) {
                $('.museum_right_case')[0].src = resroot + 'images/history/btn_history_tobacco_twist_ovr.jpg';
            }
            if (intTimer == 16) {
                $('.museum_right_case')[0].src = resroot + 'images/history/btn_history_hook_ovr.jpg';
            }
            if (intTimer == 17) {
                $('.museum_right_case')[0].src = resroot + 'images/history/btn_history_truck_ovr.jpg';
            }
            if (intTimer == 18) {
                $('.museum_right_case')[0].src = resroot + 'images/history/btn_history_cannon_ball_ovr.jpg';
            }
            //$(".museum_left_case_mask").fadeIn();
        }
        if (clearInt == true) { clearInterval(timerID); }
        if (runFour < 4) {
            timerID = setInterval('ASC.History.runRotation(true)', 700);
        }
        if (intTimer < 18) { intTimer++; }
        else if (intTimer == 18) {
            runFour++;
            intTimer = 0;
        }
        else {
            intTimer = 0;
        }
    };

    this.rotateTo = function (el) {
        clearTimeout(timeoutID);
        clearInterval(timerID);
        $('.museum_left_case')[0].src = resroot + 'images/history/spacer.gif';
        $('.museum_right_case')[0].src = resroot + 'images/history/spacer.gif';
        if (el != 'null') {
            $('.' + el.parentNode.id)[0].src = resroot + 'images/history/' + el.id;
        }
        isHovering = true;
    }

    this.rotateReset = function (el) {
        if (typeof el != 'undefined') {
            $('.' + el.parentNode.id)[0].src = resroot + 'images/history/spacer.gif';
        }
        isHovering = false;
    }
}
this.ASC.History = new History();

var aHeadLine = new Object();
var aSubHeadLine = new Object();
var aDateLine = new Object();
var aGenre = new Object();
var aProperty = new Object();
var xmlID = 0;

News = function () {
    this.initLoadXML = function () {
        $.ajax({
            type: "GET",
            url: "ASC.xml",
            dataType: "xml",
            success: function (xml) {
                xmlID = 0;
                $(xml).find('NewsComponent').each(function () {
                    aHeadLine[xmlID] = $(this).find('HeadLine').text();
                    aSubHeadLine[xmlID] = $(this).find('SubHeadLine').text();
                    aDateLine[xmlID] = $(this).find('DateLine').text();
                    xmlID++;
                });
                xmlID = 0;
                $(xml).find('DescriptiveMetaData').each(function () {
                    aGenre[xmlID] = $(this).find('Genre')[0].attributes[0].nodeValue;
                    aProperty[xmlID] = $(this).find('Property')[0].attributes[1].nodeValue;
                    xmlID++;
                });
            }
        });
    };
}
this.ASC.News = new News();












