// CSS Browser Selector   v0.2.5
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/index.html')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/index.html')?'webkit safari':is('mozilla/index.html')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();

/*
**
*/
var CONST = {
	COLOR_OVER : "#94C43A",
	TAG_COLOR_OVER : "rgb(229,241,208)".rgbToHex(),
	TAG_CONTAINER_ID : "tagContent"
};
var Site = {
	start: function(){
		Site.tooltips();
		if ($('needs')){Site.parseNeeds()};
		if ($('flags')){Site.parseFlags()};
		if ($$('.taglink')){Site.parseTags()};
		if ($$('.documentclass')){Site.createTagActions();};
		if ($$('.attachmentLink')){Site.createLinkInfos();};
	},
	parseNeeds: function(){
		var els = $$('#needs .need');
		this.createOvers(els,TABCOLOR.COLOR_OVER);
	},
	/*parseDocClass: function(){
		var els = $$('.documentclass');
		this.createOvers(els,TABCOLOR.COLOR_OVER);
	},*/
	parseFlags: function(){
		var els = $$('#flags li');
		this.createOvers(els,CONST.COLOR_OVER);
	},
	parseTags: function(){
		var els = $$('a.taglink');
		if(Cookie.get("tag") != false) {
			Site.loadTagContent(Cookie.get("tag"));
		} else {
			Site.loadTagContent(els[0]);
		}
	},
	createOvers: function(els,color){
		//var els = $$('#needs .need,.documentclass,#flags li,.taglevel');
		els.each(function(el, i){
			var fx = new Fx.Styles(el, {'duration': 200, 'wait': false});		
			var fromColor = el.getStyle('background-color');
			var toColor = color;
		
			el.addEvent('mouseover', function(e){	
				fx.start({'background-color': toColor});
			});
			el.addEvent('mouseout', function(e){
				fx.start({'background-color': fromColor});
			});
		});	
	},
	createTagActions: function(){
		$$(document.links).each(function(el){
			if (el.rel && el.rel.test(/^row/i)){
				//this.anchors.push(el);
				var a = el.rel.split('::');
				var rows = $(a[0]);
				var cols = $(a[1]);
				//var fxrows = new Fx.Styles(rows.getFirst(), {'duration': 200, 'wait': false});		
				var fxcols = new Fx.Styles(cols, {'duration': 10, 'wait': false});		
				var fromRowsColor = cols.getStyle('color');
				var fromColsColor = cols.getStyle('background-color');
				var toColor = TABCOLOR.COLOR_OVER;
				el.addEvent('mouseover', function(e){
					//if(Cookie.get("tagReminder") != el.rel ) {							  
					rows.addClass('rowheader-over');	
					fxcols.start({'background-color': toColor});
					//}
				});
				el.addEvent('mouseout', function(e){
					//if(Cookie.get("tagReminder") != el.rel ) {
					rows.removeClass('rowheader-over');
					fxcols.start({'background-color': fromColsColor});
					//}
				});
				el.addEvent('mousedown', function(e){
					//Cookie.set("tagReminder", this.rel, 1);							  
				});
			}
		});
	},
	createLinkInfos: function(){
		$$(document.links).each(function(el){
			if (el.rel && el.rel.test(/^link/i)){
				var a = el.rel.split('|');
				var img = a[1];
				var lang = a[2];
				var type = a[3];
				var size = a[4];
				var sizetype = a[5];
				
				el.addEvent('mouseover', function(e){
					$linkInfo(img,lang,type,size,sizetype);
				});
				el.addEvent('mouseout', function(e){
					$linkInfo();
				});
			} else if (el.rel && el.rel.test(/^abstract/i)) {
				var a = el.rel.split('|');
				var img = a[1];
				var lang = a[2];
				el.addEvent('mouseover', function(e){
					$linkInfo(img,lang);
				});
				el.addEvent('mouseout', function(e){
					$linkInfo();
				});
			}
		});
	},
	popupCenterWindow: function(url,name,w,h,scroll,resizable,otheroptions) {
		var win= null;
		var left = (screen.width-w)/2;
		var top = (screen.height-h)/2;
		var opt ='height='+h+',';
		opt +='width='+w+',';
		opt +='top='+top+',';
		opt +='left='+left+',';
		opt +='scrollbars='+scroll+',';
		if(otheroptions != undefined) {
			opt +='toolbar=yes,';
			opt +='menubar=yes,'; 
		}
		opt +='resizable='+resizable;
		win = window.open(url,name,opt);
		if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
	},
	loadTagContent:function(url) {
		$$('a.taglink').each(function(el){
			if(el.getParent().hasClass('tag-selected')){
				el.getParent().removeClass('tag-selected');
			}				 
			if(el.href == url) {
				el.getParent().addClass('tag-selected');
			}
		});
		$(CONST.TAG_CONTAINER_ID).src = url; 
	},
	tooltips: function(){
		var myTips = new Tips($$('.tooltip'), {
			timeOut: 700,
			maxTitleChars: 50,
			maxOpacity: .9 
		});
	}
};
// Ouverture de fenetre centree
function $win(url,name,w,h,scroll,resizable) {
	Site.popupCenterWindow(url,name,w,h,scroll,resizable);
	return false;
}
// Ouverture de fenetre centree
function $externalwin(url,name,w,h,scroll,resizable) {
	Site.popupCenterWindow(url,name,w,h,scroll,resizable,1);
	return true;
}
// Ouverture de la fenetre des tags
function $tagwin(url) {
	Cookie.remove("tag");
	if(window.ie) {
		$win(url,'tagwin',930,558,'no','yes');
	} else {
		$win(url,'tagwin',920,558,'no','yes');
	}
	return false;
}
// Affiche un tag
function $tag(url) {
	Cookie.set("tag", url, {duration: false});
	Site.loadTagContent(url);
	return false;
}
// Ouvre un formulaire
function $formwin(url) {
	$win(url,'formwin',500,400,'yes','yes');
	return false;
}
// Ouverture de la fenetre d'un abstract
function $mainthemewin(url) {
	$win(url,'mainthemewin',619,500,'no','no');
	return false;
}
// Affiche les info d'un attachemnt
function $linkInfo() {
	//imgsrc,lang,type,size
	/*$A(arguments).each(function(argument){
       // alert(argument);
    });*/
	var args = $A(arguments);
	var argscount = args.length;
	switch (argscount) {
		case 0:
			$('infoContent').setHTML('&nbsp;');
			break;
		case 2:
			$('infoContent').setHTML(' ');
			var shadow = new Element('div').setProperty('id','linkshadow');
			shadow.setProperty('class','linknoshadow');
			$(shadow).injectInside('infoContent');
			if(args[0] != 'none') {
				var img =  new Element('img').setProperty('id','linkimg');
				shadow.setProperty('class','linkshadow');
				img.setProperty('class','linkimg');
				img.setProperty('src',args[0]);
				img.injectInside(shadow);
			}
			if(args[1] != '') {
				var lang =  new Element('div').setProperty('class','linklang');
				lang.setHTML(args[1]);
				lang.injectInside('infoContent');
			}
			break;
		case 5:
			$('infoContent').setHTML(' ');
			var shadow = new Element('div').setProperty('id','linkshadow');
			shadow.setProperty('class','linknoshadow');
			$(shadow).injectInside('infoContent');
			if(args[0] != 'none') {
				var img =  new Element('img').setProperty('id','linkimg');
				shadow.setProperty('class','linkshadow');
				img.setProperty('class','linkimg');
				img.setProperty('src',args[0]);
				img.injectInside(shadow);
			}
			if(args[1] != '') {
				var lang =  new Element('div').setProperty('class','linklang');
				lang.setHTML(args[1]);
				lang.injectInside('infoContent');
			}
			if(args[2] != '') {
				var type =  new Element('div').setProperty('class','linktype');
				type.setHTML(args[2]);
				type.injectInside('infoContent');
			}
			if(args[3] != '' && args[3] != '0' && args[4] != '') {
				var size =  new Element('div').setProperty('class','linksize');
				size.setHTML(args[3]+" "+args[4]);
				size.injectInside('infoContent');
			}		
			break;
		default:
			$('infoContent').setHTML('&nbsp;');
			break;
	}
	//Site.loadTagContent(url);
	//$('infoContent').setHTML(url);

	return false;
}
// Ouverture de la fenetre d'un abstract
function $abstractwin(url) {
	$win(url,'abstractwin',914,600,'no','yes');
	return false;
}
// Ouverture de la fenetre d'un abstract
var surveywin;
function $surveywin(url) {
	if(surveywin == undefined) {
		surveywin = $win(url,'surveywin',600,600,'yes','yes');
	}
	//self.focus();
	return false;
}
// Affiche l'aide Kartoo
function $kartooHelp(url) {
	$win(url,'kartoohelp',950,620,'no','no');
	return false;
}
// Recherche
function Search_old(form,URLprefixeKartoo,URLprefixeYooget){
	var value = form["query"].value;
	if(value != '') {
		if(value>0 && value<=500) {
			// Yooget
			var url = URLprefixeYooget+value+".html";
			$win(url,'Yooget',619, 558,'no','no');
		} else {
			// Kartoo
			var url = URLprefixeKartoo+"?query="+value;
			$win(url,'Kartoo',950,620,'no','no');
		}
	}
}


