﻿var sites = [
    { name: 'betty',
      url: 'BettyCrocker.com',
      copy: 'The one stop resource when you\'re thinking ‘what should I make for dinner tonight?’ Betty Crocker’s library of content has thousands of for cooking tips & recipes from the experts.',
      img: 'bettycrocker.jpg' },
    { name: 'pillsbury',
      url: 'Pillsbury.com',
      copy: 'The cream always rises to the top at Pillsbury. A complete library of baking tips & tricks that bakers at any level can understand & enjoy.',
      img: 'pillsbury.jpg' },
    { name: 'bigoven',
      url: 'Bigoven.com',
      copy: 'Big Oven looks to answer ‘what should I make for dinner tonight? with the latest technology and by personalizing individual experiences. It\'s a place for users to go to get unstuck for dinner.',
      img: 'bigoven.jpg' },
    { name: 'eatbetteramerica',
      url: 'EatBetterAmerica.com',
      copy: 'EatBetterAmerica is designed for people who are increasingly interested in the impact food has on their health and crave simple, easy-to-understand health and nutritional information.',
      img: 'eatbetteramerica.jpg' },
    { name: 'tablespoon',
      url: 'Tablespoon.com',
      copy: 'Tablespoon is a place for users to find, save, and share recipes. Tablespoon creates a one-of-a-kind experience that brings the best kitchen-tested recipes together with the best home- tested recipes from everyday cooks across the country.',
      img: 'tablespoon.jpg' },
    { name: 'cookeatshare',
      url: 'CookEatShare.com',
      copy: 'CookEatShare aims to be the world’s largest kitchen. Through global user-generated content, CookEatShare offers a trustworthy network of passionate chefs, their recipes & great entertaining ideas.',
      img: 'cookeatshare.jpg' },
    { name: 'tastespotting',
      url: 'Tastespotting.com',
      copy: 'TasteSpotting is a highly visual potluck of recipes, references, experiences, stories, articles, products, and anything else that inspires exquisite taste.',
      img: 'tastespotting.jpg'}
];

var imgRoot = '/img/site_rotator/';
var currentSiteIndex = 0;

var lightboxImageRoot = '/img/lightboxes/';
var widgetScreens = [lightboxImageRoot + 'platefull_widget_screen_1.jpg',
                     lightboxImageRoot + 'platefull_widget_screen_2.jpg',
                     lightboxImageRoot + 'platefull_widget_screen_3.jpg',
                     lightboxImageRoot + 'platefull_widget_screen_4.jpg',
                     lightboxImageRoot + 'platefull_widget_screen_5.jpg',
                     lightboxImageRoot + 'platefull_widget_screen_6.jpg'];

var brandedPages = [lightboxImageRoot + 'pillsbury_member_page.jpg'];

function showSiteByIndex(index) {
    currentSiteIndex = index;
    $('#food-sites p').html(sites[index].copy);
    $('#food-sites span').html(sites[index].url);
    $('#food-sites')
        .css('background-image', 'url(' + imgRoot + sites[index].img + ')')
        .attr('class', sites[index].name).hide().fadeIn();
}

function moveSiteForward() {
    var siteIndexToShow = currentSiteIndex + 1;
    if (siteIndexToShow > sites.length - 1) siteIndexToShow = 0;
    showSiteByIndex(siteIndexToShow);
    return false;
}

function moveSiteBack() {
    var siteIndexToShow = currentSiteIndex - 1;
    if (siteIndexToShow < 0) siteIndexToShow = sites.length - 1;
    showSiteByIndex(siteIndexToShow);
    return false;
}

function pickFoodThought() {
    var thoughtsCount = $('#food-thoughts div').hide().length;
    var randomInt = Math.ceil(Math.random() * thoughtsCount);
    $('#food-thoughts div:nth-child(' + randomInt + ')').show();
}

function collapseContent() {
    var $this = $(this);
    $this.unbind('click');
    $this
        .parent()
        .find('span.collapse')
        .after('<span class="ellipsis">...</span>')
        .slideToggle();
    $this.html('More');
    $this.click(expandContent);
    $this.toggleClass('up');
    $this.blur();
    return false;
}

function expandContent() {
    var $this = $(this);
    $this.unbind('click');
    $this.parent().find('span.ellipsis').remove();
    $this
        .parent()
        .find('span.collapse')
        .slideToggle(function() {
            $(this).css('display', '');
        });
    $this.html('Less');
    $this.click(collapseContent);
    $this.toggleClass('up');
    $this.blur();
    return false;
}

function initializeContentAccordian() {
    $('a.expander').show();
    $('span.collapse').hide().after('<span class="ellipsis">...</span>');
    $('a.expander').live('click', expandContent);
}

$(document).ready(function() {
    $('#slideshow').cycle({
        fx: 'fade',
        timeout: 6000,
        startingSlide: Math.floor(Math.random() * $('#slideshow > a').length)
    });

    $('#pills-lightbox').click(function() {
        $('#branded-lightbox').LightBox();
        return false;
    });

    $('#spinner-lightbox').click(function() {
        $('#widget-lightbox').LightBox();
        return false;
    });

    pickFoodThought();
    $('#site-next').click(moveSiteForward);
    $('#site-prev').click(moveSiteBack);
    initializeContentAccordian();
});   
