﻿var rotator_index;
var front_images = new Array();
var front_caption = new Array();
var front_text = new Array();
var front_link = new Array();
var front_width = new Array();
var i = 0;

// Populate arrays with the individual ads in the rotator.  Ads can easily be re-arranged by changing the
// order.  

front_images[i] = 'Images/FrontPage/Picture2d.jpg';
front_caption[i] = 'Royal Crest Dairy - Serving Colorado families for over 85 years';
front_text[i++] = '';

front_images[i] = 'Images/FrontPage/Picture3.jpg';
front_caption[i] = 'Delivered Fresh To Your Front Door  - Just in Time for Breakfast!';
front_text[i++] = '';

front_images[i] = 'Images/FrontPage/Picture7.jpg';
front_caption[i] = '';
front_text[i++] = '<div style="width: 300px;margin-left: -10px;"><span style="font-size:16px;font-weight: bold;text-align:center"><i>Are you making too many trips to the grocery store?</i></span><ul><li>The average shopper makes <u>four</u> trips to the store each week.</li><li> They spend 66% of their food dollars on “impulse” purchases.</li></ul><span style="font-size:14px;">Royal Crest Dairy customers...</span><ul><li>Save time.</li><li>Save money on gasoline and reduce air pollution.</li><li>Prevent tons of plastic waste from going to the landfills. (Return/Reuse)</li><br/><br/><span style="font-size:16px;font-weight:bold">' +
'<i><a href="Shared/SignUp.aspx">Sign-Up for service today!</a></i></span></div>';

front_images[i] = 'Images/FrontPage/Picture5a.jpg';
front_caption[i] = 'Locally Owned and Operated';
front_text[i++] = '';

front_images[i] = 'Images/FrontPage/Milk.jpg';
front_caption[i] = '';
front_text[i++] = '<div style="width: 270px; text-align: center;">Royal Crest Dairy, a family owned business serving Colorado since 1927, provides families with the freshest milk produced on local Colorado dairy farms.  These farms are all grade "A" producers and must submit to a rigid testing program to insure purity, quality and flavor.  Royal Crest contracts with producers not to treat their cows with the bovine growth hormone rbGH.  All milk is tested for antibiotics and if detected, the milk is rejected and not processed at our plant located in Longmont, Colorado</div>';

front_images[i] = 'Images/FrontPage/Yogurt.jpg';
front_caption[i] = '';
front_text[i++] = '<div style="font-size: 18px; line-height: 24px; width: 300px; text-align: center; color: #1F296B; margin-top: 10px;"><span style="font-size: 24px; line-height: 28px;">Westby Plain Yogurt<br/>(Sweetened)</span><p>Now available in a larger container (24 oz).  This 1% lowfat yogurt is, as always,<br/> <span style="color: red"> rbGH hormone free!</span><br/> Order yours today and mix with your favorite fruits and granolas.</div>';

front_images[i] = 'Images/FrontPage/Picture8.jpg';
front_caption[i] = '';
front_text[i++] = '<div style="width: 270px; margin-left:10px;"><br><br><span style="font-size:16px; font-weight: bold">We are more than just milk!</span><br><ul><li>We offer fresh products for breakfast, school lunches, and those everyday items needed for your family meals.<br><br></li><li>Important nutritional products like orange juice, cheese, bread, butter, and eggs may be added to your order anytime.</li></ul></div>';
 
front_images[i] = 'Images/FrontPage/CookieDough3.jpg';
front_caption[i] = '';
/* front_link[i] = 'Shared/ValuePage.aspx'; */
front_text[i++] = '<div style="width: 270px; text-align: center; margin-left:10px;font-size: 16px; color: #7F5322;">English Bay Gourmet Cookie Dough is made with all natural ingredients and no preservatives.  Bake an entire tub or a couple at a time.  Tastes just like homemade.<div style="font-size:18px;"><br/>-Just scoop and bake! <p>Each 40 oz. tub makes 37 gourmet cookies!</p><p><a style="text-decoration: underline" href="Shared/ValuePage.aspx">Click here to view specials</a></p></div></div>';

