﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />
$(document).ready(function() {
    var controls = $(".controls-container .control");
    homam.controls = controls;
    var allTags = new Array();
    controls.each(function() {
        var t = $(this);
        var tags = t.attr(homam._TAGS_NS).split(',');
        for (var j = 0; j < tags.length; j++) {
            var tag = tags[j];
            var alreadyExists = false;
            for (var i = 0, length = allTags.length; i < length; i++)
                if (allTags[i] == tag) {
                alreadyExists = true;
                break;
            }
            if (!alreadyExists)
                allTags.push(tag);
        }
    });
    homam.allTags = allTags;
    controls.click(homam.control);

    homam.showFullElement = $("#show_full");
    homam.showFullElement.attr("checked", false);
    homam.showFullElement.click(homam.controlFullDescriptions);
    homam.control();

    $(".controls-container .info").mouseover(function() {
        $(".me").slideDown('normal');
        $(".controls-container .info").hide();
    });
    $(".me").mouseover(function() {
        this.mouseover = true;
    });
    $(".me").mouseout(function() {
        var t = $(this);
        this.mouseover = false;
        var _this = this;
        setTimeout(function() {
            if (!_this.mouseover) {
                $(".me").slideUp('normal', function() {
                    $(".controls-container .info").show();
                });
            }
        }, 1000);
    });

    $(".imageGallery").hide();
    $(".gallery-link").click(function() {
        $(".imageGallery").slideDown('slow');
        var t = $(this);
        var photoId = t.attr("homam:photoId");
        if (!photoId) {
            photoId = $._wingooliPhotoGallery.galleries[0].groups[0].pics[0].id;
        }
        $._wingooliPhotoGallery.galleries[0].selectPhotoById(photoId);
    });
    $(".gallery-hide").click(function() {
        $(".imageGallery").slideUp('normal');
    });
});

homam = {};
homam._TAGS_NS = "homam:tags";
homam.allTags = new Array();
homam.controls = null;
homam.controlTags = function(tagsToShow, tagsToHide) {
    for (var i = 0, l = tagsToHide.length; i < l; i++)
        homam.hide($(("." + tagsToHide[i])));

    for (var i = 0, l = tagsToShow.length; i < l; i++)
        homam.show($(("." + tagsToShow[i])));

    homam.controlFullDescriptions();
};

homam.hide = function(j) {
    if (!homam.printMode)
        j.addClass("disabled");
    else
        j.hide();
}

homam.show = function(j) {
    j.removeClass("disabled");
    j.show();
}

homam.showFullElement = null;

homam.controlFullDescriptions = function() {
    var t = homam.showFullElement;
    var fulls = $(".full");
    if (t.attr("checked"))
        fulls.show();
    else
        fulls.hide();
}

homam.control = function() {
    var tagsToHide = new Array();
    var tagsToShow = new Array();
    homam.controls.each(function() {
        var t = $(this);
        var tags = t.attr(homam._TAGS_NS).split(',');
        for (var j = 0; j < tags.length; j++) {
            var tag = tags[j];
            if (t.attr("checked")) {
                tagsToShow.push(tag);
            } else {
                tagsToHide.push(tag);
            }
        }
    });
    homam.controlTags(tagsToShow, tagsToHide);
}

homam.printMode = false;