﻿window.onload = function () {
    imageBox();
};

jQuery(document).ready(function ($) {

    //Detect OS
    osDetect();

    //load additional styling
    addedStyle();

    //load form styling
    forms();

    //load carousel
    carousels();

    //load fontscaling
    fontscale();

    //disables current pagination button
    jQuery('.rw-pagination .rw-button.ui-button.rw-current').click(function () {
        return false;
    });

    //adds commas to pledge number
    addCommas();
    var myNumber = jQuery('.rw-pledge-number').text();
    var myCommadString = addCommas(myNumber);
    jQuery('.rw-pledge-number').text(myCommadString);
	
	//adds a rw-last class to the last list item in the content nav jumps
	jQuery('.rw-content-nav ul li:last').addClass('rw-last');

});

function osDetect() {

    // This script sets OSName variable as follows:
    // "MacOS" for all versions of Macintosh OS

    var OSName = "Unknown OS";
    if (navigator.appVersion.indexOf("Mac") != -1) OSName = "MacOS";
    if (OSName == "MacOS") {
        jQuery('.rw-navigation').css('width', '650px');
        jQuery('.rw-navigation li a').css('padding', '10px 18px 8px 18px');
    }

}


function addedStyle() {

    //News & Events Tables
    jQuery('.rw-events tr:last td, .rw-news tr:last td').addClass('rw-last');
}

function forms() {

    //jQueryUI global buttons
    jQuery('.rw-button').button();

    ////jQueryUI radio buttons
    jQuery(".rw-radios").buttonset();

    //jQueryUI drop down
    /* jQuery( ".rerun" )
			.button()
			.click(function() {
				alert( "Running the last action" );
			})
			.next()
				.button( {
					text: false,
					icons: {
						primary: "ui-icon-triangle-1-s"
					}
				})
				.click(function() {
					alert( "Could display a menu to select an action" );
				})
				.parent()
					.buttonset(); */

    //ddlist selector click
    jQuery('.rw-ddlist-selector').click(function () {
        jQuery('.rw-ddlist').click();
        return false;
    });
}

