﻿var $ = jQuery.noConflict();
var options = {
    path: "/",
    Domain: "localhost",
    expires: 1
};
$(document).ready(function () {
    $('.cs-rounded').corner('5px');
    $('.cs-rounded-t').corner('tl tr 5px');
    $('.cs-rounded-b').corner('bl br 5px');
    $('.cs-rounded-l').corner('tl bl 5px');
    $('.cs-rounded-r').corner('tr br 5px');
    $('.cs-rounded-menu').corner('5px', '#cs-page-holder');
    var random = Math.floor(Math.random() * 9999)
    // <!--photo album preview-->
    $("img[alt2='photoalbumpreview']").each(function (i) {
        var folderID = $(this).attr("id");
        var imgPath = '/controls/familywebsite/media/PhotoAlbumPreview.ashx?folderID=' + folderID + "&sub=false";
        if ($(this).attr("sub") == "true") {
            var imgPath = '/controls/familywebsite/media/PhotoAlbumPreview.ashx?folderID=' + folderID + "&sub=true";
        }
        $(this).attr("src", imgPath);
    });
    $("img[alt1='photopreviewsimpleWithFamily']").each(function (i) {
        var fileName = $(this).attr("filename");
        var id = $(this).attr("pid");
        var familyid = $(this).attr("fid");
        var imgPath = '/controls/familywebsite/media/PhotoPreview.ashx?fileName=' + fileName + '&pid=' + id + "&fid=" + familyid;
        $(this).attr("src", imgPath);
    });
    $("img[alt1='photopreviewsimple']").each(function (i) {
        var fileName = $(this).attr("filename");
        var id = $(this).attr("pid");
        var imgPath = '/controls/familywebsite/media/PhotoPreview.ashx?fileName=' + fileName + '&pid=' + id;
        $(this).attr("src", imgPath);
    });
    $('#DashboardNewStuff').load('/controls/familywebsite/home/newstuff.aspx').fadeIn("slow");
    $('#DashboardMemberList').load('/controls/familywebsite/home/members.aspx').fadeIn("slow");
    $('#DashboardCalendar').load('/controls/familywebsite/home/calendar.aspx').fadeIn("slow");
    //$('#MembersGrid').load('/controls/familywebsite/members/membersgrid.aspx').fadeIn("slow");
    //$('#ExistingInvites').load('/controls/familywebsite/members/existinginvites.aspx').fadeIn("slow");
    //    $("img[alt2='addPhotoEditClick']:not(.loaded)").live('mouseover', function () {
    //    qTipEditPhoto(this);
    //    });
    $("img[alt2='addPhotoEditClickStatic']").click(function () {
        $("photoDetailsDiv").fadeIn("slow");
        $("#hideCommnets").hide();
        var pid = $(this).attr("pid");
        $('#photoDetails').load('/controls/familywebsite/media/PhotoDetails2.aspx?pid=' + pid).fadeIn('slow');
        $('#comments').load('/controls/familywebsite/media/Comments.aspx?pid=' + pid + "&itemtypeid=0").fadeIn('slow');
        //attached fancybox
        $('#PhotoCommentsDetails').show();
        updateProfilePics();
    });
    $("#photoLeftDiv").live('mouseover', function () {
        $("#photoLeftDiv").click(function () {
            var pid = $(this).attr("id");
            // <!--
            alert(id);
            // -->
        });
    });
    $("a[alt2='addPhotoEditClick']").live('mouseover', function () {
        $("a[alt2='addPhotoEditClick']").fancybox({
            'width': 560,
            'height': 500,
            'autoScale': false,
            'scrolling': 'no',
            'transitionIn': 'none',
            'transitionOut': 'none',
            'type': 'iframe'
        });
    });


    $(".videoImageItem").fancybox({
        'width': 655,
        'height': 495,
        'autoScale': false,
        'scrolling': 'no',
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });


    $("#various3").fancybox({
        'width': '75%',
        'height': '75%',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });

    $('#autoStart').fancybox({

    });

    $('#closeFancybox').click(function () {
        $.fancybox.close();
    });

    $("#pollSubmit").click(
            function () {

                var txtQuickQuestion = $(".qpQuestion").html();
                var txtQuickPoll = $(".qpAnswer").val();
                var displayName = '';

                $.ajax({
                    type: "POST",
                    url: "/Controls/FamilyWebsite/Services/FamilyService.asmx/AddQuickPoll",
                    data: "{response: '" + txtQuickPoll + "', question: '" + txtQuickQuestion + "', displayName: '" + displayName + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        // Replace the div's content with the page method's return.
                        //$("#txtQuickPoll").attr("value", msg.d);
                        //alert(msg.d);
                        //need to reload newstuff to show entry
                        $('#DashboardNewStuff').load('/controls/familywebsite/home/newstuff.aspx?newqp=1').fadeIn("slow");
                        //$('.GreenDiv').hide();// (2000).fadeOut(1000);
                    }
                });


                $.fancybox.close();
            });




    function qTipEditPhoto(photo) {
        $(this).addClass('loaded');
        var id = $(this).attr("id");
        $(this).qtip(
        {
            ready: true,
            content: {
                title: {
                    text: 'Edit Photo',
                    button: 'Close'
                },
                text: '<div id="photoDetailLoader" style="width:600px;" ><iframe frameborder="0" src="/controls/familywebsite/media/photoedit.aspx?"' + id + ' width="600" height="400">' +
                        '<p>Your browser does not support iframes.</p>' +
                        '</iframe></div>'
            },
            position: {
                target: $(document.body), // Position it via the document body...
                corner: 'center' // ...at the center of the viewport
            },
            show: {
                when: 'click', // Show it on click
                solo: true // And hide all other tooltips
            },
            hide: false,
            style: {
                width: { max: 600 },
                padding: '14px',
                border: {
                    width: 9,
                    radius: 9,
                    color: '#666666'
                },
                name: 'light'
            },
            api: {
                beforeShow: function () {
                    // Fade in the modal "blanket" using the defined show speed
                    $('#qtip-blanket').fadeIn(); //this.options.show.effect.length);
                },
                beforeHide: function () {
                    // Fade out the modal "blanket" using the defined hide speed
                    $('#qtip-blanket').fadeOut(); //this.options.hide.effect.length);
                }
            }
        });
    }
    //    $("img[alt2='addPhotoEditClick']").live('mouseover', function () {

    //    //$("#testtip").trigger();
    //    //attacheQtipPhoto("123");
    //    
    //    ("img[alt2='addPhotoEditClick']").qtip({
    //    overwrite: false, // Make sure another tooltip can't overwrite this one without it being explicitly destroyed
    //    content: 'I\'m a live qTip',
    //    show: {
    //    ready: true // Needed to make it show on first mouseover event
    //    }
    //    });
    //        

    //    });
    //    
    //    $("img[alt2='addPhotoEditClick']:not(.loaded)").live("click", function () {

    //    $(this).addClass('loaded');
    //    var id = $(this).attr("id");
    //    this.qtip(
    //    {
    //    content: '123 Some basic content for the tooltip' // Give it some content, in this case a simple string
    //    });

    //    //attacheQtipPhoto(id);
    //    });
    //    $("img[alt2='photopreview']").each(function () {
    //    $(this).live("hover", function () {
    //    var fileName = $(this).attr("filename");
    //    var id = $(this).attr("id");
    //    var imgPath = '/controls/familywebsite/media/PhotoPreview.ashx?fileName=' + fileName;
    //    $(this).attr("src", imgPath);
    //    });
    //    });
    //    $("img[alt2='photopreview']").each(function (i) {
    //    var fileName = $(this).attr("filename");
    //    var id = $(this).attr("id");
    //    var imgPath = '/controls/familywebsite/media/PhotoPreview.ashx?fileName=' + fileName;
    //    $(this).attr("src", imgPath);
    //    attacheQtipPhoto(this, id);
    //    });
    //    $("img[alt2='photopreview']:not(.loaded)").live("hover", function () {

    //    $(this).addClass('loaded');
    //    var id = $(this).attr("id");
    //    attacheQtipPhoto(this, id);
    //    });
    //    $("img[alt2='photopreview']:not(.loaded)").live("click", function () {

    //    $(this).addClass('loaded');

    //    var fileName = $(this).attr("filename");
    //    var id = $(this).attr("id");
    //    var imgPath = '/controls/familywebsite/media/PhotoPreview.ashx?fileName=' + fileName;
    //    $(this).attr("src", imgPath);
    //    //        attacheQtipPhoto(id);
    //    });
    function attacheQtipPhoto(id) {

        $("#triggerTest").qtip(
        {
            content: {
                title: {
                    text: 'Edit Photo',
                    button: 'Close'
                },
                text: '<div style="width:600px;" ><iframe frameborder="0" src="/controls/familywebsite/media/photoedit.aspx?pid=' + id + '" width="600" height="400">' +
                        '<p>Your browser does not support iframes.</p>' +
                        '</iframe></div>'
            },
            position: {
                target: $(document.body), // Position it via the document body...
                corner: 'center' // ...at the center of the viewport
            },
            show: {
                when: 'click', // Show it on click
                solo: true // And hide all other tooltips
            },
            hide: false,
            style: {
                width: { max: 600 },
                padding: '14px',
                border: {
                    width: 9,
                    radius: 9,
                    color: '#666666'
                },
                name: 'light'
            },
            api: {
                beforeShow: function () {
                    // Fade in the modal "blanket" using the defined show speed
                    $('#qtip-blanket').fadeIn(); //this.options.show.effect.length);
                },
                beforeHide: function () {
                    // Fade out the modal "blanket" using the defined hide speed
                    $('#qtip-blanket').fadeOut(); //this.options.hide.effect.length);
                }
            }
        })
    }
    $('<div id="qtip-blanket">').css({
        position: 'absolute',
        top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
        left: 0,
        height: $(document).height(), // Span the full document height...
        width: '100%', // ...and full width
        opacity: 0.7, // Make it slightly transparent
        backgroundColor: 'black',
        zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
    })
      .appendTo(document.body) // Append to the document body
      .hide(); // Hide it initially
    $("img[imgtype='profilepic']").each(function (i) {
        var id = $(this).attr("userid");
        var imgPath = '/controls/common/handlers/UserProfilePhoto.ashx?id=' + id;
        //$(this).attr("src", imgPath);
    });
    function LoadPhotoDetails(photoFileName) {
        $("#photoDetails").append(photoFileName);
    }
    $("#btnSelectFolder").click(function () {
        $("#divFolders").slideToggle();
    });
    $("#divFoldersClose").click(function () {
        $("#divFolders").slideUp();
    });
    $("#btnSelectFolder").click(function () {
        $("#btnOptions").slideToggle();
    });
    $("#dnn_ctr376_ModuleLoaderDNN_upload_RadioButtonList1_1").click(function () {
        $("#divExistingFolder").show();
        $("#divNewFolder").hide();
    });
    $("#dnn_ctr376_ModuleLoaderDNN_upload_RadioButtonList1_0").click(function () {
        //$("#divExistingFolder").hide();
        //$("#divNewFolder").show();
    });
    //    var dockOptions =
    //    { align: 'left' // vertical menu, with expansion RIGHT from a fixed LEFT edge
    //    , size: 48  // set the maximum minor axis (horizontal) image dimension to 60px
    //    , labels: 'mc'  // add labels (defaults to 'br')
    //    };
    //    $("#menu").jqDock(dockOptions);
    //    $("a[alt2='addPhotoEditClick']").fancybox({
    //    'width': 560,
    //    'height': '75%',
    //    'autoScale': false,
    //    'transitionIn': 'none',
    //    'transitionOut': 'none',
    //    'type': 'iframe'
    //    });
    function testCall() {
        // <!--
        alert("go!");
        // -->
    }
    $("#btnSavePhoto").click(
            function () {
                //save data
                $.post("/controls/familywebsite/media/processjquerypost.aspx", { item1: $("#txtName").val(), item2: $("#txtDescription").val(), type: "photoedit" },
                   function (data) {

                       //$("#Result").html(data).slideDown(400);
                       //update panel
                       //var pid = $(this).attr("pid");
                       //$('#photoDetails').load('/controls/familywebsite/media/PhotoDetails.aspx?pid=' + pid).fadeIn('slow');
                   });
                var pid = $(this).attr("pid");
                parent.$('#photoDetails').load('/controls/familywebsite/media/PhotoDetails.aspx?pid=' + pid).fadeIn('slow');
                parent.$.fancybox.close();
            });
    $("#hypUploadNext2").click(function () {
        var folder = $("#dnn_ctr376_ModuleLoaderDNN_upload_PhotoMove1_txtFolder").val();
        $("#popupContent").html("<h1>Please select a folder</h1>");
        $("#popup1").fancybox().trigger('click')
    });
    //    $("#popup1").fancybox({
    //    'transitionIn': 'none',
    //    'transitionOut': 'none'
    //    });
    // bind to button click
    //    $("input").click(apiHandler)
    //    $("#togglePlay").click(apiHandler)
    //    $("#txtComment").focus(function () {
    //        api.pause();
    //        $("#togglePlayImage").attr("src", "/images/play.png")
    //    });
    //    function apiHandler(e) {

    //        if ($("#togglePlayImage").attr("src") == "/images/pause.png") {
    //            api.pause();
    //            $("#togglePlayImage").attr("src", "/images/play.png")
    //        }
    //        else {
    //            api.resume();
    //            $("#togglePlayImage").attr("src", "/images/pause.png")
    //        }
    //        return false;
    //    }
    $("#btnAddcomment").click(function () {
        var pid = $("#lblPhotoID").html();
        $.post("/controls/familywebsite/media/processjquerypost.aspx", { item1: pid, item2: $("#txtComment").val(), type: "comment" },
                   function (data) {
                       $("#Result").html(data).slideDown(400);
                       //reload comments
                       $('#comments').load('/controls/familywebsite/media/Comments.aspx?pid=' + pid + "&itemtypeid=0").fadeIn('slow');
                       $('#txtComment').val("");
                       $('#Result').val("");
                       //hide success message
                       $("#Result").delay(4000).slideUp();
                   });
        return false;
    });
    function updateProfilePics() {
        $("img[imgtype='profilepic']").each(function (i) {
            var id = $(this).attr("userid");
            var imgPath = '/controls/common/handlers/UserProfilePhoto.ashx?id=' + id;
            $(this).attr("src", imgPath);
        });
    }
    $("#updateProfilePics").click(function () {
        updateProfilePics();
    });



    $("img[imgtype='photocollage']").each(function (i) {
        var batchid = $(this).attr("batchid");
        var imgPath = '/controls/familywebsite/media/PhotoCollage.ashx?batchid=' + batchid;
        $(this).attr("src", imgPath);
    });
    // get public API from slider
    //var api = $(".peKenBurns").peKenburnsSlider({ api: true })
});

function fnChangeFD(obj) {    
    window.location.href = "/controls/familywebsite/home/ChangeFamily.aspx?fid=" + obj.value;
}
function fnshowImg(obj) {
    var temp = document.getElementById(obj).src;
    var temp2 = new Array();
    temp2 = temp.split('/');
    if ("icomin_Minimalist.png" == temp2[temp2.length - 1]) {
        document.getElementById(obj).src = "/images/icomax_Minimalist.png";
    }
    else {
        document.getElementById(obj).src = "/images/icomin_Minimalist.png";
    }
}
