﻿$(document).ready(function () {

    var arr = [
	           $("#products-panel"),
	           $("#gproi-panel").hide(),
	           $("#marketing-panel").hide()
	       ];
    var cur = 0, nxt = 1;

    setInterval(function () {
        if ($.browser.msie) {
            arr[cur].fadeOut(100);
            /*arr[nxt].animate({width:'toggle'},500); */
            arr[nxt].slideDown();
        } else {
            arr[cur].fadeOut(2000);
            arr[nxt].fadeIn(2000);
        }

        cur = (cur + 1 < arr.length) ? cur + 1 : 0;
        nxt = (nxt + 1 < arr.length) ? nxt + 1 : 0;
    }, 12000);
    var ajax_load = "<img class='loading' src='/VMBC/img/load.gif' alt='loading...' />";
    var overlay = ("#fade")

    $(".team a").click(function () {
        var loadUrl = $(this).attr("href");
        var placeResult = ("pop");
        $("#" + placeResult)
		.html(ajax_load)
		.load(loadUrl + " #tm");

        $("#" + placeResult).fadeIn();
        $(overlay).fadeIn(function () {

        });

        $(overlay).click(function () {
            $(overlay).fadeOut();
            $("#" + placeResult).fadeOut();

        });

        return false;

    });

    done = function () { };

    $(".plus-list a").click(function () {

        reinitialiseScrollPane = function () {
            $('#scrollme').jScrollPane();
        }

        var loadUrl = $(this).attr("href");
        var placeResult = ("pop");
        $("#" + placeResult)
		.html(ajax_load)
		.load(loadUrl + " #tm");

        
        $(overlay).fadeIn(function () {
            $("#" + placeResult).positionCenter();
            $("#" + placeResult).fadeIn();
            if ($('#scrollme').length) {
                $('#scrollme').jScrollPane();
            }
        });

        $(overlay).click(function () {
            $(overlay).fadeOut();
            $("#" + placeResult).fadeOut();

        });

        return false;

    });

    $(".solutions a").click(function () {
        
		reinitialiseScrollPane = function () {
            $('#scrollme').jScrollPane();
        }
		
		var loadUrl = $(this).attr("href");
        var placeResult = ("pop");
        $("#" + placeResult)
		.html(ajax_load)
		.load(loadUrl + " #tm");

        $(overlay).fadeIn(function () {
            $("#" + placeResult).positionCenter();
            $("#" + placeResult).fadeIn();
            if ($('#scrollme').length) {
                $('#scrollme').jScrollPane();
            }
        });

        $(overlay).click(function () {
            $(overlay).fadeOut();
            $("#" + placeResult).fadeOut();

        });
		
        return false;

    });

    $("a.kill").live('click', function () {
        $("#fade").fadeOut();
        $("#pop").fadeOut();
        return false;
    });

    $('#tm').live('mouseover', function (event) {
        $('#scrollme').jScrollPane();
    });

    $('#tm').live('mouseover', function (event) {
        $('#scrollme2').jScrollPane();
    });

    $("#means .btn-medium").click(function () {
        return false;
    });

    $("#calc input[type='text']").click(function () {
        $(this).val("");
    });

    $('#f1, #f2, #f3, #f4, #f5, #f6').keyup(function () {
        var $this = $(this);
        var num = $this.val().replace(/,/g, '');
        $this.val(num.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
    });

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;
}


    $("#c1a .btn-medium").click(function () {
        /*The variable names are the same as The cell names in the excel file */
        var customers = $("#f1").val().replace(/,/g, '');
        var emaiLDB = $("#f2").val().replace(/,/g, '');
        var stores = $("#f3").val().replace(/,/g, '');

        if (customers != "ex - 6000000") {
            /*Top 3 fields*/
            var C2 = customers;

            var C3 = 0;
            if (emaiLDB != "ex - 1000000") {
                C3 = emaiLDB;
            }

            var C4 = 0;
            if (stores != "ex - 1000") {
                C4 = stores;
            }

            var D7 = C2 * 0.1;
            var D8 = C2 * 0.15;
            var D9 = C2 * 0.3;

            var E7 = ((C4 / C2) * 2000) * D7;
            var E8 = ((C4 / C2) * 2000) * D8;
            var E9 = ((C4 / C2) * 2000) * D9;
        
			var H7 = C3 / C2;
			var mailsToAdd = 0;
			
			if (H7 >= 0.05 && H7 < 0.1){
				mailsToAdd = C3 * 0.01;
			}
			
			if (H7 >= 0.1 && H7 < 0.15){
				mailsToAdd = C3 * 0.02;
			}

			if (H7 >= 0.15 && H7 < 0.2){
				mailsToAdd = C3 * 0.03;
			}

			if (H7 >= 0.2 && H7 < 0.3){
				mailsToAdd = C3 * 0.04;
			}
				
			if (H7 >= 0.3){
				mailsToAdd = C3 * 0.05;
			}

			
            var J7 = Math.round(D7 + E7 + mailsToAdd);
            var J8 = Math.round(D8 + E8 + mailsToAdd);
            var J9 = Math.round(D9 + E9 + mailsToAdd);

			
            var D12 = J9 * 0.95;
            var D13 = J9 * 0.92;
            var D14 = J9 * 0.85;
            var D15 = J9 * 0.35;
            var D16 = J9 * 0.45;
            var D17 = J9 * 0.2;
            var D18 = J9 * 0.25;
            var D19 = 0.85 * (D17 + D18);
            var D20 = D12 * 0.03;

			/*Get Specifics pop-up */
            $(".ii1 span").text(addCommas(D12.toFixed(0))); /*able to receive text messages*/
            $(".ii2 span").text(addCommas(D17.toFixed(0))); /*able to download an iPhone app*/
            $(".ii3 span").text(addCommas(D13.toFixed(0))); /*who will read text messages*/
            $(".ii4 span").text(addCommas(D18.toFixed(0))); /*able to download an Android app*/
            $(".ii5 span").text(addCommas(D14.toFixed(0))); /*who will read within 20 minutes*/
            $(".ii6 span").text(addCommas(D19.toFixed(0))); /*likely to opt-in to receiving push notifications*/
            $(".ii7 span").text(addCommas(D15.toFixed(0))); /*able to recieve MMS messages*/
            $(".ii8 span").text(addCommas(D20.toFixed(0))); /*likely to opt out of receiving future messages*/
            $(".ii9 span").text(addCommas(D16.toFixed(0))); /*able to access the mobile internet*/

			/* The text under the left calculate button*/
            $("#results1 span").text(J7);
            $("#results2 span").text(J8);
            $("#results3 span").text(J9);
            /*"# Customers you wish to send Text or Push notifications to" is being filled */
			$("#f4").val(J9);

            $("#means .btn-medium").click(function () {
                $("#pop").fadeIn(function () { });
                $("#fade").fadeIn(function () { });

                var isist = $('div#is-ist')

                $("#pop").append(isist);

                return false;

            });

            $.fn.digits = function () {
                return this.each(function () {
                    $(this).text($(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
                })
            }

            $.fn.digitsVal = function () {
                return this.each(function () {
                    $(this).val($(this).val().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
                })
            }

            $("#results1 span").digits();
            $("#results2 span").digits();
            $("#results3 span").digits();

            $("#f4").digitsVal()
        };
    });


    $("#c2a .btn-medium").click(function () {
        var customers = $("#f4").val().replace(/,/g, '');
        var price = $("#f5").val().replace(/$/g, '');
        var profit = $("#f6").val().replace(/%/g, '');
        var response = $("#f7").val().replace(/%/g, '');

        if (customers != "ex - 1000000") {
            var D23 = customers;
            var D24 = 0;
            if (price != "ex - 45.00 (in USD)") {
                D24 = price;
            }

            var D25 = 0;
            if (profit != "ex - 33.00 (in USD)") {
                D25 = profit;
            }

            var D26 = 1;
            if (response != "ex - 5 (in )") {
                D26 = response;
            }	

            var D30 = (D23 * D26) * D24;
            var D31 = D30 * D25;
            var D32 = D23 * 0.025;
            var D33 = D31 / D32;

            $("#c2b strong span").text(D33 / 100);

            $.fn.digits = function () {
                return this.each(function () {
                    $(this).text($(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
                })
            }
            $("#c2b strong span").digits();
        };

    });

});	
