(function() {
    var m = document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand;
    try { if (!!m) { m('BackgroundImageCache', false, true); } }
    catch (oh) { };
    var u = navigator.userAgent.toLowerCase();
    var is = function(t) { return (u.indexOf(t) != -1) };
    jQuery('html').addClass([(!(/opera|webtv/i.test(u)) && /msie (\d)/.test(u)) ? ('ie ie' + RegExp.$1)
    : is('firefox/2') ? 'gecko firefox2'
    : is('firefox/3') ? 'gecko firefox3'
    : is('gecko/') ? 'gecko'
    : is('chrome/') ? 'chrome'
    : is('opera/9') ? 'opera opera9' : /opera (\d)/.test(u) ? 'opera opera' + RegExp.$1
    : is('konqueror') ? 'konqueror'
    : is('applewebkit/') ? 'webkit safari'
    : is('mozilla/') ? 'gecko' : '',
    (is('x11') || is('linux')) ? ' linux'
    : is('mac') ? ' mac'
    : is('win') ? ' win' : ''
    ].join(' '));
})();
var _nicchiStyleUrlCached = null;
function fnicchiGetStyleUrl() {
    if (null == _nicchiStyleUrlCached) {
        var ns;
        _nicchiStyleUrlCached = '';
        ns = jQuery('link');
        for (var i = 0; i < ns.length; i++) {
            var l = ns[i].href;
            if (l && /style\.ie6\.css(\?.*)?$/.test(l))
                return _nicchiStyleUrlCached = l.replace(/style\.ie6\.css(\?.*)?$/, '');
        }
        ns = jQuery('style');
        for (var i = 0; i < ns.length; i++) {
            var matches = new RegExp('import\\s+"([^"]+\\/)style\\.ie6\\.css"').exec(ns[i].html());
            if (null != matches && matches.length > 0)
                return _nicchiStyleUrlCached = matches[1];
        }
    }
    return _nicchiStyleUrlCached;
}
function fnicchiFixPNG(element) {
    if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
		var src;
		if (element.tagName == 'IMG') {
			if (/\.png$/.test(element.src)) {
				src = element.src;
				element.src = fnicchiGetStyleUrl() + 'images/spacer.gif';
			}
		}
		else {
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
			if (src) {
				src = src[1];
				element.runtimeStyle.backgroundImage = 'none';
			}
		}
		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "')";
	}
}
jQuery(function() {
    jQuery.each(jQuery('ul.nicchi-menu>li,ul.nicchi-vmenu>li'), function(i, val) {
        var l = jQuery(val); var s = l.children('span'); if (s.length == 0) return;
        var t = l.find('span.t').last(); l.children('a').append(t.html(t.text()));
        s.remove();
    });
}); 
jQuery(function() {
    jQuery.each(jQuery('ul.nicchi-menu>li:not(:last-child)'), function(i, val) {
        jQuery('<li class="nicchi-menu-li-separator"><span class="nicchi-menu-separator"> </span></li>').insertAfter(val);
    });
    if (!jQuery.browser.msie || parseInt(jQuery.browser.version) > 6) return;
    jQuery.each(jQuery('ul.nicchi-menu li'), function(i, val) {
        val.j = jQuery(val);
        val.UL = val.j.children('ul:first');
        if (val.UL.length == 0) return;
        val.A = val.j.children('a:first');
        this.onmouseenter = function() {
            this.j.addClass('nicchi-menuhover');
            this.UL.addClass('nicchi-menuhoverUL');
            this.A.addClass('nicchi-menuhoverA');
        };
        this.onmouseleave = function() {
            this.j.removeClass('nicchi-menuhover');
            this.UL.removeClass('nicchi-menuhoverUL');
            this.A.removeClass('nicchi-menuhoverA');
        };
    });
});
jQuery(function () {
    if (!jQuery.browser.msie || parseInt(jQuery.browser.version) > 7) return;
    var c = jQuery('div.nicchi-content');
    if (c.length !== 1) return;
    var s = c.parent().children('.nicchi-layout-cell:not(.nicchi-content)');
    jQuery(window).bind('resize', function () {
        if (c.w == c.parent().width()) return;
        var w = 0; c.css('width', "0");
        s.each(function () { w += this.clientWidth; });
        c.w = c.parent().width();c.css('width', c.w - w);
    }).trigger('resize');
    jQuery('div.nicchi-content-layout-row').each(function () {
        this.c = jQuery(this).children('.nicchi-layout-cell');
    }).bind('resize', function () {
        if (this.h == this.clientHeight) return;
        this.c.css('height', 'auto');
        this.h = this.clientHeight;
        this.c.css('height', this.h + 'px');
    }).trigger('resize');
});
jQuery(function() {
    jQuery('ul.nicchi-vmenu li').not(':first').before('<li class="nicchi-vsubmenu-separator"><span class="nicchi-vsubmenu-separator-span"> </span></li>');
    jQuery('ul.nicchi-vmenu > li.nicchi-vsubmenu-separator').removeClass('nicchi-vsubmenu-separator').addClass('nicchi-vmenu-separator').children('span').removeClass('nicchi-vsubmenu-separator-span').addClass('nicchi-vmenu-separator-span');
    jQuery('ul.nicchi-vmenu > li > ul > li.nicchi-vsubmenu-separator:first-child').removeClass('nicchi-vsubmenu-separator').addClass('nicchi-vmenu-separator').addClass('nicchi-vmenu-separator-first').children('span').removeClass('nicchi-vsubmenu-separator-span').addClass('nicchi-vmenu-separator-span');
});   
function fnicchiButtonSetup(className) {
    jQuery.each(jQuery("a." + className + ", button." + className + ", input." + className), function(i, val) {
        var b = jQuery(val);
        if (!b.parent().hasClass('nicchi-button-wrapper')) {
            if (!b.hasClass('nicchi-button')) b.addClass('nicchi-button');
            jQuery("<span class='nicchi-button-wrapper'><span class='nicchi-button-l'> </span><span class='nicchi-button-r'> </span></span>").insertBefore(b).append(b);
            if (b.hasClass('active')) b.parent().addClass('active');
        }
        b.mouseover(function() { jQuery(this).parent().addClass("hover"); });
        b.mouseout(function() { var b = jQuery(this); b.parent().removeClass("hover"); if (!b.hasClass('active')) b.parent().removeClass('active'); });
        b.mousedown(function() { var b = jQuery(this); b.parent().removeClass("hover"); if (!b.hasClass('active')) b.parent().addClass('active'); });
        b.mouseup(function() { var b = jQuery(this); if (!b.hasClass('active')) b.parent().removeClass('active'); });
    });
}
jQuery(function() { fnicchiButtonSetup("nicchi-button"); });
jQuery(function() {
    jQuery.each(jQuery('button'), function(i, button) {
        button.buttonName = button.getAttribute('name');
        button.buttonValue = button.getAttribute('value');
        button.prevOnClick = button.onclick;
        if (button.outerHTML) {
            var re = /\bvalue="([^"]+)"/i;
            button.buttonValue = re.test(button.outerHTML) ? re.exec(button.outerHTML)[1] : button.buttonValue;
        }
        button.setAttribute("name", "_" + button.buttonName);
        button.onclick = function() {
            if (this.prevOnClick) this.prevOnClick.apply(this);
            var f = this;
            while (f.tagName.toLowerCase() != "body") {
                if (f.tagName.toLowerCase() == "form") {
                    var subButton = document.createElement("input");
                    subButton.setAttribute("type", "hidden");
                    subButton.setAttribute("name", this.buttonName);
                    subButton.setAttribute("value", this.buttonValue);
                    f.appendChild(subButton);
                    return true;
                }
                f = f.parentNode;
            }
            return false;
        };
    });
});
jQuery(function() {
    var imgAssistElem = parent.document.getElementsByName("img_assist_header");
    if (null != imgAssistElem && imgAssistElem.length > 0) {
        imgAssistElem[0].scrolling = "no";
        imgAssistElem[0].style.height = "150px";
    }
});
