﻿// Search hide

function closeSearch() {
    $(".skybarSearch").slideUp("slow");
    return false;
}

$(function() {

    //  Search dropdown
    $("#skybarSearch").mouseenter(function() {
        var p = $(this);
        var position = p.position();

        $(".skybarSearch").css("left", position.left, "top", position.top);
        $(".skybarSearch").slideDown("slow");

        $("#ctl00_searchBox").focus(function() {
            $(this).select();
        });
    });

    // Carousel

    $('#carousel').carousel({
        pagination: true,
        effect: "side",
        loop: true,
        autoSlide: true,
        autoSlideInterval: "10000",
        nextBtn: "<span class='iconArrowR16'></span>",
        prevBtn: "<span class='iconArrowL16'></span>",
        animSpeed: "slow"
    });


    // Modal popup

    var dialogBox = $("#dialogue-box").dialog({
        height: 360,
        width: 640,
        modal: true,
        draggable: false,
        resizable: false,
        autoOpen: false,
        show: "fade",
        hide: "fade"
    });

    dialogBox.parent().appendTo(jQuery("form:first"));

    // Readers page tabs

    $("#profileTabs, #phoneTabs, #imTabs, #emailTabs").tabs({
        event: "click",
        selected: 0
    });

    $("#imrTabs").tabs({
        event: "click",
        selected: -1
    });

    // Registration videos show and hide text function

    $(".rgsterVideo").hover(
        function() {
            rgsterText = $(this).children(".rgsterVideoTxt");
            $(rgsterText).stop().show("slide", { direction: "down" }, 200);
        },
        function() {
            rgsterText = $(this).children(".rgsterVideoTxt");
            $(rgsterText).stop().hide("slide", { direction: "down" }, 200);
        }
    );

    // Populate tooltip

    $('.tooltipOn').tipsy({ gravity: 's' });

    // Feedback box stuff

    // Animate on hover

    //$('.feedbackIconClosed').mouseover(function() {
    //    $(this).animate({ width: '+=10' }, 400);
    //}).mouseout(function() {
    //    $(this).animate({ width: '-=10' }, 400);
    //});

    $(".jQDatePicker").attr("readonly", true);
    $(".jQDatePicker").datepicker({
        dateFormat: "dd/mm/yy",
        changeMonth: true,
        changeYear: true,
        defaultDate: "-18y",
        maxDate: "-18y",
        firstDay: 1,
        showMonthAfterYear: true,
        yearRange: "c-80:c+80"
    });
});

function fixTipsy() {
    $('.tooltipOn').tipsy({ gravity: 's' });
}

function openFeedbackBox() {
    $('.lytFeedbackBox').animate({ left: '0' }, 400, function() {
        $('<div class="ui-overlay feedbackOverlay" style="display: none;"><div class="ui-widget-overlay"></div></div>').insertAfter('#feedbackBox');
        $('.feedbackOverlay').fadeIn(800);
        $('.feedbackIconClosed').hide();
        $('.feedbackIconOpen').show();
        $('.feedbackTitle').fadeIn(800);
        $('.feedbackContent').fadeIn(800);
    });
}

function closeFeedbackBox() {
    $('.feedbackTitle').fadeOut(300);
    $('.feedbackContent').fadeOut(300);
    $('.lytFeedbackBox').animate({ left: '-650px' }, 400, function() {
//        $('.feedbackIconOpen').hide();
//        $('.feedbackIconClosed').show();
    });
    $('.feedbackOverlay').fadeOut(800, function() {
        $('.feedbackOverlay').remove();
    });
}

//function feedbackButtonGood() {
//    $('#ctl00_FeedbackBoxUserControl_UserOption').val("new");
//    $('.feedbackOptions').fadeOut(300, function() {
//        $('.feedbackForm').fadeIn(300);
//        $('.feedbackBoxInner').animate({ height: '420px' }, 400);
//    });
//}

//function feedbackButtonBad() {
//    $('#ctl00_FeedbackBoxUserControl_UserOption').val("old");
//    $('.feedbackOptions').fadeOut(300, function() {
//        $('.feedbackForm').fadeIn(300);
//        $('.feedbackBoxInner').animate({ height: '420px' }, 400);
//    });
//}

// Open login popup

function openLoginBox() {
    $("#dialogue-box").dialog("open");
    return false;
}

// Reader tabs function

function openTab(tabsid, tabid, ptabsid) {    
    $(tabsid).tabs("select", tabid); // Setting the tab to visible
    $('#profileTabs').tabs("select", ptabsid); // Setting the parent tab to visible incase the current tab is outside
    $(".tabsSubNav a").closest("div", this).addClass("tabsSubNavHide"); // Hiding our
}

function closeCallMeNow() {
    $("#iframeCallMeNow").attr("src", "");
    $("#popupCallMeNow").dialog("close");
    return false;
}

function videoPlayer(streamURL, subfolder) {
    if (streamURL) {
        $(".videoTutorial").flash({
            swf: (subfolder ? "../" : "") + "assets/js/swfObject/MediaPlayer.swf",
            height: "480",
            width: "640",
            flashvars: {
                javascriptid: "FlashVideoPlayer",
                autostart: "true",
                showdigits: "false",
                height: "480",
                width: "640",
                enablejs: "true",
                shownavigation: "false",
                file: escape(streamURL)
            }
        });

        $(".videoPlayerPopUp").dialog("destroy");
        $(".videoPlayerPopUp").dialog(
        {
            modal: true,
            draggable: false,
            resizable: false,
            autoOpen: false,
            position: "center",
            show: "fade",
            hide: "fade",
            width: "665",
            height: "515",
            closeText: ""            
        });
        $(".videoPlayerPopUp").dialog("open");
        
        return false;
    }
}
