﻿var Site = function() {
    var HANDLER_URL = "Handlers/FontHAndler.ashx?txt={txt}&size={size}&font={font}&color={color}&bgcolor={bgcolor}";
    var VIEWER_URL = "Flash/video_player.swf?file={file}";
    function initFontishTitles() {
        $$(".fontish").each(function(el) {
            return alert(h(el.getStyles("font-size", "color", "font-family", "background-color")));
            new Element("img", {
                src: HANDLER_URL.substitute({
                    txt: el.get("text"),
                    size: el.getStyle("font-size").toInt(),
                    font: el.getStyle("font-family"),
                    color: el.getStyle("color").substr(1),
                    bgcolor: el.getStyle("background-color").substr(1)
                })
            })
        });
    }
    function initSearch() {
        var searchForm = $("headerSerchForm");
        if (searchForm) {
            var searchLink = searchForm.getElement("a").get("href");
            searchForm.addEvent("submit", function(e) {
                location.href = searchLink + "/" + encodeURIComponent($("headerSearch").value.replace(/^\s*|\s*$/g, ''));
                e.stop();
            });

            searchForm.getElement(".fontimage").addEvent("click", function(e) {
                location.href = searchLink + "/" + encodeURIComponent($("headerSearch").value.replace(/^\s*|\s*$/g, ''));
                e.stop();
            });
        }
    }
    function initFlash() {
        var flashDivs = $$('div.Flash');
        flashDivs.each(function(div) {
            var link = div.getElement('a');
            if (link) {
                var flash = link.get('href');
                var id = "flash-" + link.innerHTML;
                var obj = new Swiff(VIEWER_URL.substitute({ file: flash }), {
                    width: 430,
                    height: 389,
                    id: id,
                    bgcolor: '#000000',
                    container: div,
                    params: {
                        allowFullScreen: true,
                        wMode: null
                    }
                });
                window[id] = $(id);
            }
        });
    }

    function initLanguageMenuScroller() {

        var isWebKit = Browser.Engine.webkit;
        var isIE6 = Browser.Engine.trident && Browser.Engine.version == 4;
        var isBrowserSupportsScoller = true; //!(isIE6); //isWebKit ||

        try {
            if (isBrowserSupportsScoller) {
                new UvumiScrollbar("lang-dropdown");
            }
        }
        catch (e) {
        }

    }

    function init() {
        initSearch();
        //initFontishTitles();
        if ($("lang-dropdown") != null)
            initLanguageMenuScroller();
        initFlash();
    }
    $domready(init);
} ();

Element.Properties.html = {set: function(){
	var tagName = this.get('tag'), html = Array.flatten(arguments).join('');
	if (Browser.Engine.trident && Element.Properties.insertionTranslations[tagName]) {
		var node = new Element('div', {html: Element.Properties.insertionTranslations[tagName].replace('*', html) });
		return node.getElement(tagName).replaces(this);
	} else {
		return this.innerHTML = html;
	}
}};

Element.Properties.insertionTranslations = {
    table: '<table>*</table>',
    tbody: '<table><tbody>*</tbody></table>',
    tr: '<table><tbody><tr>*</tr></tbody></table>',
    td: '<table><tbody><tr><td>*</td></tr></tbody></table>',
    select: '<select>*</select>'
};
