var onLoadReiterNum = 1;

document.addEvent('domready',function(){
    var reiter = $$('.reiter1');

    if(reiter.length > 0){
        reiter.each(function(r){
            r.setStyle('display','block');
        });
        showContent(onLoadReiterNum);
    }

    $('print').setStyle('display','inline');
    $('print').getChildren('a')[0].set('href','javascript: window.print();');
    $$('.hideIfJS').setStyle('display','none');

    $$('div.news a').each(function(e){
        var src = 2;
        e.getParent('div.news').addClass('showPointer').addEvent('click',function(){ window.location.href = e.getProperty('href'); });
    })

    regio.create();


    $$('dt a[href*=tx_cms_showpic]').each(function(e){
        var u = new URI(e.href);
        e.setProperties({
            'href': u.get('data').file,
            'rel':  'lightbox',
            'onclick': 'return false'
        })
        return false;
        //http://hitachidev.testfactor.de/index.php?eID=tx_cms_showpic&file=uploads%2Fpics%2F01.l74m.jpg&width=800&height=600m&bodyTag=%3Cbody%20style%3D%22margin%3A0%3B%20background%3A%23fff%3B%22%3E&wrap=%3Ca%20href%3D%22javascript%3Aclose%28%29%3B%22%3E%20%7C%20%3C%2Fa%3E&md5=d247bf4b7c9f3a737fb6a0278928cc32
    });


    new QuickBox();
});



var regio = {
    allowKill: false,
    kill: function(){
        if(regio.allowKill) $('regio').fade('out');
    },
    create: function(){
        var el = new Element('div',{
            id: 'regio'
        });
        var countries = [
            ['flag_eu',             'http://www.hitachi-medical-systems.com',   'European Headquarters',    '/about-hitachi/hitachi-medical-systems/dealers.html', 'Dealer Network'],
            ['flag_france',         'http://www.hitachi-medical-systems.fr',    'France',                   '/about-hitachi/hitachi-medical-systems/dealers.html', 'Dealers'],
            ['flag_great_britain',  'http://www.hitachi-medical-systems.co.uk', 'Great Britain',            '/about-hitachi/hitachi-medical-systems/dealers.html', 'Dealers'],
            ['flag_spain',          'http://www.hitachi-medical-systems.es',    'Spain',                    '/about-hitachi/hitachi-medical-systems/dealers.html', 'Dealers'],
            ['flag_netherlands',    'http://www.hitachi-medical-systems.nl',    'Netherlands',              '/about-hitachi/hitachi-medical-systems/dealers.html', 'Dealers'],
            ['flag_hungary',        'http://www.hitachi-medical-systems.hu',    'Hungary',                  '/about-hitachi/hitachi-medical-systems/dealers.html', 'Dealers'],
            ['de',                  'http://www.hitachi-medical-systems.de',    'Germany',                  '/hitachi/hitachi-medical-systems/haendler.html', 'H&auml;ndler'],
            ['at',                  'http://www.hitachi-medical-systems.at',    'Austria',                  '/hitachi/hitachi-medical-systems/haendler.html', 'H&auml;ndler'],
            ['ch',                  'http://www.hitachi-medical-systems.ch',    'Swiss',                    '/hitachi/hitachi-medical-systems/haendler.html', 'H&auml;ndler']
        ];
        dealerUrl = "";
        dealerTxt = "";
        countries.each(function(c,i){
            var cl = '';
            if(i==0){
                if($('claim').get('html')==c[2] || (i == 0 && $('claim').get('html') == 'Europe' && true)) {
                    var cl='cur';
                    dealerUrl = c[3];
                    dealerTxt = c[4];
                }

                var div = new Element('a',{
                    html: '<img src="http://www.hitachi-medical-systems.com/portal/48/'+c[0]+'.gif" /> '+c[2],
                    'class': cl,
                    target: '_blank',
                    href: c[1]
                }).inject(el);
            } else {
                if($('claim').get('html')==c[2]) {
                    var cl='cur';
                    dealerUrl = c[3];
                    dealerTxt = c[4];
                }

                var div = new Element('a',{
                    html: '<img src="http://www.hitachi-medical-systems.com/portal/32/'+c[0]+'.gif" /> '+c[2],
                    'class': cl,
                    target: '_blank',
                    href: c[1]
                }).inject(el);
            }
        });
        if(dealerUrl.length > 0 && dealerTxt.length > 0) {
            var dealer = new Element('a', {
                html: '<img src="http://www.hitachi-medical-systems.com/portal/32/handshake.gif" /> '+dealerTxt,
                href:dealerUrl,
                'class': 'dealer'
            });
            dealer.inject(el);
        }





        el.addEvents({
            mouseenter: function(){
                regio.allowKill = false;
            },
            mouseleave: function(){
                regio.allowKill = true;
                regio.kill.delay(500);
            }
        });
        $('region').setStyle('position','relative');
        $('region').addEvent('click',function(e){
            e.stopPropagation();
            e.preventDefault();
            if($('regio')){
                $('regio').fade('in');
            } else {
                el.inject(
                    $('region'),'after'
                ).position({
                    relativeTo: $('region'),
                    position: 'bottomLeft',
                    edge: 'upperLeft'
                }).fade('hide').fade('in');
            }

        })
    }
}



function showContent(myNum){
    var list = $$('.reiterContent');
    var active = false;
    list.each(function(e){
        if(e.id=='content_'+myNum || myNum=='all'){
            e.style.display = 'block';
            if(myNum!='all') $('rcontent_'+myNum).className = 'aktiv';
            active = true;
        } else {
            e.style.display = 'none';
            $('r'+e.id).className = '';
        }
    })
    if(!active) showContent(1);
    //return false;
}


function showHide(elName,switchTo){
    el = $(elName);
    if(!switchTo) switchTo = 'block';
    if(el){
        el.setStyle('display',(el.getStyle('display')=='none' ? switchTo : 'none'));
        return true;
    }

    return false;
}

function hideAll() {
	$$('div.hideIfJS').setStyle('display', 'none');
}