function Search(form,URLprefixeKartoo,URLprefixeYooget){
	var value = form["query"].value;
	if(value != '') {
		var type="^-?\\d+$";
		var re= new RegExp(type);
		if(value.match(re)==null){
			// Kartoo
			var url = URLprefixeKartoo+"?query="+value;
			$win(url,'Kartoo',950,620,'no','no');
		}else{
			var ftmp=document.URL.substring(0,document.URL.indexOf("?"));
			var fname=ftmp.substring(ftmp.lastIndexOf("/")+1);
			var prefixe="";
			if(fname.substring(0,fname.indexOf("_"))!="index")
				prefixe="../";
			var url = prefixe+"assets/html/call_site.html?query="+value+"&q="+URLprefixeYooget+"&send="+URLprefixeKartoo;
			$win(url,'Yooget',619, 558,'no','no');
		}
	}
	
}


window.addEvent('domready', Site.start);
window.addEvent('load', function() {
	// Corrction taille bandeau
	if ($('brand')){
		if($('brand').getSize().size.y != $$('#header .left').getStyle('height') ) {
			var brandImgHeight = document.images['brand'].height;
			var headerLeft = $$('#header .left');
			var headerRight = $$('#header .right');
			headerLeft.setStyle('height', brandImgHeight+'px');
			headerRight.setStyle('height', brandImgHeight+'px');
		}
	}
});

