var iphone = navigator.userAgent && ( navigator.userAgent.match( /iPhone/i ) || navigator.userAgent.match( /iPod/i ) );
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function iphoneCheck() {
	// iPhone switch !
	if ( iphone ) {
		if ( readCookie( 'iphone' ) == null ) {
			if ( confirm( "Utiliser la version iPhone de LudoMac ?" ) ) {
				eraseCookie('iphone');
				window.location.href = "http://www.ludomac.com/iphone.php";
			}
			createCookie('iphone',1,1);
		}
		
	}
}
iphoneCheck();
window.addEvent('domready',function(){
	// ajout du style de background sur le select
	$$('#top_bar li.current').each(function(e,index){
		var size=e.getSize();
		var bkg=new Element('div',{
			'class': 'bkg',
			'styles': {
				'width':(size.x+10),
				'left': -5
			}
		}).adopt(new Element('div', {'class': 'left'}));
		bkg.inject(e);
	});
	$$('#top_bar li').each(function(e,index){
		if(e.get('class')!='current'){
			e.addEvents({
				'mouseover':function(){
					var size=this.getSize();
					var bkg=new Element('div',{
							'class': 'bkg',
							'styles': {
								'width':(size.x+10),
								'left': -5
							}
						}).adopt(new Element('div', {'class': 'left'}));
					bkg.inject(e);
				},
				'mouseout':function(){
					e.getChildren('div').destroy();
				}
			});
		}
	});
}
);
function make_rating(id){
	for(i=1;i<6;i++){
		document.write('<img src="/interface/star_off.png" id="'+id+'__'+i+'" border="0" />');
		$(id+'__'+i).addEvents({
			'mouseover':function(){
				var dual=this.get('id').split('__');
				var id=dual[1];
				var nom=dual[0];
				for(var i=1;i<6;i++){
					if(i<=id){
						$(nom+'__'+i).set('src','/interface/star_on.png');
					}
					else{
						$(nom+'__'+i).set('src','/interface/star_off.png');
					}
				}
			},
			'click':function(){
				var dual=this.get('id').split('__');
				var id=dual[1];
				var nom=dual[0];
				$(nom).set('value',id);
				for(var i=1;i<6;i++){
					if(i<=id){
						$(nom+'__'+i).set('src','/interface/star_on.png');
					}
					else{
						$(nom+'__'+i).set('src','/interface/star_off.png');
					}
					$(nom+'__'+i).removeEvents('mouseover');
					$(nom+'__'+i).removeEvents('mouseout');
				}
			},
			'mouseout':function(){
				var dual=this.get('id').split('__');
				var id=dual[1];
				var nom=dual[0];
				for(var i=1;i<6;i++){
					$(nom+'__'+i).set('src','/interface/star_off.png');
				}
			}
		});
	}
}
