
/* Kinyithato/becsukhato tartalom */
function toggleElement(e) {
   if(e && e.style) {
      if(e.style.display == 'none') {
         e.style.display = 'block'; 
      }
      else {
         e.style.display = 'none'; 
      }
   }
}

function toggleNextElement(caller, tag) {
   if(!tag) tag = null;
   //trigger = caller;
   if(caller.hasClass('shmClosed')) {
       caller.removeClass('shmClosed');
       caller.addClass('shmOpen');
   }
   else {
       caller.removeClass('shmOpen');
       caller.addClass('shmClosed');
   }
   var ns = getNextSibling(caller, tag);
   if(ns) {
      toggleElement(ns);
   }
}

function getNextSibling(caller, tag) {
   if(!tag) tag = null;
   var n = caller;
   do {
      n = n.nextSibling;
   } while (n && (n.nodeType != 1 || (tag && n.nodeName.toUpperCase() != tag.toUpperCase())) );
   return n == caller ? false : n;
}


/* 
Toggling show-hide content sections with mootools
*/

window.addEvent('domready', function() {
    // show-hide elements
    found = false;
    $each($$('.showHideMenu'), function(item) {
        found = true;
        toggleNextElement(item); //initialize related content element
        text = item.get('text');
        link = new Element('a');
        // link.set('text',  text); // fails in IE6
        // workaround
        t = document.createTextNode(text);
        link.adopt(t);
        // item.set('text','');     // fails in IE6
        // workaround
        item.firstChild.nodeValue = '';
        item.adopt(link);

        item.addClass('shmClosed');
        link.addEvent('click', function(e) {
            e = new Event(e).stop();
            var p = this.getParent();
            toggleNextElement(p);
        });
    });
    
});


/*
Make map interactive on regional presence page 
*/
/*
window.addEvent('domready', function() {
    if(!$('countryMap')) return false;
    $each($$('#countryMap area'), function(area) {
        //alert(area.get('id'));
        area.set('href',window.location.href+'#'+area.get('title'));
        area.addEvent('click', function(e) {
            e = new Event(e).stop();
            sectionId = 'country'+area.get('id').substr(String('countryMap').length,10);
            if(section = $(sectionId)) {
                toggleNextElement(section);
            }
           //scroll to the element
           position = section.getPosition();
           window.scrollTo(0,position.y);
        });
        area.addEvent('mouseover', function(e) {
            e = new Event(e).stop();
            if(!$('countryMapOver')) return false;
            countryId = area.get('id').substr(String('countryMap').length,10);
            //rollover image
            ext = '.png';
            if(Browser.Engine.trident && Browser.Engine.version == 4) { //trident engine v4 is used by IE6
                ext = '.gif';
            }
            //if(countryId == 'HR' || countryId == 'RO' ||countryId == 'SK' )
            $('countryMapOver').set('src', 'images/countryMap/countryMap'+countryId+ext);
        });
        area.addEvent('mouseout', function(e) {
            e = new Event(e).stop();
            if(!$('countryMapOver')) return false;
            $('countryMapOver').set('src', 'images/countryMap/countryMap.jpg');
        });
    })
});
*/

//hide showHideContent elements if JS is available
document.write('<style type="text/css">.showHideContent { display: none; }</style>');


if (typeof(hs) != "undefined") {
/* kep nagyitas */

	hs.graphicsDir = 'js/highslide/graphics/';
	hs.align = 'center';
	hs.transitions = ['expand', 'crossfade'];
	hs.outlineType = 'rounded-white';
	hs.fadeInOut = true;
	hs.showCredits = false;
	//hs.dimmingOpacity = 0.75;

	// Add the controlbar
	if (hs.addSlideshow) hs.addSlideshow({
		//slideshowGroup: 'group1',
		interval: 5000,
		repeat: false,
		useControls: true,
		fixedControls: true,
		overlayOptions: {
			opacity: .75,
			position: 'top center',
			hideOnMouseOut: true
		}
	});

};

window.addEvent('domready', function() {
    /* temporary code
    $each($$('h4.showHideMenu'), function(o) {
        if(o.get('text') == 'Success Story') o.set('id', 'successStory');
    });
    */
    if(!$('successStory')) return false;
    illustration = $$('img.illustration');
    if(illustration.length == 1) {
        illustration = illustration[0];
        ssbanner = new Element('div', { id: 'flashSuccessButton' });
        ssbanner.inject(illustration, 'after');
        ssbanner.set('html', 
            '<object type="application/x-shockwave-flash" width="936" height="64" id="success-story-header" data="/success-story-headerV5.swf?lang=' + document.lang + '" wmode="transparent">',
            '<param name="allowScriptAccess" value="sameDomain" />',
            '<param name="movie" value="/success-story-headerV5.swf?lang=' + document.lang + '" />',
            '<param name="quality" value="high" />',
            '<param name="wmode" value="transparent" />',
            '</object>'
            );
    }
    // opens success story if we come from the index page success story banner (verify #success-story int the URL)
    bookmark = window.location.hash.substr(1,window.location.hash.length-1);
    if(bookmark == 'success-story') openSuccessStory();
    

});

