
/* Before domReady Event */
conoco.initGlobalCufon();


/* domReady Event */
conoco.readyEvent = function() {

    // find section
    conoco.section = conoco.findSection();

    // rewrite mobile links
    if (conoco.isMobile()) {
        conoco.addMobileLinks();
    }

    // reduce object depth for performance
    var config = conoco.config;
    var animation = config.animation;
    var section = conoco.section
    var track = conoco.track;

    /*******************************
    Event Handlers
    *******************************/
    conoco.handler = {
        header: {
            mouseenter: function() {
                var $scaleIcon = $(this).find('.scale');
                $scaleIcon
					.protectAnimation()
					.show()
					.animate({ scale: 1 }, animation.quicker)
				;
            },
            mouseleave: function() {
                var $scaleIcon = $(this).find('.scale');
                $scaleIcon
					.protectAnimation()
					.animate({ scale: animation.scale.header }, animation.quicker, function() { $scaleIcon.hide(); })
				;
            },
            register: {
                mouseenter: function() {
                    $(this).find('.hover')
						.protectAnimation()
						.fadeIn(animation.quick)
					;
                },
                mouseleave: function() {
                    $(this).find('.hover')
						.fadeOut(animation.quick)
					;
                },
                keypress: function(event) {
                    if (event.which == 13) {
                        event.preventDefault();
                        event.stopPropagation();
                        $(this).find('.submit').click();
                    }
                },
                click: function(event) {
                    var $content = $(this).find('.content');
                    if (!$(this).find('.content').hasClass('open')) {
                        track.trackEvent('register', 'open');
                        $content
							.addClass('open')
							.protectAnimation()
							.slideDown(animation.medium)
						;
                    }
                    else {
                        track.trackEvent('register', 'close');
                        $content
							.removeClass('open')
							.protectAnimation()
							.slideUp(animation.medium)
						;
                        $content.find('input').each(function() { $(this).val(''); $(this).blur(); });
                        $content.find('.errors').remove();
                        $content.find('input').removeClass('warn');
                        $content.find('.middle').css('height', config.register.height.normal);
                        $content.find('.thanks').hide();
                        $content.find('.signup').show();
                    }
                    return false;
                },
                form: {
                    success: function() {
                        // cache
                        var $content = $('#links-register .content .middle');
                        var $errors = $content.find('.errors');
                        var $submit = $content.find('.submit');
                        var loadMin = 750;
                        // show loader, disable hammer click
                        if (!$submit.hasClass('disabled')) {
                            $submit.addClass('disabled');
                            $('<div />')
								.addClass('progress')
								.appendTo($content)
							;
                            $submit.hide();
                            // clear errors 
                            $errors.remove();
                            // post ajax
                            var serializedData = $('#links-register form').serialize();
                            var startTime = new Date().getTime();
                            // nab form and serialize
                            $.ajax({
                                type: 'POST',
                                url: config.register.url,
                                data: serializedData,
                                complete: function() {
                                    var elapsed = new Date().getTime() - startTime;
                                    var delay = 0;
                                    // show for at least 1500 ms
                                    if (elapsed < loadMin) {
                                        delay = loadMin - elapsed;
                                    }
                                    setTimeout(function() {
                                        $submit.removeClass('disabled');
                                        $submit.show();
                                        $content.find('.progress').hide();
                                    }, delay);
                                },
                                success: function(response) {
                                    try {
                                        if (typeof (response) == 'object' && response.errors == false) {
                                            track.trackEvent('register', 'success');
                                            var elapsed = new Date().getTime() - startTime;
                                            var delay = 0;
                                            // show for at least 1500 ms
                                            if (elapsed < loadMin) {
                                                delay = loadMin - elapsed;
                                            }
                                            setTimeout(function() {
                                                // hide signup form show thank you
                                                $content
													.find('.signup')
														.css('visibility', 'hidden')
														.end()
													.animate({ height: config.register.height.thankYou }, animation.medium, function() {
													    $content.find('.signup').css('visibility', 'visible').hide();
													    $content.find('.thanks').show();
													})
												;
                                            }, delay);
                                        }
                                    }
                                    catch (e) {
                                        track.trackEvent('register', 'error', 'blank-server-response');
                                    }
                                },
                                error: function() {
                                    track.trackEvent('register', 'error', 'no-server-response');
                                    // do something on error
                                },
                                dataType: 'json'
                            });
                        }
                        return false;
                    },
                    failure: function(errors) {
                        track.trackEvent('register', 'error', 'missing-fields');
                        var $content = $('#links-register .content .middle');
                        var $signup = $content.find('.signup');
                        var $errors = $content.find('.errors');
                        // generate errors
                        var errorList = '';
                        jQuery.each(errors, function(i, error) {
                            errorList += '<li>' + error + '</li>';
                        });
                        $content.animate({ height: config.register.height.errors }, animation.medium, function() {
                            // generate list on first error
                            if (!$errors.exists()) {
                                $('<ul/>')
									.attr('class', 'errors')
									.appendTo($signup)
								;
                            }
                            // Just add new errors
                            $content.find('.errors')
								.html(errorList)
								.show()
							;
                        });
                        return false;
                    }
                },
                close: {
                    click: function() {
                        $(this).parents('li').click();
                        return false;
                    }
                }
            }
        },
        navigation: {
            mousedown: function() {
                var $section = $(this);
                if (!$section.hasClass('active')) {
                    $section.siblings('.active').find('.active')
						.protectAnimation()
						.fadeOut(animation.quick)
					;
                    $section
						.bind('mouseleave.escape', function() {
						    $(this).trigger('mouseup');
						})
						.find('.down')
							.protectAnimation()
							.fadeIn(animation.quick)
					;
                }
            },
            mouseup: function() {
                var $section = $(this);
                if (!$section.hasClass('active')) {
                    // only reshow active section if nothing clicked
                    if (!conoco.clicked) {
                        $section.siblings('.active').find('.active').fadeIn(animation.quick);
                    }
                    $section
						.unbind('mouseleave.escape')
						.find('.down')
							.fadeOut(animation.quick);
                }
            },
            mouseenter: function() {
                if (!$(this).hasClass('down')) {
                    $(this).find('.hover').show();
                }
            },
            mouseleave: function() {
                $(this).find('.hover').fadeOut(animation.quick);
            },
            // click event does not occur properly because mousedown and mouseup event occur on different DOM elements
            // this event fixes this bug
            clickFix: function() {
                $(this).parent().click();
                // let mouseup event know not to show active section
                conoco.clicked = true;
            }
        },
        touts: {
            top: {
                mouseenter: function() {
                    var speed = animation.quick;
                    if ($.browser.msie) {
                        speed = 0;
                    }
                    var $tout = $(this);
                    var $boxHover = $tout.find('.box > .hover');
                    var $go = $tout.find('.go > .hover');
                    $boxHover
						.protectAnimation()
						.fadeIn(speed)
					;
                    $go
						.protectAnimation()
						.show()
						.animate({ scale: 1 }, speed)
					;
                },
                mouseleave: function() {
                    var speed = animation.quick;
                    if ($.browser.msie) {
                        speed = 0;
                    }
                    var $tout = $(this);
                    var $boxHover = $tout.find('.box > .hover');
                    var $go = $tout.find('.go > .hover');
                    $boxHover.fadeOut(speed);
                    $go
                        .protectAnimation()
                        .animate({ scale: animation.scale.touts }, speed, function() { $go.hide(); })
					;
                },
                mouseclick: function() {
                    var text = [];
                    //alert($(this).parents(".card").find(".info").find("h4").html());

                    $(this).find("h2").find("cufontext")
							.each(function() {
							    var newtext = $(this).html().replace("&reg;", "");
							    text.push(newtext);
							})
					;
                    var title = text.join('');
                    title = title.replace(" ", "_");
                    title = title.toLowerCase();
                    // from tracking.js
                    track.trackEvent('home', 'tout', title);
                }
            },
            bottom: {
                mouseenter: function() {
                    var speed = animation.quick;
                    if ($.browser.msie) {
                        speed = 0;
                    }
                    var $hoverIcon = $(this).find('.icon .hover');
                    $hoverIcon
						.protectAnimation()
						.fadeIn(speed);
                    ;
                },
                mouseleave: function() {
                    var speed = animation.quick;
                    if ($.browser.msie) {
                        speed = 0;
                    }
                    var $hoverIcon = $(this).find('.icon .hover');
                    $hoverIcon.fadeOut(speed);
                },
                mouseclick: function() {
                    var text = [];
                    //alert($(this).parents(".card").find(".info").find("h4").html());
                    $(this).find("h2").find("cufontext")
							.each(function() {
							    var newtext = $(this).html().replace("&reg;", "");
							    text.push(newtext);
							})
					;
                    var title = text.join('');
                    title = title.replace(" ", "_");
                    title = title.toLowerCase();
                    // from tracking.js
                    track.trackEvent('home', 'tout', title);
                }
            }
        },

        advertising: {
            categories: {
                click: function() {
                    var $category = $(this);
                    // category name child anchor tag minus anchor
                    var categoryName = $category.find('a').attr('href').replace('#', '.');
                    if (typeof (categoryName) != 'undefined') {
                        var $tabs = $('#gallery .tabs');
                        $category
							.addClass('active')
							.siblings()
								.removeClass('active')
						;
                        $tabs.find(categoryName)
							.show()
							.siblings()
								.hide()
						;
                        track.protectBounce = false;
                        track.trackEvent('advertising', 'gallery', categoryName);
                    }
                    return false;
                }
            },
            photos: {
                click: function() {
                    var spot = $(this).parent().children().index($(this));
                    track.protectBounce = false;
                    track.trackEvent('advertising', 'gallery', 'image-' + (spot + 1));
                }
            },
            videoSelector: {
                click: function() {
                    if (!$(this).hasClass('disabled')) {
                        var $video = $(this);
                        var $file = $video.find('.file');
                        // grab data
                        var filename = $file.html();
                        var title = $file.attr('title');
                        // set hash tag
                        $.address.value(title.replace(/ /g, '-') + '/');
                        if (filename != "#") {
                            try {
                                conoco.externalInterface('#video-swf').initPlayer(filename, title);
                            }
                            catch (e) {
                                // swf not ready
                            }
                            $(this)
								.addClass('active')
								.siblings()
									.removeClass('active')
							;
                        }
                    }
                    return false;
                }
            },
            videoPagination: {
                click: function() {
                    if (!$(this).hasClass("inactive")) {
                        var itemsPerPage = 6;
                        var totalItems = $("#video-list ul").children().size();
                        var totalPages = Math.ceil(totalItems / itemsPerPage);

                        var height = $("#video-mask").height();
                        var pos = $("#video-mask ul").css("margin-top").replace("px", "");
                        var page = Math.ceil(pos / height) * -1;

                        if ($(this).hasClass("next")) {
                            page = page + 1;
                        }
                        else if ($(this).hasClass("prev")) {
                            page = page - 1;
                        }
                        var $videoList = $("#video-list ul");
                        var destination = (height * page) * -1

                        if (!$videoList.hasClass('disabled')) {
                            $videoList
								.addClass('disabled')
								.animate({ marginTop: destination }, 500, function() {
								    $videoList.removeClass('disabled');
								    var $prevArrow = $("#video-list .inner-nav .prev");
								    var $nextArrow = $("#video-list .inner-nav .next");
								    if (page > 0) {
								        $prevArrow.removeClass("inactive");
								    }
								    else {
								        $prevArrow.addClass("inactive");
								    }
								    if ((page + 1) == totalPages) {
								        $nextArrow.addClass("inactive");
								    }
								    else {
								        $nextArrow.removeClass("inactive");
								    }
								})
							;
                        }


                        return false;
                    }
                }
            },
            gallery: {
                init: function() {
                    var $shadowbox = $('#sb-container');
                    if (!$shadowbox.hasClass('init')) {
                        var advertising = conoco.handler.advertising;
                        var $close = $('#sb-close');
                        var $leftArrow = $('#sb-nav-previous');
                        var $rightArrow = $('#sb-nav-next');
                        $close
							.hoverClass()
							.click(advertising.gallery.close)
						;
                        $leftArrow
							.hoverClass()
							.click(advertising.gallery.leftArrow)
						;
                        $rightArrow
							.hoverClass()
							.click(advertising.gallery.rightArrow)
						;
                        $shadowbox.addClass('init');
                    }
                },
                leftArrow: function() {
                    track.trackEvent('advertising', 'gallery', 'prev-arrow');
                    Shadowbox.previous();
                },
                rightArrow: function() {
                    track.trackEvent('advertising', 'gallery', 'next-arrow');
                    Shadowbox.next();
                },
                close: function() {
                    track.trackEvent('advertising', 'gallery', 'close');
                    Shadowbox.close();
                }
            }
        },

        contactUs: {
            success: function() {
                var $form = $('#content .form');
                var $submit = $form.find('.submit');
                var $thankYou = $('#content .thankyou');
                // no hammerclick
                if (!$submit.hasClass('disabled')) {
                    var loadMin = 750;
                    // disable form
                    $submit.addClass('disabled');
                    $('<div />')
						.addClass('progress')
						.insertAfter($submit)
					;
                    var serializedData = $('#content #container form').serialize();
                    var subject = $('#subject').val();
                    var startTime = new Date().getTime();
                    track.trackEvent('contact-us', 'submitted');
                    // nab form and serialize
                    $.ajax({
                        type: 'POST',
                        url: config.contactUs.url,
                        data: serializedData,
                        complete: function() {
                            var elapsed = new Date().getTime() - startTime;
                            var delay = 0;
                            // show for at least 1500 ms
                            if (elapsed < loadMin) {
                                delay = loadMin - elapsed;
                            }
                            setTimeout(function() {
                                $form.find('.progress').remove();
                                $submit.removeClass('disabled');
                            }, delay);
                        },
                        success: function(response) {
                            track.trackEvent('contact-us', 'success', subject);
                            var elapsed = new Date().getTime() - startTime;
                            var delay = 0;
                            // show for at least 1500 ms
                            if (elapsed < loadMin) {
                                delay = loadMin - elapsed;
                            }
                            setTimeout(function() {
                                $('html, body').animate({ scrollTop: $('#container').offset().top }, animation.slowish, function() {
                                    if (typeof (response) == 'object' && response.errors == false) {
                                        $thankYou.show();
                                        $form.hide();
                                    }
                                });
                            }, delay);
                            // scroll to top
                        },
                        error: function() {
                            // do something on error
                            track.trackEvent('contact-us', 'error', 'no-server-response');
                        },
                        dataType: 'json'
                    });
                }
                return false;
            },
            failure: function(errors) {
                track.trackEvent('contact-us', 'error', 'field-missing');
                return false;
            }
        },

        entertainment: {
            init: function() { $('#entertainment-selector')[0].viewIndex = 0; },
            uparrow: {
                click: function(e) {
                    e.preventDefault();
                    if ($('#entertainment-selector')[0].viewIndex > 0) {
                        $('#entertainment-selector')[0].viewIndex--;
                        $('#entertainment-selector').animate({
                            marginTop: $('#entertainment-selector')[0].viewIndex * -150
                        }, 500);
                    }
                }
            },
            downarrow: {
                click: function(e) {
                    e.preventDefault();
                    if ($('#entertainment-selector')[0].viewIndex < 2) {
                        $('#entertainment-selector')[0].viewIndex++;
                        $('#entertainment-selector').animate({
                            marginTop: $('#entertainment-selector')[0].viewIndex * -150
                        }, 500);
                    }
                }
            },
            selector: {
                mousemove: function(e) {
                    var offset = e.pageY - $('#selector-container').offset().top;
                    var percent = offset / 450;
                    var max = 150 * ($('#entertainment-selector').find('li').length - 3)
                    $('#entertainment-selector').css('margin-top', -Math.floor(max * percent));
                },
                click: function() {
                    if (!$(this).hasClass('disabled')) {
                        var $video = $(this);
                        var $file = $video.find('.file');
                        // grab data
                        var filename = $file.html();
                        var title = $file.attr('title');
                        // set hash tag
                        $.address.value(title.replace(/ /g, '-') + '/');
                        // track this interaction
                        //var title = track.safeTitle($video.find('p').html());
                        //track.trackEvent('entertainment', title, 'view');
                        $(this)
							.addClass('active')
							.siblings()
								.removeClass('active')
						;
                    }
                    return false;
                }
            }
        },
        creditcard: {
            selector: {
                click: function() {
                    var re = new RegExp("\\w+");
                    // find parent ID	
                    var category = $(this).parents(".card").attr("id");
                    // find li class 
                    var action = $(this).parent("li").attr("class");
                    // find card title
                    //var title = $(this).parents("h4").text();

                    var text = [];
                    //alert($(this).parents(".card").find(".info").find("h4").html());

                    $(this).parents("ul.action").parent("li").find(".info").find("h4").find("cufontext")
							.each(function() {
							    var newtext = $(this).html().replace("&reg;", "");
							    text.push(newtext);
							})
					;
                    var title = text.join('');
                    // from tracking.js
                    track.creditClick(category, action, title);
                    return true;
                }
            }
        },
        aboutus: {
            selector: {
                click: function() {
                    track.trackEvent('about-us', 'our-history');
                    return true;
                }
            }
        },
        promotions: {
            selector: {
                click: function() {
                    var exitid = $(this).attr("id");
                    track.trackEvent('promotions', exitid);
                    return true;
                }
            }
        },
        stationFinder: {
            findAStation: {
                openButton: {
                    click: function() {
                        track.trackEvent('station-finder', 'find-a-station', 'panel-opened');
                    }
                },
                findButton: {
                    click: function() {
                        var zipCode = $('#txtZip').val();
                        if (typeof (zipCode) != 'undefined' && zipCode && zipCode != '' && zipCode != 'Zipcode') {
                            track.trackEvent('station-finder', 'find-a-station', 'search', zipCode);
                        }
                        else {
                            track.trackEvent('station-finder', 'find-a-station', 'search');
                        }
                    }
                },
                resetButton: {
                    click: function() {
                        track.trackEvent('station-finder', 'find-a-station', 'form-reset');
                    }
                }
            },
            planATrip: {
                openButton: {
                    click: function() {
                        track.trackEvent('station-finder', 'plan-a-trip', 'panel-open');
                    }
                },
                findButton: {
                    click: function() {
                        var startZipCode = $('#txtZipFrom').val();
                        var endZipCode = $('#txtZipTo').val();
                        if (typeof (startZipCode) != 'undefined' && startZipCode && startZipCode != '' && startZipCode != 'Starting Zip' && typeof (endZipCode) != 'undefined' && endZipCode && endZipCode != '' && endZipCode != 'Ending Zip') {
                            track.trackEvent('station-finder', 'plan-a-trip', 'start-zipcode', startZipCode);
                            track.trackEvent('station-finder', 'plan-a-trip', 'end-zipcode', endZipCode);
                        }
                        track.trackEvent('station-finder', 'plan-a-trip', 'search');
                    }
                },
                resetButton: {
                    click: function() {
                        track.trackEvent('station-finder', 'plan-a-trip', 'form-reset');
                    }
                }
            },
            weatherConditions: {
                openButton: {
                    click: function() {
                        track.trackEvent('station-finder', 'weather-conditions', 'panel-open');
                    }
                },
                findButton: {
                    click: function() {
                        var zipCode = $('#infoZip').val();
                        if (typeof (zipCode) != 'undefined' && zipCode && zipCode != '' && zipCode != 'Zipcode') {
                            track.trackEvent('station-finder', 'weather-conditions', 'search', zipCode);
                        }
                        else {
                            track.trackEvent('station-finder', 'weather-conditions', 'search');
                        }
                    }
                },
                resetButton: {
                    click: function() {
                        track.trackEvent('station-finder', 'weather-conditions', 'form-reset');
                    }
                }
            }
        },


        followLink: function() {
            // grab link
            var base = '';
            var href = $(this).find('a').eq(0).attr('href');
            // force ie to obey base tag for window.location
            try {
                var base = document.getElementsByTagName("base")[0].href;
            }
            catch (e) { }
            // follow link
            if (typeof (href) != 'undefined' && href != '' && href != '#') {
                window.location = base + href;
            }
            return false;
        },
        submitForm: function() {
            $(this).parents('form').submit();
            return false;
        },
        returnFalse: function() {
            return false;
        },
        stopPropagation: function(e) {
            e.stopImmediatePropagation();
        }

    };
    // reduce obj depth 
    var handler = conoco.handler;


    /*******************************
    Attach Events
    *******************************/

    // cache objects
    var $register = $('#links-register');
    var $registerForm = $('#links-register form');
    var $header = $('#header li').not($register);
    var $navigation = $('#navigation li');

    // register modal
    var register = handler.header.register;
    var registerConfig = conoco.config.register;
    // validate register form on submit
    $registerForm.validateForm(registerConfig.form.validation, {
        onSuccess: register.form.success,
        onFailure: register.form.failure,
        inlinePrompt: false
    });

    $register
		.hover(register.mouseenter, register.mouseleave)
		.keypress(register.keypress)
		.click(register.click)
		.find('.content')
    // prevent content from causing closing click
			.click(handler.stopPropagation)
			.find('.submit')
				.downClass()
				.click(conoco.handler.submitForm)
				.end()
    // initialize default value for each form field
			.find('input')
				.focusClass()
				.each(function() {
				    var name = $(this).attr('id');
				    $(this).preserveDefaultText({
				        defaultValue: registerConfig.form.defaultText[name]
				    });
				})
				.end()
			.find('.close')
				.click(register.close.click)
	;
    // header
    var header = handler.header;
    $header
		.hoverClass()
		.hover(header.mouseenter, header.mouseleave)
		.click(handler.followLink)
	;

    // navigation
    var navigation = handler.navigation;
    $navigation
		.click(handler.followLink)
		.bind('mousedown', navigation.mousedown)
		.bind('mouseup', navigation.mouseup)
		.hover(navigation.mouseenter, navigation.mouseleave)
		.find('.down')
			.bind('mouseup', navigation.clickFix)
	;
    // call custom UI continuity fx
    conoco.navigation.uiContinuity();

    if (section == 'home') {
        var $topTouts = $('#touts-top li');
        var $bottomTouts = $('#touts-bottom li');

        // track event
        //track.trackEvent('home', 'page-view');
        // touts
        var touts = handler.touts;
        $topTouts
			.hoverClass()
			.hover(touts.top.mouseenter, touts.top.mouseleave)
			.click(handler.followLink)
			.bind('mousedown', touts.top.mouseclick)
		;
        $bottomTouts
			.hoverClass()
			.hover(touts.bottom.mouseenter, touts.bottom.mouseleave)
			.click(handler.followLink)
			.bind('mousedown', touts.bottom.mouseclick)

		;
    }
    if (section == 'advertising') {
        // cache
        var $videoSelector = $('#video-selector li');
        var $videoPagination = $("#video-list .inner-nav a");
        var $photos = $('#gallery .photos li');
        var $categories = $('#gallery .categories li');
        // track event
        //track.trackEvent('advertising', 'page-view');
        track.protectBounce = true;
        // handle hash tag
        $.address.change(function(event) {
            if (typeof (event.pathNames[0]) != 'undefined' && event.pathNames[0] != 'tv' && event.pathNames[0] != 'gallery') {
                track.protectBounce = false;
                var videoTitle = event.pathNames[0].replace(/-/g, ' ');
                if (typeof (videoTitle) != 'undefined') {
                    var $file = $videoSelector.find('.file[title="' + videoTitle + '"]');
                    var filename = $file.html();
                    var title = $file.attr('title');
                    // add new swfobject
                    var config = {
                        embed: "video-swf",
                        src: "swf/videoplayer.swf",
                        width: "666",
                        height: "425",
                        flashVersion: '9.0.0',
                        expressInstall: 'swf/express-install.swf',
                        vars: { flv_url: filename, flv_title: title },
                        params: { scale: "scale", bgcolor: "#98A2AB", menu: "false", wmode: "opaque", allowFullscreen: true, allowscriptaccess: "always" },
                        attributes: { id: 'video-swf', name: 'video-swf' }
                    };
                    swfobject.embedSWF(config.src, config.embed, config.width, config.height, config.flashVersion, config.expressInstall, config.vars, config.params, config.attributes);
                    // set video selector to hash video
                    $file.parent().click();
                }
            }
        });
        // stringified shadowbox link
        var shadowboxLinks = '#gallery .tabs li .hover a';
        var advertising = handler.advertising;


        $videoSelector
			.smoothHover(animation.quick, { ieFix: true, instantOn: true })
			.smoothDown(animation.quick, { ieFix: true })
			.click(advertising.videoSelector.click)
		;
        $videoPagination
			.click(advertising.videoPagination.click)
		;
        $photos
			.smoothHover(animation.quick, { instantOn: true, ieFix: true })
			.click(advertising.photos.click)
		;
        $categories
			.click(advertising.categories.click)
		;
        // Setup shadowbox
        Shadowbox.init({
            skipSetup: true
        });
        // set up all anchor elements with a "movie" class to work with Shadowbox
        Shadowbox.setup(shadowboxLinks, {
            overlayOpacity: 0.85,
            gallery: 'gallery',
            onOpen: advertising.gallery.init
        });
    }

    if (section == 'gas') {
        // track event
        //track.trackEvent('our-gas', 'page-view');
    }

    if (section == 'promotions') {
        var $button = $('#content .promotion .button');
        var $winner = $('#container h5');
        // track event
        //track.trackEvent('promotions', 'page-view');
        $button
			.smoothHover(animation.medium)
			.click(handler.promotions.selector.click)
		;
        conoco.cycleWinners($winner);
    }

    if (section == 'sponsorships') {
        // track event
        //track.trackEvent('sponsorships', 'page-view');
    }
    if (section == 'entertainment') {
        var $entertainmentSelector = $('#entertainment-selector li');

        // handle hash tag
        $.address.change(function(event) {
            if (typeof (event.pathNames[0]) != 'undefined') {
                var swfTitle = event.pathNames[0].replace(/-/g, ' ');
                if (typeof (swfTitle) != 'undefined') {
                    var $file = $entertainmentSelector.find('.file[title=' + swfTitle + ']');
                    var filename = $.trim($file.html());
                    var title = $file.attr('title');
                    // add new swfobject

                    try {
                        var flashIframe = $('<iframe></iframe>')
							.css({ width: 678, height: 442, border: 0 })
							.attr('frameborder', 0)
							.attr('scrolling', 'no')
							.attr('src', '/flash.html?vid=' + filename)
                        $("#entertainment-content-seo").empty()
							.append(flashIframe);

                        track.trackEvent('entertainment', title, 'view');
                    }
                    catch (e) {
                        console.log('embed failed');
                        // embed failed
                    }
                    $file.parent().click();
                }
            }
        });

        // track event
        //track.trackEvent('entertainment', 'page-view');

        var entertainment = handler.entertainment;
        $(".entertainment #uparrow").click(entertainment.uparrow.click);
        $(".entertainment #downarrow").click(entertainment.downarrow.click);
        entertainment.init();
        $entertainmentSelector
			.hoverClass()
			.smoothHover(animation.quick, { ieFix: true, instantOn: true })
			.smoothDown(animation.quick, { ieFix: true })
			.click(entertainment.selector.click)
		;

    }
    if (section == 'contactus') {

        var $form = $('#content form');
        var $labeledFields = $form.find('.labeled .input');
        var $submit = $form.find('.submit');

        // reduce object depth
        var form = config.contactUs.form;
        var contactUs = handler.contactUs;

        // initialize default text for form fields marked as labeled
        $labeledFields.each(function() {
            var fieldName = $(this).attr('id');
            var defaultText = form.defaultText[fieldName];

            if (typeof (defaultText) != 'undefined')
                $(this).inputPrompt(defaultText);

            if (fieldName != 'comments')
                $(this).focus(function() { $(this).select(); });
        });

        // set up form validation (defined in config.js)
        $form.validateForm(form.validation, {
            onSuccess: contactUs.success,
            onFailure: contactUs.failure
        });

        // setup submit button
        $submit
			.smoothHover(animation.quick)
			.smoothDown(animation.quick)
			.click(conoco.handler.submitForm)
		;

        $('.form input').keypress(function(e) {
            if (e.which == 13) {
                e.preventDefault();
                e.stopPropagation();
                $submit.click();
            }
        });

        $('.form select').keypress(function(e) {
            if (e.which == 13) {
                e.preventDefault();
                e.stopPropagation();
                $submit.click();
            }
        });

    }

    // added: 5-25-2010

    if (section == 'creditcard') {
        var $exits = $("#content .card ul.action li a");
        // track event
        //track.trackEvent('credit-cards', 'page-view');
        var creditcard = handler.creditcard;
        $exits.click(creditcard.selector.click);

    }

    if (section == 'aboutus') {
        var $ourHistory = $("#content .info .tout a");
        var aboutus = handler.aboutus;
        //track.trackEvent('about-us', 'page-view');
        $ourHistory.click(aboutus.selector.click);
    }

    if (section == 'stationfinder') {
        var $findAStation = $('#mItem1');
        var $findAStationFind = $('#btnFind');
        var $findAStationReset = $('#btnReset');
        var $planTrip = $('#mItem2Sel');
        var $planTripFind = $('#Button1');
        var $planTripReset = $('#btnReset1');
        var $weather = $('#mItem13');
        var $weatherFind = $('#Button2');
        var $weatherReset = $('#Button3');
        var stationFinder = handler.stationFinder;
        //track.trackEvent('station-finder', 'page-view');
        $findAStation.click(stationFinder.findAStation.openButton.click);
        $findAStationFind.click(stationFinder.findAStation.findButton.click);
        $findAStationReset.click(stationFinder.findAStation.resetButton.click);
        $planTrip.click(stationFinder.planATrip.openButton.click);
        $planTripFind.click(stationFinder.planATrip.findButton.click);
        $planTripReset.click(stationFinder.planATrip.resetButton.click);
        $weather.click(stationFinder.weatherConditions.openButton.click);
        $weatherFind.click(stationFinder.weatherConditions.findButton.click);
        $weatherReset.click(stationFinder.weatherConditions.resetButton.click);
    }
}

$(document).ready(conoco.readyEvent);
