﻿function sanatize(str) {
    str = str.replace(/[~!@#$%^*()+=<>.|\[\]{}\",:;`?\\]/g, "");
    str = str.replace(/^\s+|\s+$/g, "");    
    return str;
}

function prepairUri(str) {
    str = str.toLowerCase();
    str = str.replace(/\s/g, "-");
    str = sanatize(str);
    str = str.replace(/&/g, "");
    str = str.replace(/\//g, "_");
    str = str.replace(/--/g, "-");
    str = str.replace(/:/g, "");
    str = str.replace(/\'/g, "");
    return str;
}

function clearAllTagged() {
    jQuery(".tagged").attr('value', '');
}

jQuery(document).ready(function () {
    jQuery("#subNav > ul ul").hide();
    jQuery("#subNav > ul ul").parent().prepend("<a class='plus' href='javascript:void(0)'></a>");

    jQuery(".plus:not(.hideSubNav)").live('click', function () {
        $(".plus").removeClass("hideSubNav");
        $("#subNav > ul ul").slideUp();
        $(this).parent().find('ul').slideDown();
        $(this).addClass("hideSubNav");
    });

    jQuery(".hideSubNav").live('click', function () {
        $(this).parent().find('ul').slideUp();
        $(this).removeClass("hideSubNav");
    });
});

(function ($) {
    var imgList = [];
    $.extend({
        preload: function (imgArr, option) {
            var setting = $.extend({
                init: function (loaded, total) { },
                loaded: function (img, loaded, total) { },
                loaded_all: function (loaded, total) { }
            }, option);
            var total = imgArr.length;
            var loaded = 0;

            setting.init(0, total);
            for (var i in imgArr) {
                imgList.push($("<img />")
					.attr("src", imgArr[i])
					.load(function () {
					    loaded++;
					    setting.loaded(this, loaded, total);
					    if (loaded == total) {
					        setting.loaded_all(loaded, total);
					    }
					})
				);
            }

        }
    });
})(jQuery);