function openSuccessStory() {

   section = $('successStory');
   if(!section) return false;

   toggleNextElement(section);

   //scroll to the element
   position = section.getPosition();
   window.scrollTo(0,position.y);
}


/* Tech helpers */

/* Startup page flash header tabs */
function TBActiveAction() { return TBAction(); }
function TBAction() {
    if($('techproductstab')) { // only tab flash

        if(document.lang == 'en') {
            redirect('en/products/treasury+backbone+suite+/aam+technologies+-+treasury+backbone+suite.html');
        } 
        else if(document.lang == 'hu') {
            redirect('hu/termekek/treasury+backbone/aam+technologies+-+treasury+backbone.html');
        }
    }
    else { // landing page with full flash
        o = $('SAMUStartup');
        if(o) {
            o.style.display = 'none';
        }
        o = $('TBStartup');
        if(o) {
            o.style.display = 'block';
        }
    }

}

function SAMUActiveAction() { return SAMUAction(); }
function SAMUAction() {
    if($('techproductstab')) { // only tab flash
        if(document.lang == 'en') {
            redirect('en/products/samu+suite/aam+technologies+-+samu+suite.html');
        } 
        else if(document.lang == 'hu') {
            redirect('hu/termekek/samu+suite/aam+technologies+-+samu+suite.html');
        }
    }
    else { // landing page with full flash
        o = $('SAMUStartup');
        if(o) {
            o.style.display = 'block';
        }
        o = $('TBStartup');
        if(o) {
            o.style.display = 'none';
        }
    }

}

/* Startup page Learn more button */ 
function SAMULearn() {
        if(document.lang == 'en') {
            redirect('en/products/samu+suite/aam+technologies+-+samu+suite.html');
        } 
        else if(document.lang == 'hu') {
            redirect('hu/termekek/samu+suite/aam+technologies+-+samu+suite.html');
        }
}

function TBLearn() {

        if(document.lang == 'en') {
            redirect('en/products/treasury+backbone+suite+/aam+technologies+-+treasury+backbone+suite.html');
        } 
        else if(document.lang == 'hu') {
            redirect('hu/termekek/treasury+backbone/aam+technologies+-+treasury+backbone.html');
        }
}

/* SAMU Suite flash diagram */
function OpenHW() {
        if(document.lang == 'en') {
            redirect('en/products/samu+suite/samu+human+workflow/aam+technologies+-+samu+human+workflow.html');
        } 
        else if(document.lang == 'hu') {
            redirect('hu/termekek/samu+suite/samu+human+workflow/aam+technologies+-+samu+human+workflow.html');
        }
}

function OpenSD() {
        if(document.lang == 'en') {
            redirect('en/products/samu+suite/samu+service+desk/aam+technologies+-+samu+service+desk.html');
        } 
        else if(document.lang == 'hu') {
            redirect('hu/termekek/samu+suite/samu+service+desk/aam+technologies+-+samu+service+desk.html');
        }
}

function OpenR() {
        if(document.lang == 'en') {
            redirect('en/products/samu+suite/samu+repository/aam+technologies+-+samu+repository.html');
        } 
        else if(document.lang == 'hu') {
            redirect('hu/termekek/samu+suite/samu+repository/aam+technologies+-+samu+repository.html');
        }
}

function redirect(url) {
    // relative url with base href doesn't work in IE, so transforming to absolute by preprending base href to url
    var b = document.getElementsByTagName('base');
    if (b && b[0] && b[0].href) {
      url = b[0].href + url;
    }
    
    //alert(url);
    window.location.href = url;
    return true;
}

window.addEvent('domready', function() {
    if(!$('contact')) return false;
    params = window.location.search;
    key = 'subject';
    
    start = params.indexOf(key+'=');
    if(start > 0) {
        start = start + key.length + 1;
        end = params.indexOf('&', start);
        if(end < 0) end = params.length;
        value = params.substr(start, end-start);
        
        if(value ) {
            if(document.lang == 'hu') {
                e = $$('select[name=form_elements7]');
            } else if(document.lang == 'en') {
                e = $$('select[name=form_elements15]');
            }

            s = e.getElement('option[value^='+value.capitalize()+']');
            if(s)
                s.setProperty('selected',1);

        }
    }
});
