﻿function firstWindow(page) {
    OpenWin = this.open(page, "CtrlWindow", "width=750,height=600,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,left=50,top=50");
}


function EmailWindow(page) {
    OpenWin = this.open(page, "CtrlWindow", "width=450,height=450,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,left=50,top=50");
}

function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

function UserCommentsWindow(page) {
    var NewWindow = this.open(page, "newWin", "width=600,height=350,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,left=50,top=50");
    NewWindow.focus();
    return false;
}

function PopupPage(page) {
    var popupPage = this.open(page, "popupPage", "width=640,height=350,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,left=50,top=50");
    popupPage.focus();
    return false;
}

function DoSearch() {
    var newLocation = '/Search.aspx?cx=partner-pub-3653138092946575:76g41w-8w4i&cof=FORID:10&ie=ISO-8859-1&q=' + $("#searchBox").val();
    document.location.href = newLocation;
}

function WireDisclosureTrigger() {
    $(".disclosureTrigger").click(
        function() {
            window.open("/disclosure.html", "disclosure", " height = 300, width = 330, resizable = 0, location=0");
            return false;
        }
    );
}

function WireSearchTrigger() {
    $(".searchTrigger").click(
        function() {
            DoSearch();
        }
    );
}

function WireInputBoxes() {
    $('input[type="text"]')
    .focusin(
        function() {
            $(this).val("");
        }
    )
    .focusout(
        function() {
            if($(this).val() == "")
            {
                $(this).val(this.defaultValue);
            }
        }
    );
}

function WireTopNavSiteList() {
    $('.topnav .sitelistTrigger').each(function() {
        // options
        var distance = 10;
        var time = 250;
        var hideDelay = 500;

        var hideDelayTimer = null;

        // tracker
        var beingShown = false;
        var shown = false;


        var trigger = $(this);
        var popup = $(this).siblings(".container_sitelist").css('opacity', 0);



        // set the mouseover and mouseout on both element
        $([trigger.get(0), popup.get(0)]).mouseover(function() {


            var trigger_offset = $(this).offset();
            var trigger_height = $(this).height();

            var parent_offset = $(this).parent().offset();
            var popup_right = parseInt($(window).width()) - parseInt(trigger_offset['left']) - parseInt(trigger.width());
            var popup_top = parseInt(trigger_offset['top']) - parseInt(parent_offset['top']) + parseInt(trigger_height) + 10;


            // stops the hide event if we move from the trigger to the popup element
            if (hideDelayTimer) clearTimeout(hideDelayTimer);

            // don't trigger the animation again if we're being shown, or already visible
            if (beingShown || shown) {
                return;
            } else {
                beingShown = true;

                // reset position of popup box
                popup.css({
                    top: popup_top,
                    right: popup_right,
                    zIndex: 100000,
                    display: 'block' // brings the popup back in to view
                })

                // (we're using chaining on the popup) now animate it's opacity and position
	        .animate({
	            top: '+=' + distance + 'px',
	            opacity: 1
	        }, time, 'swing', function() {
	            // once the animation is complete, set the tracker variables
	            beingShown = false;
	            shown = true;
	        });
            }
        }).mouseout(function() {
            // reset the timer if we get fired again - avoids double animations
            if (hideDelayTimer) clearTimeout(hideDelayTimer);

            // store the timer so that it can be cleared in the mouseover if required
            hideDelayTimer = setTimeout(function() {
                hideDelayTimer = null;
                popup.animate({
                    top: '+=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function() {
                    // once the animate is complete, set the tracker variables
                    shown = false;
                    // hide the popup entirely after the effect (opacity alone doesn't do the job)
                    popup.css('display', 'none');
                });
            }, hideDelay);
        });
    });
}

function WireTopMenuSiteList() {
    $('.mainmenu .sitelistTrigger').each(function() {
        // options
        var distance = 10;
        var time = 250;
        var hideDelay = 500;

        var hideDelayTimer = null;

        // tracker
        var beingShown = false;
        var shown = false;

        var trigger = $(this);
        var popup = $(this).siblings(".container_sitelist").css('opacity', 0);



        // set the mouseover and mouseout on both element
        $([trigger.get(0), popup.get(0)]).mouseover(function() {


            var trigger_offset = $(this).offset();
            var trigger_height = $(this).height();
            var parent_offset = $(this).parent().offset();
            var popup_left = parseInt((parseInt($(window).width()) - parseInt(popup.width())) / 2);
            var popup_top = parseInt(trigger_offset['top']) + parseInt(trigger_height);


            // stops the hide event if we move from the trigger to the popup element
            if (hideDelayTimer) clearTimeout(hideDelayTimer);

            // don't trigger the animation again if we're being shown, or already visible
            if (beingShown || shown) {
                return;
            } else {
                beingShown = true;

                // reset position of popup box
                popup.css({
                    top: popup_top,
                    left: popup_left,
                    zIndex: 100000,
                    display: 'block' // brings the popup back in to view
                })

                // (we're using chaining on the popup) now animate it's opacity and position
	        .animate({
	            top: '+=' + distance + 'px',
	            opacity: 1
	        }, time, 'swing', function() {
	            // once the animation is complete, set the tracker variables
	            beingShown = false;
	            shown = true;
	        });
            }
        }).mouseout(function() {
            // reset the timer if we get fired again - avoids double animations
            if (hideDelayTimer) clearTimeout(hideDelayTimer);

            // store the timer so that it can be cleared in the mouseover if required
            hideDelayTimer = setTimeout(function() {
                hideDelayTimer = null;
                popup.animate({
                    top: '+=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function() {
                    // once the animate is complete, set the tracker variables
                    shown = false;
                    // hide the popup entirely after the effect (opacity alone doesn't do the job)
                    popup.css('display', 'none');
                });
            }, hideDelay);
        });
    });
}

function WireSiteLists() {
    WireTopNavSiteList();
    WireTopMenuSiteList();
}

function WireStarAlertSignupTriggers() {
    $(".starAlertSignupTrigger").click(
        function() {
            $("#starAlertSignupForm").slideToggle();
            return false;
        }
    );
}

function WireExpandTriggers() {
    $(".expandTrigger").click(
        function() {
            $(this).parents(".expandTriggerContainer").addClass("hidden");
            $(this).parents(".expandTriggerContainer").siblings(".fullListContainer").removeClass("hidden");
            $(this).parents(".expandTriggerContainer").siblings(".shortListContainer").addClass("hidden");
            $(this).parents(".expandTriggerContainer").siblings(".collapseTriggerContainer").removeClass("hidden");
        }
    );
}

function WireCollapseTriggers() {
    $(".collapseTrigger").click(
        function() {
            $(this).parents(".collapseTriggerContainer").addClass("hidden");
            $(this).parents(".collapseTriggerContainer").siblings(".fullListContainer").addClass("hidden");
            $(this).parents(".collapseTriggerContainer").siblings(".shortListContainer").removeClass("hidden");
            $(this).parents(".collapseTriggerContainer").siblings(".expandTriggerContainer").removeClass("hidden");
        }
    );
}

function WireRotatePanel() {
    $("#rotator").jcarousel({
        scroll: 1,
        start: 1,
        offset: 1,
        auto: 3,
        wrap: 'circular',
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
}

$(document).ready(
    function() {
        WireDisclosureTrigger();
        WireSearchTrigger();
        WireInputBoxes();
        WireSiteLists();
        WireStarAlertSignupTriggers();
        WireExpandTriggers();
        WireCollapseTriggers();
        WireRotatePanel();
    }
);