/**
 * @author tlohner
 */
$('document').ready(function (){
	bugs = false
	if ( $.browser.msie && $.browser.version=='6.0' ){return false;}
	if(typeof (top.frames['vnav']) == 'undefined') { bugs = true};
//	if(typeof (top.frames['vnav'].tree) == 'undefined') { bugs = true};
	if(!$('#footer')){ return false};
	if(bugs == true){
		/*include_js('left_nav.js');
		include_js('data_nav.js');
		//window.setNavigation('service');
		var tm = setTimeout(ready,0);*/
		//ready();
	} else {
		tree = top.frames['vnav'].tree;
		printSiteMap();
	}
})

function ready(){
	SITE='PUBLIC';
	setNavigation('service');
	printSiteMap();
}

function printSiteMap(){
	//var tree = top.frames['vnav'].tree;
	
	var lang = top.frames['vnav'].lang0;
	if (lang == 4){ lang =1; }
	
	if(typeof(_sitemap)!= 'undefined'){
		tree = tree.getNodeByPublicId(_sitemap);	
	}
	
	$("<div></div>").attr("id","sitemap").appendTo("#footer");
	for(i=0; i<tree._nbChilds; i++){
		var child = tree._childs[i];
		
		var el = $("<h6></h6>")
			.addClass('sitemap')
			.hover(function(){
				$(this).addClass('over');
				$(this).parent().find('.sitemap_link').hide();
				var mnu = $(this).find('div:first');
				$(mnu).css('top',$(this).offset().top-$(mnu).height()-11+'px');
				$(mnu).css('left',$(this).offset().left+'px');
				$(mnu).fadeIn('fast');
			},function(){
				$(this).removeClass('over');
				hideAll();
			})
			.append($('<a></a>').attr("href",parseLang(child._url)).html(child._libelle[lang]))
			.appendTo($('#sitemap'));
		
		if(child._nbChilds>0){
			printChild(child,el);
		}		
	}
}

function printChild(child,el){
	
	var lang = top.frames['vnav'].lang0;
	if (lang == 4){ lang =1; }
	
	var over = $("<div></div>")
		.addClass("sitemap_link")
		.appendTo(el);
	var ul = $("<ul></ul>")
	.appendTo(over);
	
	for(var j=0; j<child._nbChilds; j++){
		var li = $("<li></li>")
		.hover(function(e){
			$(this).addClass('over');
			$(this).parent().find('.sitemap_link').hide();
			var mnu = $(this).find('div:first');
			$(mnu).css('top',this.offsetTop-$(this).find('div:first').height()+'px');
			$(mnu).css('left','140px');
			$(mnu).fadeIn('fast');
			
		},function(){
			$(this).removeClass('over');
		})
		.append($('<a></a>').attr("href",parseLang(child._childs[j]._url)).html(child._childs[j]._libelle[lang]))
		.appendTo(ul);
		
		if(child._childs[j]._nbChilds>0){
			printChild(child._childs[j],li);
		}	
	}
}

function parseLang(url){
	var _lang1 = top.frames['vnav'].lang1;
	var _lang2 = top.frames['vnav'].lang2;
	var _lang0 = top.frames['vnav'].lang0;
	
	url = url.replace(/CLANG2/,_lang2);
	url = url.replace(/CLANG1/,_lang1);
	url = url.replace(/CLANG0/,_lang0);
	
	return url;
}

function hideAll(){
	$('.sitemap_link').hide();
}

function include_js(file) {
    var html_doc = document.getElementsByTagName('head')[0];
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', file);
    html_doc.appendChild(js);

    js.onreadystatechange = function () {
        if (js.readyState == 'complete') {
          //  alert('JS onreadystate fired');
        }
    }

    js.onload = function () {
       // alert('JS onload fired ' + file);
    }
    return true;
}

