﻿$(document).ready(function () {
    // put all your jQuery goodness in here.
    $('#loginArea a').hover(function () { $(this).stop().animate({ backgroundColor: '#2B5A8B' }, 300) }, function () { $(this).stop().animate({ backgroundColor: '#A4AC3B' }, 200) });
    $('.cta a').hover(function () { $(this).stop().animate({ backgroundColor: '#A4AC3B' }, 300) }, function () { $(this).stop().animate({ backgroundColor: '#2B5A8B' }, 200) });
    $('#topLinks ul li a').hover(function () { $(this).stop().animate({ color: '#A4AC3B' }, 400) }, function () { $(this).stop().animate({ color: '#2B5A8B' }, 200) });
    $('#loginArea a #logout').parent().css({ 'background-color': '#999' }).hover(function () { $(this).stop().animate({ backgroundColor: '#2B5A8B' }, 300) }, function () { $(this).stop().animate({ backgroundColor: '#999' }, 200) }); ;
    $('.memberLinks a').hover(function () { $(this).stop().animate({ color: '#2B5A8B' }, 150) }, function () { $(this).stop().animate({ color: '#fff' }, 200) });
    $('.column').fixHeight();
    var dlgInstrustions = $('#instructionPane').dialog({ autoOpen: false, width: 700 });
//    $('.question').click(function () {
//        dlgInstrustions.dialog("open");
//    });
    var dlgFrgtPass = $('.forgotPassword').dialog({ autoOpen: false, width: "auto", show: "blind", title: $('#forgotPasswordTitle').html() });
    dlgFrgtPass.parent().appendTo($("form:first"));
    $('#forgotPasswordTitle').hide();
    $("#PasswordRecoveryLink").click(function (event) {
        event.preventDefault();
        dlgFrgtPass.dialog("open");
    });
    $('input:submit').button().css("color", "#fff");
    $('input:button').button().css("color", "#fff");
    $("id$=['rblQRCodes']").buttonset();

    //JobPosting
    $('.postingSection').hide();
    $('.postingSection:first').show();
    $('input#btnNext').click(function () {
        if (Page_ClientValidate('posting'))
            $(this).parent().slideToggle("slow").next().slideToggle("slow");
    });
    $('input#btnPrevious').click(function () {
        $(this).parent().parent().slideToggle("slow").prev().slideToggle("slow");
    });
    $('.highlight').focus(function () {
        $(this).parent().parent().parent().stop().animate({
            backgroundColor: "#ececec"
        }, 500);
    });
    $('.highlight').blur(function () {
        $(this).parent().parent().parent().stop().animate({
            backgroundColor: "transparent"
        }, 300);
    });
    $('.button').button().css("font-size", 12).css("color", "#fff");
    $('input:submit').button().css("font-size", 12);
    $("input:submit[id$='Login']").button().css("font-size", "1.3em");
    $('#btnNext').button({ icons: { secondary: "ui-icon-circle-triangle-e"} }).css("font-size", 12);
    $('#btnPrevious').button({ icons: { primary: "ui-icon-circle-triangle-w"} }).css("font-size", 12);
    $('.datepicker').datepicker();
    /*Style Tables with jQuery UI*/
    $(".postingTable th").each(function () { $(this).addClass("ui-state-default"); });
    //$("#postingTable td").each(function() { $(this).addClass("ui-widget-content"); });
    $(".postingTable tr").hover(function () { $(this).children("td").addClass("ui-state-hover"); }, function () { $(this).children("td").removeClass("ui-state-hover"); });
    $(".postingTable tr").click(function () { $(this).children("td").toggleClass("ui-state-highlight"); });

    $(".clsproducts th").each(function () { $(this).addClass("ui-state-default"); });
    //$(".clsproducts td").each(function() { $(this).addClass("ui-widget-content"); });
    $(".clsproducts tr").hover(function () { $(this).children("td").addClass("ui-state-hover"); }, function () { $(this).children("td").removeClass("ui-state-hover"); });
    $(".clsproducts tr").click(function () { $(this).children("td").toggleClass("ui-state-highlight"); });

    $(".myPosting th").each(function () { $(this).addClass("ui-state-default"); });
    //$(".myPosting td").each(function() { $(this).addClass("ui-widget-content"); });
    $(".myPosting tr").hover(function () { $(this).children("td").addClass("ui-state-hover"); }, function () { $(this).children("td").removeClass("ui-state-hover"); });
    $(".myPosting tr").click(function () { $(this).children("td").toggleClass("ui-state-highlight"); });



    $("[id$='chkbxCheque']").click(function () {
        $("[id$='pnlCreditCard']").slideToggle();
        $("[id$='pnlCardExists']").slideToggle();
    });

    $('.tablehighlight').focus(function () {
        $(this).parent().parent().stop().animate({
            backgroundColor: "#b7c5d0"
        }, 500);
    });
    $('.tablehighlight').blur(function () {
        $(this).parent().parent().stop().animate({
            backgroundColor: "transparent"
        }, 300);
    });



    //QRCode Generation
    if ($("input:radio[name$='rblQRCodes']")) {
        var selected = $("input:radio[name$='rblQRCodes']:checked").val();
        var orginalQRImage = $('img#qrCode').attr('src');
        var url;

        chooseQRAction(selected);
        $(':input').focusout(function () { chooseQRAction(selected); });
        $("input:radio[name$='rblQRCodes']").change(function () {
            selected = $("input:radio[name$='rblQRCodes']:checked").val();
            chooseQRAction(selected);
        });
    }
    function chooseQRAction(selected) {
        if (selected === "0") {
            createVCardQR();
        } else if (selected === "1") {
            createUrlQR();
        } else {
            noQR();
        }
    }
    function noQR() { $('img#qrCode').attr('src', orginalQRImage); }
    function createUrlQR() { url = "http://www.sparqcode.com/qrgen?qt=url&data=" + $("[id$='Web']").val(); $('img#qrCode').attr('src', url); }
    function createVCardQR() {
        url = "http://www.sparqcode.com/qrgen?qt=vcard" +
        "&fName=" + $("[id$='FirstName']").val() +
        "&lName=" + $("[id$='LastName']").val() +
        "&company=" + $("[id$='Company']").val() +
        "&title=" + $("[id$='Title']").val() +
        "&tel=" + $("[id$='Phone']").val() +
        "&fax=" + $("[id$='Fax']").val() +
        "&address=" + $("[id$='Address']").val() + " " + $("[id$='Address2']").val() +
        "&city=" + $("[id$='City']").val() +
        "&state=" + $("[id$='States'] option:selected").val() +
        "&zip=" + $("[id$='PostalCode']").val() +
        "&country=" + $("[id$='Country'] option:selected").val() +
        "&email=" + $("[id$='UserName']").val() +
        "&url=" + $("[id$='Web']").val();

        $('img#qrCode').attr('src', url);
    }
    //END QRCode Generation
    var options = {
        'maxCharacterSize': 200,
        'textFontSize': '12px',
        'textColor': '#5C2306',
        'textFamily': 'Tahoma,sans-serif',
        'textAlign': 'right',
        'warningColor': '#CC3300',
        'warningNumber': 40,
        'isCharacterCount': true,
        'isWordCount': false
    };
    $("[id$='taDescription']").textareaCount(options);

    $('.whoIsComing').button({ icons: { primary: "ui-icon-help", secondary: "ui-icon-newwin"} }).css("color", "#fff");
    $('.linkButtonSubmit').button({ icons: { secondary: "ui-icon-circle-triangle-e"} }).css("color", "#fff");
    $('.question').button({ icons: { primary: "ui-icon-help" }, text: false });
    var questionTitle = $('.instructionPane h3');
    var questionDlg = $('.instructionPane').dialog({ autoOpen: false, width: 700, show: "blind", title: questionTitle.text() });
    questionTitle.hide();
    $('.question').click(function (event) {
        event.preventDefault();
        questionDlg.dialog("open");
    });

    $(".linkButton").button().css("color", "#fff");
    //$('.linkButton').button({ icons: { secondary: "ui-icon-circle-triangle-e"} });
    $('.eventDetailsItem').hide();
    $('.eventDetails span').button({ icons: { primary: "ui-icon-circle-plus"} }).click(function (event) {
        event.preventDefault();
        $(this).next().toggle();
	$('.column').fixHeight();
        $(this).toggleClass("clicked");
        
        if ($(this).hasClass("clicked"))
            $(this).button("option", "icons", { primary: "ui-icon-circle-minus" }).css("color", "#fff");
        else
            $(this).button("option", "icons", { primary: "ui-icon-circle-plus" }).css("color", "#fff");

    }).css("font-size", 11);
    $("#tabs").tabs();

    $(".modalOpen").click(function (event) {
        event.preventDefault();
        var url = $(this).attr("href");
        var title = $(this).attr('title')
        var newDiv = $('<iframe frameBorder="0"></iframe>').attr('src', url).dialog({
            title: title,
            width: 560,
            height: 370,
            modal: true
        }).css({ width: "530px", height: "350px" });

    });
    //    $("#linksResources ul").hide();
    //    $("#linksResources h4").click(function (e) {
    //        e.preventDefault();
    //        $(this).next().slideToggle();
    //        $(this).toggleClass("clicked");
    //    });
    $(".accordion").accordion({
        autoHeight: false,
        collapsible: true,
        active: false
    });

    //Image rotator | Assumes images are in '/images/VRA/Banner' 
    //set image names
    var imageArr = ["banner_bear.jpg", "banner_bcflag.jpg", "banner_canadaplace.jpg", "banner_forest.jpg", "banner_inushuk.jpg", "banner_orca.jpg", "banner_scienceworld.jpg", "banner_bridge.jpg", "banner_totem.jpg", "banner_vancouver.jpg", "banner_victoria.jpg", "banner_trail.jpg"];
    //shuffle the order
    imageArr = $.shuffle(imageArr);
    var imageLength = imageArr.length;
    var cache = [];
    //preload the images
    for (var i = 0; i < imageLength; i++) {
        var cacheImage = document.createElement('img');
        cacheImage.src = "/images/VRA/" + imageArr[i];
        cache.push(cacheImage);
    }

    $(function () {
        //pull the images from the array andpu them back at the end with fades
        $('#imageSlideShow').append("<img src='/images/VRA/" + imageArr.splice(0, 1) + "'>");
        setInterval(function () {
            var imageName = $('#imageSlideShow :first-child').attr('src').split("\/")[3];
            imageArr.push(imageName);
            $('#imageSlideShow :first-child').fadeOut(1500, function () {
                $(this).remove();
            });
            var item = $("<img src='/images/VRA/" + imageArr.splice(0, 1) + "'>");
            $('#imageSlideShow').append(item.hide().fadeIn(1000));
        },
      5000);
    });
    //End Image Rotator
    //TextShadows for IE
    //    $('#loginArea a').textShadow();
    $('.rssReadMore').textShadow();
    $('.footer a').textShadow();
    $('.CopyRightHolder').textShadow();
    //    $('#postingHeader h1').textShadow();
    //    $('.postingSection h2').textShadow();
    //    $('.form #header h1').textShadow();
    //    $('.form .postingSection h2').textShadow();
    $('h1').textShadow();
    $('h2').textShadow();
    $('#topLinks ul li a').textShadow();
    //    $('.regSteps').textShadow();
});