function carousels() {

    // initialize main carousel
    jQuery("#rw-carousel .jCarouselLite").jCarouselLite({
        btnNext: "#rw-carousel .rw-next",
        btnPrev: "#rw-carousel .rw-prev",
        visible: 3,
        scroll: 1,
        circular:0
    });

    jQuery('#rw-carousel .rw-prev, #rw-carousel .rw-next').click(function () {
        jQuery(this).blur();
    });
    jQuery('#rw-carousel .rw-prev.disabled, #rw-carousel .rw-next.disabled').click(function() {
        return false;
    });

    // initialize cheers carousel
    jQuery("#rw-carousel-cheers .jCarouselLite").jCarouselLite({
        btnNext: "#rw-carousel-cheers .rw-next",
        btnPrev: "#rw-carousel-cheers .rw-prev",
        visible: 1,
        scroll: 1,
        circular: 0
    });

    jQuery('#rw-carousel-cheers .rw-prev, #rw-carousel-cheers .rw-next').click(function () {
        jQuery(this).blur();
    });
    jQuery('#rw-carousel-cheers .rw-prev.disabled, #rw-carousel-cheers .rw-next.disabled').click(function () {
        return false;
    });

    // initialize jeers carousel
    jQuery("#rw-carousel-jeers .jCarouselLite").jCarouselLite({
        btnNext: "#rw-carousel-jeers .rw-next",
        btnPrev: "#rw-carousel-jeers .rw-prev",
        visible: 1,
        scroll: 1,
        circular: 0
    });

    jQuery('#rw-carousel-jeers .rw-prev, #rw-carousel-jeers .rw-next').click(function () {
        jQuery(this).blur();
    });
    jQuery('#rw-carousel-jeers .rw-prev.disabled, #rw-carousel-jeers .rw-next.disabled').click(function () {
        return false;
    });

    // initialize category carousel #1
    jQuery("#rw-carousel-category-1 .jCarouselLite").jCarouselLite({
        btnNext: "#rw-carousel-category-1 .rw-next",
        btnPrev: "#rw-carousel-category-1 .rw-prev",
        visible: 4,
        scroll: 1,
        circular: 0
    });

    jQuery('#rw-carousel-category-1 .rw-prev, #rw-carousel-category-1 .rw-next').click(function () {
        jQuery(this).blur();
    });
    jQuery('#rw-carousel-category-1 .rw-prev.disabled, #rw-carousel-category-1 .rw-next.disabled').click(function () {
        return false;
    });

    // initialize video carousel #2
    jQuery("#rw-carousel-category-2 .jCarouselLite").jCarouselLite({
        btnNext: "#rw-carousel-category-2 .rw-next",
        btnPrev: "#rw-carousel-category-2 .rw-prev",
        visible: 4,
        scroll: 1,
        circular: 0
    });

    jQuery('#rw-carousel-category-2 .rw-prev, #rw-carousel-category-2 .rw-next').click(function () {
        jQuery(this).blur();
    });
    jQuery('#rw-carousel-category-2 .rw-prev.disabled, #rw-carousel-category-2 .rw-next.disabled').click(function () {
        return false;
    });

    // initialize category carousel #3
    jQuery("#rw-carousel-category-3 .jCarouselLite").jCarouselLite({
        btnNext: "#rw-carousel-category-3 .rw-next",
        btnPrev: "#rw-carousel-category-3 .rw-prev",
        visible: 4,
        scroll: 1,
        circular: 0
    });

    jQuery('#rw-carousel-category-3 .rw-prev, #rw-carousel-category-3 .rw-next').click(function () {
        jQuery(this).blur();
    });
    jQuery('#rw-carousel-category-3 .rw-prev.disabled, #rw-carousel-category-3 .rw-next.disabled').click(function () {
        return false;
    });

    // initialize category carousel #4
    jQuery("#rw-carousel-category-4 .jCarouselLite").jCarouselLite({
        btnNext: "#rw-carousel-category-4 .rw-next",
        btnPrev: "#rw-carousel-category-4 .rw-prev",
        visible: 4,
        scroll: 1,
        circular: 0
    });

    jQuery('#rw-carousel-category-4 .rw-prev, #rw-carousel-category-4 .rw-next').click(function () {
        jQuery(this).blur();
    });
    jQuery('#rw-carousel-category-4 .rw-prev.disabled, #rw-carousel-category-4 .rw-next.disabled').click(function () {
        return false;
    });


    // initialize category carousel #5
    jQuery("#rw-carousel-category-5 .jCarouselLite").jCarouselLite({
        btnNext: "#rw-carousel-category-5 .rw-next",
        btnPrev: "#rw-carousel-category-5 .rw-prev",
        visible: 4,
        scroll: 1,
        circular: 0
    });

    jQuery('#rw-carousel-category-5 .rw-prev, #rw-carousel-category-5 .rw-next').click(function () {
        jQuery(this).blur();
    });
    jQuery('#rw-carousel-category-5 .rw-prev.disabled, #rw-carousel-category-5 .rw-next.disabled').click(function () {
        return false;
    });


}

function gallery() {

    jQuery('#rw-gallery').galleryView({
        panel_width: 600,
        panel_height: 550,
        frame_width: 60,
        frame_height: 40,
        transition_interval: 100000000,
        overlay_opacity: 1.0,
        frame_opacity: 1.0,
        frame_gap: 2,
        filmstrip_size: 8
    });

    jQuery('#rw-prev-top.rw-active').click(function () {
        jQuery('.nav-prev').click();
        jQuery(this).blur();
        return false;
    });
    jQuery('#rw-next-top.rw-active').click(function () {
        jQuery('.nav-next').click();
        jQuery(this).blur();
        return false;
    });
}

function fontscale() {
    //Scale Fonts
    jQuery(".rw-font-increase").fontscale(".rw-content p, .rw-content h1, .rw-content h2, .rw-content td, .rw-content h2 .rw-date, .rw-image-box .rw-description", "up", { unit: "px", increment: 1 });
    jQuery(".rw-font-decrease").fontscale(".rw-content p, .rw-content h1, .rw-content h2, .rw-content td, .rw-content h2 .rw-date, .rw-image-box .rw-description", "down", { unit: "px", increment: 1 });
    jQuery(".rw-font-reset").fontscale(".rw-content p, .rw-content h1, .rw-content h2, .rw-content td, .rw-content h2 .rw-date", "reset");

    jQuery('.rw-font-increase, .rw-font-decrease, .rw-font-reset').click(function () { jQuery(this).blur(); });
}

function imageBox() {

    //set image box widths
    jQuery('.rw-image-box img').each(function () {
        var i = jQuery(this).width();
        jQuery(this).parent('.rw-image-box').width(i);
    });
}

function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

function mailpage() {
    mail_str = "mailto:?subject=" + document.title;
    mail_str += "&body= I visited the R-word.org site and found this:" + location.href;
    //mail_str += ". You should check this out at, " + location.href;
    location.href = mail_str;
}
