try {
    document.execCommand('BackgroundImageCache', false, true);
} 
catch (e) {}

JAME.ASYNC.Events.addListener('onFullLoad',function() {
	var subacc;
	var acc = new JAME.Components.Accordeon({
		visible: parse('#globalmenu li.fatmenu>a'),
		hidden : parse('#globalmenu li.fatmenu ul'),
		opened : -1,
		onExpand : function(elm,e) {
			var self=this;

			if(elm.parentNode.getElementsByTagName('ul').length==0){

				new JAME.Ajax({
					url:elm.href+'/?ajax=true&output=raw&getMenu=1',
					onSuccess:function(resp){
						var fr = document.createElement('div');
						fr.className='productLine';
						fr.innerHTML=resp;
						elm.parentNode.appendChild(fr);
						fr.maxH = parseInt(JAME.CSS.getStyle(fr,'height','+padding +margin'));
						fr.style.display = 'none';
						fr.style.overflow = 'hidden';
						fr.style.height = '0px';
						self._open(elm);
						addProductMenuLinkage(fr)
					}
				});
			}
			if(!JAME.DOM.nextNode(elm) || (JAME.DOM.nextNode(elm) && JAME.DOM.nextNode(elm).className==='productLine')){
				SWFAddress.setValue(getValue(elm.href)[1]);
			}

			if(subacc) {
				var tohide=subacc.openedAccordeon;
				subacc.openedAccordeon=undefined;
				subacc.close(tohide);
			}
			if(elm) {	
			  return true;
			}
		},
		closing:true,
		preventDefault: true
	});

	subacc = new JAME.Components.Accordeon({
		visible: parse('#globalmenu li.fatmenu li.fatmenu>a'),
		hidden : parse('#globalmenu li.fatmenu li.fatmenu ul'),
		opened : -1,
		onExpand : function(elm,e) {
			var self=this;
			var resize=elm.parentNode.parentNode.parentNode;
			if(elm.parentNode.getElementsByTagName('ul').length==0){

				new JAME.Ajax({
					url:elm.href+'/?ajax=true&output=raw&getMenu=1',
					onSuccess:function(resp){
						var fr = document.createElement('div');
						fr.className='productLine';
						fr.innerHTML=resp;
						elm.parentNode.appendChild(fr);
						fr.maxH = parseInt(JAME.CSS.getStyle(fr,'height','+padding +margin'));
						fr.style.display = 'none';
						fr.style.overflow = 'hidden';
						fr.style.height = '0px';
						self._open(elm);
					    resize.style.height=(resize.maxH+fr.maxH)+'px';
						addProductMenuLinkage(fr)
					}
				});

			}

			SWFAddress.setValue(getValue(elm.href)[1]);

			if(JAME.DOM.nextNode(elm))
				resize.style.height=(resize.maxH+JAME.DOM.nextNode(elm).maxH)+'px';
			return true;
		},
		preventDefault: true
	});



	var caller = arguments.callee;//save the function stack trace
	setTimeout(function() {JAME.ASYNC.Events.removeListener('onFullLoad',caller);},0);

});

function addProductMenuLinkage(div) {

	JAME.Events.addListener(div,'mouseover',function(e){

		if(!e.target.tagName.toLowerCase==='a') return true;

		var id = e.target.id.replace('linkto_','');

		if(!JAME.$(id)) return;

		var products = parse('#search_products .product_found');

		JAME.each(products,function(elm,i){

			if(elm.id!=id){
				new JAME.FX.Tween(elm,{opacity:.1},{duration:200})
			}
			else {
				new JAME.FX.Tween(elm,{opacity:1},{duration:200})
			}

/*
			if(elm.id!=id){
				if(JAME.$(elm.id+'_clone')) JAME.$('overallContainer').removeChild(JAME.$(elm.id+'_clone'))
			}
			else {
				var clone = elm.cloneNode(true);
				clone.id=clone.id+'_clone';
				var position     = e.pageY-70;
				var windowHeight = JAME.Dimensions.windowSize().height;

				JAME.CSS.setStyles(clone,{opacity:0,position:'absolute',left:200,top:position,backgroundColor:'#ffffff',height:450,overflow:'hidden'});
				JAME.$('overallContainer').appendChild(clone);
				if(position+parseInt(JAME.CSS.getStyle(clone,'height'))>windowHeight){
					JAME.CSS.setStyles(clone,{top:windowHeight - parseInt(JAME.CSS.getStyle(clone,'height'))-70});
				}
				new JAME.FX.Tween(clone,{opacity:1},{duration:200})
			}
*/
		})
	});

	JAME.Events.addListener(div,'mouseleave',function(e){
		var products = parse('#search_products .product_found');
		JAME.each(products,function(elm,i){
			//if(JAME.$(elm.id+'_clone')) JAME.$('overallContainer').removeChild(JAME.$(elm.id+'_clone'))
				new JAME.FX.Tween(elm,{opacity:1},{duration:200})
		})
	});
}

/*-------------------*/
/*=TOP PAGE---------*/
/*-----------------*/

JAME.ASYNC.Events.addListener('onFullLoad',function() {
	var string = window.location.href;
	var domain = window.location.hostname+'\/(#)?$';
	var regex = new RegExp(domain);
	if(string.match(regex)){
		new JAME.Ajax({
			url:'/?ajax=true&output=raw',
			onSuccess:function(resp){
				JAME.$('website').innerHTML=resp;
				setUpTop();
			}
		});
	}
});

JAME.ASYNC.Events.addListener('onFullLoad',function() {

	if(! /faq\/Faq\.html/.test(SWFAddress.getValue()) ) return;

	subacc = new JAME.Components.Accordeon({
		visible: parse('#html_contents h5'),
		hidden : parse('#html_contents div.faqcontainer'),
		opened : -1,
		onExpand : function(elm,e) {
			var self=this;
			return true;
		},
		closing:true,
		preventDefault: true
	});


})

JAME.ASYNC.Events.addListener('onFullLoad',function() {
	if(! /(?:product\/|products\/|news)/.test(SWFAddress.getValue()) ) return;
	addthis.init();
	addthis.toolbox(JAME.$('addthis'));
	addthis.counter(JAME.$('counter'));
});

JAME.ASYNC.Events.addListener('onFullLoad',function() {
	if(! /(?:product\/|products\/Info)/.test(SWFAddress.getValue()) ) return;
	addthis.init();
	addthis.toolbox(JAME.$('addthis'));
	addthis.counter(JAME.$('counter'));
})

function random(min, max) {
    return Math.round((Math.random() * (max - min)) + min);
}

function setUpTop() {

		var imgs = parse('#html_container div.fader img');
		JAME.ASYNC.stack.push(imgs);
		var root='/precor/local/img/splash/';
		var container =parse('#html_container div.fader');
		JAME.ASYNC.crossfader = new JAME.Components.CrossFader({
			imgs : imgs,
			imgsToLoad:[				
				root+'splash2.jpg'			
			],
			container:container[0]
		}).start();

		JAME.CSS.setStyles(parse('#top-news ul'),{opacity:1,zIndex:50000});

		var news  = parse('#top-news ul');
 		var title = parse('#top-news h2');
 		var span  = parse('#top-news h2 span');
		var accordean = new JAME.Components.Accordeon({
			visible: title,
			hidden : news,
			opened : -1,
			closing : true,
			onExpand:function(elm){
				span.innerHTML='▼';
				span.className='';
				return true;
			},
			onClose:function(elm){
				span.innerHTML='▲';
				span.className='augmented';
				return true;
			}
		});
		accordean.toggle(title[0]);

}
