General.subscript = {
    init: function() {
        this.preparePng();
        this.prepareFlash();
        this.prepareSearch();
        this.prepareSubscribe();
        this.prepareIE6DropMenu();
        this.prepareSalesContact();
        this.prepareRelatedDocument();
        this.prepareSalesContactList();
        this.prepareEmailTransform();
    },
    preparePng: function() {
        $.ifixpng('image/pixel.gif');
        $('.png').ifixpng();
    },
    prepareFlash: function() {
        General.tools.embedFlash($('#ctl00_ctl00_MainContentPlaceHolder_StartPageContentPlaceHolder_StartPageFlash_flash').attr('rel'), 'ctl00_ctl00_MainContentPlaceHolder_StartPageContentPlaceHolder_StartPageFlash_flash', '1005', '298');
    },
    prepareEmailTransform: function() {
        $('.email').each(function() {
            var $email = $(this);
            var address = $email.text()
                .replace(/\s*\[at\]\s*/, '@')
                .replace(/\s*\[dot\]\s*/g, '.');
            $email.html('<a href="mailto:' + address + '">'+ address +'</a>');
        });
    },
    prepareSearch: function() {
        $('#search-button').click(function() {
            $('#search-field').focus();

            var q = $.trim($('#search-field').val());

            if (q.length > 1)
                window.location.href = '/en/search/' + q;

            return false;
        });

        $('#search-field').focus(function() {
            if ($(this).val() == this.defaultValue) {
                $(this).val('');
            }
        }).blur(function() {
            if ($(this).val() == '') {
                $(this).val(this.defaultValue);
            }
        }).keydown(function(e) {
            if (e.keyCode == 13) {
                var q = $.trim($('#search-field').val());

                if (q.length > 1)
                    window.location.href = '/en/search/' + q;

                return false;
            }
        });
    },
    prepareSubscribe: function() {
        $('#subscription .text-input').focus(function() {
            if ($(this).val() == this.defaultValue) {
                $(this).val('');
            }
        }).blur(function() {
            if ($(this).val() == '') {
                $(this).val(this.defaultValue);
            }
        });
    },
    prepareIE6DropMenu: function() {
        if (typeof document.body.style.maxHeight === 'undefined') {
            $('.top-menu li').hover(
                function() {
                    $(this).addClass('hover');
                },
                function() {
                    $(this).removeClass('hover');
                }
            );
        }
    },
    prepareSalesContact: function() {
        $('.sales-contact a').click(function(){
            $( '.background' ).show();
            $( '.lightbox' ).show();
            $( '.contact-form' ).show();
            return false;
        });
        $('.contact-form .close-button').click(function(){
            $( '.contact-form' ).hide();
            $( '.lightbox' ).hide();
            $( '.background' ).hide();
            return false;
        });
    },
    prepareRelatedDocument: function() {
        $('.request-form .close-button').click(function(){
            $( '.request-form' ).hide();
            $( '.lightbox' ).hide();
            $( '.background' ).hide();
            return false;
        });
    },
    prepareSalesContactList: function() {
        $('#oglSalesContact').change(function(){
            var groupId = $('option:selected', this).val();
           //var name = /\(([^)]+)\)/gi.exec($('option:selected', this).text())[1].replace(' ', '-');
           if(groupId>0) {
               $('.contact-area').hide();
               $('.hide').hide();
               $('.group' + groupId).show();
           }
           else {
               $('.contact-area').show();
               $('.hide').show();
           }
           return false;
        });
    }
    
}
$( 'document' ).ready( function(){
	General.subscript.init();
} );
