﻿/* Global Vars */
var bcItemsAdded = false;

/* On Ready Event */

$(function () {
    queryObj = getQueryStringObj();
    $('#hp-news').liScroll();

    /* Populate the referral source, if there's no q string only write direct if it's not already populated (i.e. by the session) */
    if ($('#refsource')) {
        if (queryObj["s"]) {
            $('#refsource').val(decodeURIComponent(queryObj["s"]));
        }
        else {
            if ('' == $('#refsource').val()) {
                $('#refsource').val('Direct');
            }
        }
    }
    /* Populate the email address if we have one */
    if ($('#Email')) {
        if (queryObj["em"]) {
            $('#Email').val(decodeURIComponent(queryObj["em"]));
        }
    }

    /* Set up Exhibit Hall mouse effects */
    $('.exhall_booths_toprow a, .exhall_booths_midrow a, .exhall_booths_botrow a').mouseover(function () {
        $(this).find('.over').show();
        $(this).find('.exhall_booths_logo').hide();
    });
    $('.exhall_booths_toprow a, .exhall_booths_midrow a, .exhall_booths_botrow a').mouseout(function () {
        $(this).find('.over').hide();
        $(this).find('.exhall_booths_logo').show();
    });

    /* Set up Fancy Box Items */
    /* Note on previous settings - 'width': 600, 'height': 450 */
    $(".fancyb").fancybox({
        'hideOnContentClick': true,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        'autoDimensions': true,
        'onClosed': function () { if (bcItemsAdded) window.location.reload(); }
    });

    /* Add to briefcase links */
    $('.add-to-briefcase').click(function () {
        $.ajax({
            url: $(this).attr('href'),
            context: document.body,
            dataType: 'html',
            success: function (data) { alert('That item was added to your briefcase'); bcItemsAdded = true; },
            error: function (data) { alert('Sorry, there was a problem putting this item in your briefcase. If this continues to happen please visit the Help Desk'); }
        });
        return false;
    });

    $('.showbcitems').click(function () {
        $('#bcitemlist').show();
        $('#briefcase .bc-title').hide();
    });

    $('.hidebcitems').click(function () {
        $('#briefcase .bc-title').show();
        $('#bcitemlist').hide();
    });

    $('.exportbcitems').click(function () {
        document.location = '/_resources/handlers/briefcaseaszip.ashx';
    });

    /* Set up JT effect */
    //$('#lobby-jumbtron').cycle({
    //    fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    //});

});
/* / On Ready Event */

var tWidth = 0;
var tHeight = 0;
var tHtml = '';

/* Custom Functions */
var popForm = function (email, formid) {
    $.ajax({
        url: '/_resources/handlers/reghandler.ashx?e=' + email + '&f=' + formid,
        context: document.body,
        dataType: 'json',
        success: function (data) {
            if (data && data[0].Key != 'none') {
                $(data).each(function (index, value) {
                    $('input[name="' + value.Key + '"]').val(value.Value);
                    $('select[name="' + value.Key + '"]').val(value.Value);
                    $('textarea[name="' + value.Key + '"]').val(value.Value);
                });

                $('#regResults').hide();
                $('#regResults').html('<p>We found your registration information. It is shown below. Please update any incorrect information and click the &quot;submit&quot; button.</p>');
                $('#regResults').fadeIn(2000);
            }
        }
    });
};

var getQueryStringObj = function () {
    var querystring = location.search.replace('?', '').split('&');
    var queryObj = {};
    for (var i = 0; i < querystring.length; i++) {
        var name = querystring[i].split('=')[0];
        var value = querystring[i].split('=')[1];
        queryObj[name] = value;
    }
    return queryObj;
};
/* /Custom Functions */

/* jQ Plugins */
/*!
* liScroll 1.0
* Examples and documentation at: 
* http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
* 2007-2010 Gian Carlo Mingati
* Version: 1.0.2.1 (22-APRIL-2011)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Requires:
* jQuery v1.2.x or later
* 
*/
jQuery.fn.liScroll = function (settings) {
    settings = jQuery.extend({
        travelocity: 0.07
    }, settings);
    return this.each(function () {
        var $strip = jQuery(this);
        $strip.addClass("newsticker")
        var stripWidth = 1;
        $strip.find("li").each(function (i) {
            stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar and Fabien Volpi
        });
        var $mask = $strip.wrap("<div class='mask'></div>");
        var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
        var containerWidth = $strip.parent().parent().width(); //a.k.a. 'mask' width 	
        $strip.width(stripWidth + 1000);
        var totalTravel = stripWidth + containerWidth;
        var defTiming = totalTravel / settings.travelocity; // thanks to Scott Waye		
        function scrollnews(spazio, tempo) {
            $strip.animate({ left: '-=' + spazio }, tempo, "linear", function () { $strip.css("left", containerWidth); scrollnews(totalTravel, defTiming); });
        }
        scrollnews(totalTravel, defTiming);
        $strip.hover(function () {
            jQuery(this).stop();
        },
				function () {
				    var offset = jQuery(this).offset();
				    var residualSpace = offset.left + stripWidth;
				    var residualTime = residualSpace / settings.travelocity;
				    scrollnews(residualSpace, residualTime);
				});
    });
};