front_images[i] = 'Images/FrontPage/OrderCard2.png';
front_caption[i] = 'Need an order card?  <a href="Shared/Order_Card.pdf">Click here</a> to print <span style="font-size: 12px;">(Adobe Acrobat needed)</span>' +
'<div style="text-align: left;font-size: 12px;">** Don\'t have adobe acrobat reader? <a href="http://get.adobe.com/reader/">Click to download</a>';
front_text[i++] = '<div style="width: 300px;margin-left:-50px;">' +
'<div style="font-size: 18px; text-align: center; font-weight: bold;">Ordering made easy:</div><div style="font-size: 12px;"><ol>' +
'<li><a href="Shared/login.aspx">Log in here</a> or above to place your order until 7:00pm the night of your delivery.</li>' +
'<li>Call our friendly Customer Service Department between the hours of 6:30am and 4:00pm (303-777-3055 or <br/>1-888-266-6455)' +
'<li>Check your refrigerator the night of your delivery ad mark your order card for last minute items needed.  Please have your order card out by 10:00 p.m. for your driver.  We carry extra items on our trucks for your convenience!</li>' +
'</div>';

front_images[i] = 'Images/FrontPage/autopay1.jpg';
front_caption[i] = '';
front_text[i++] = '<div style="width: 290px; margin-left:10px; font-size:11px; font-weight: bold;"><br><div style="text-align: center;font-size: 16px;">' +
'The choice is yours:</div><br/><a href="Shared/CheckPayment.aspx">Click here</a> to download the form for automatic withdrawal' +
' from your <i>checking account.</i>&nbsp;This occurs on the <i>20th</i> of each month.<br/>' +
'<p><a href="Shared/CreditCardPayment.aspx">Click here</a> to download the form to automatically charge your ' +
'<i>debit or credit card.</i> This process orccurs on the <i>10th</i> of each month. </p>' +
'We gladly accept the following:<div style="margin:6px 0 17px 0;text-align:left"><img style="height: 24px;" src="Images/FrontPage/credit_cards.jpg"></div>' +
'<b>There is no additional charge for auto pay!</b></div>';

front_images[i] = 'Images/FrontPage/Picture6.jpg';
front_caption[i] = '';
front_text[i++] = '<div style="width: 180px; font-size:14px;text-align: center;"><br>What is sweet and<br>rich in vitamins?<br><br><br>Royal Crest Dairy<br> Orange Juice<br><br>Talbott Farms<br> Apple Juice<br><br>Simply the Best!</div>';

front_images[i] = 'Images/FrontPage/Referral_slide.jpg';
front_caption[i] = 'Click <a href="Referral.pdf" target="_blank">here</a> for more details.';
front_text[i++] = '';

var max_index = i - 1;
var show_paused = false;
var next_image;
var image_index;
var timer_id;

function init_show() {
	show_paused = false;
	next_image = 0;
	image_index = 0;
	slide_show(0);
}

// If show running, then pause.  If paused, start show running
function toggle_pause() {
    if (show_paused == false) {
        $('#pause_button_img').attr('src','Images/FrontPage/play.jpg');
		show_paused = true;
		clearTimeout(timer_id);
	} else {
	    $('#pause_button_img').attr('src','Images/FrontPage/pause2.jpg');
	    show_paused = false;
		slide_show(next_image);
	}
}

// Show the previous image in the sequence
function show_previous() {
	show_paused = false;
	toggle_pause();
	image_index = image_index - 1;
	if (image_index < 0) {
		image_index = max_index;
	}
	next_image = image_index;
	show_image(image_index);
}

// Show the next image in the sequence
function show_next() {
    show_paused = false;
    toggle_pause();
    if (image_index < max_index) {
		image_index = image_index + 1;
	} else {
		image_index = 0;
	}
	next_image = image_index;
	show_image(image_index);
}

// Run the slide show starting at the image with index 'idx'
function slide_show(idx) {
	if (show_paused) {
		return;
	}
	show_image(idx);
	image_index = idx;
	next_image = idx + 1;
	if (next_image > max_index) {
		next_image = 0;
	}
	if (!show_paused) {
		timer_id = setTimeout("slide_show(" + next_image + ")", 10000);
	}
}

// Show the image/ad with an index of 'idx'
function show_image(idx) {
    if (document.getElementById('frontImage') != null) {
        document.getElementById('frontImage').src = front_images[idx];
        if (front_text[idx] == '') {
            // If no caption, use tall class, otherwise use wide class
            if (front_caption[idx] == '') {
                document.getElementById('frontImageLeft').className = 'rotator_img_tall';
            } else {
                document.getElementById('frontImageLeft').className = 'rotator_img_wide';
            }
        } else {
            document.getElementById('frontImageLeft').className = 'rotator_img_narrow';
        }
        var handler = function() { window.location.href = front_link[idx]; };
        if (typeof front_link[idx] != 'undefined') {
            $('#frontImageLeft').bind('click',handler);
        } else {
            $('#frontImageLeft').unbind('click',handler);
        }
        $('#frontImageText').html(front_text[idx]);
        $('#frontImageCaption').html(front_caption[idx]);
	}
}
