fields = {
	empty : function(which){
		fields.initialValue = $(which).attr('value');
		
		if($(which).attr('value') == fields.initialValue){
			$(which).attr('value', '');
		}

		$(which).bind("blur", function(){
			if(this.value == ""){ this.value = fields.initialValue; }
		});
	}
}


editorsPicks = {
	init : function(w){
		editorsPicks.currentLi = 0;
		editorsPicks.w = w;
		// Set all the li positions
		$.each($('#editorsPicks ul li'), function(i){
			$('#editorsPicks ul li:eq('+i+')').css({
				'position' : 'absolute',
				'left' : editorsPicks.w * i
			});
		});
		
	},
	next : function(){
		$.each($('#editorsPicks ul li'), function(i){
			$('#editorsPicks ul li:eq('+i+')').animate({
			   left: (i * editorsPicks.w) - editorsPicks.w
			 }, 500, function(){
				$.each($('#editorsPicks ul li'), function(i){
					$('#editorsPicks ul li:eq('+i+')').css({
						'position' : 'absolute',
						'left' : editorsPicks.w * i
					});
				});
			});
		});

		$('#editorsPicks ul li:first-child').appendTo($('#editorsPicks ul'));
	},
	previous : function(){
		$('#editorsPicks ul li:last-child').css('left', -editorsPicks.w);
		$('#editorsPicks ul li:last-child').prependTo($('#editorsPicks ul'));
		
		$.each($('#editorsPicks ul li'), function(i){
			$('#editorsPicks ul li:eq('+i+')').animate({
			   left: (i * editorsPicks.w)
			 }, 500);
		});
	}
}

shoppingAlerts = {
	init : function(){
		shoppingAlerts.currentLi = 0;

		// Set all the li positions
		$.each($('#shoppingAlerts ul li'), function(i){
			$('#shoppingAlerts ul li:eq('+i+')').css({
				'position' : 'absolute',
				'left' : 140 * i
			});
		});
		
	},
	next : function(){
		$.each($('#shoppingAlerts ul li'), function(i){
			$('#shoppingAlerts ul li:eq('+i+')').animate({
			   left: (i * 140) - 140
			 }, 500, function(){
				$.each($('#shoppingAlerts ul li'), function(i){
					$('#shoppingAlerts ul li:eq('+i+')').css({
						'position' : 'absolute',
						'left' : 140 * i
					});
				});
			});
		});

		$('#shoppingAlerts ul li:first-child').appendTo($('#shoppingAlerts ul'));
	},
	previous : function(){
		$('#shoppingAlerts ul li:last-child').css('left', - 140);
		$('#shoppingAlerts ul li:last-child').prependTo($('#shoppingAlerts ul'));
		
		$.each($('#shoppingAlerts ul li'), function(i){
			$('#shoppingAlerts ul li:eq('+i+')').animate({
			   left: (i * 140)
			 }, 500);
		});
	}
}

hotItems = {	
	init : function(){
		$("a[@rel=hot]").bind('mouseover', function(event){
			hotItems.create();
			hotItems.positionItem(event);
		});
		
		$("a[@rel=hot]").bind('mouseout', function(){
			hotItems.hide(this);
		});
		
		$("a[@rel=hot]").bind('mousemove', function(event){
			hotItems.positionItem(event);
		});
	},
	create : function(caller){
		$('body').append('<span id="hotItem" class="hotItem">Hot!</span>');
	},
	hide : function(){
		$('#hotItem').remove();
	},
	positionItem : function(eventObject){
		if($.browser.msie){
			hotItems.cursorX = eventObject.pageX;
			hotItems.cursorY = eventObject.pageY -35;
		}else{
			hotItems.cursorX = eventObject.pageX;
			hotItems.cursorY = eventObject.pageY - 30;
		}

		$('#hotItem').css({
			'left' : hotItems.cursorX,
			'top' : hotItems.cursorY
		});
	}
}

tendanceItems = {	
	init : function(){
		$("a[@rel=tendance]").bind('mouseover', function(event){
			tendanceItems.create();
			tendanceItems.positionItem(event);
		});
		
		$("a[@rel=tendance]").bind('mouseout', function(){
			tendanceItems.hide(this);
		});
		
		$("a[@rel=tendance]").bind('mousemove', function(event){
			tendanceItems.positionItem(event);
		});
	},
	create : function(caller){
		$('body').append('<span id="tendanceItem" class="tendanceItem">Tendance</span>');
	},
	hide : function(){
		$('#tendanceItem').remove();
	},
	positionItem : function(eventObject){
		if($.browser.msie){
			tendanceItems.cursorX = eventObject.x;
			tendanceItems.cursorY = eventObject.y + document.documentElement.scrollTop - 40;
		}else{
			tendanceItems.cursorX = eventObject.pageX;
			tendanceItems.cursorY = eventObject.pageY - 30;
		}

		$('#tendanceItem').css({
			'left' : tendanceItems.cursorX,
			'top' : tendanceItems.cursorY
		});
	}
}

subitem = {
	open : function(caller){
		// Get the longest item with
		currentLength = 0;
		$.each($(caller).find('ul li a'), function(i){
			currentText = $(caller).find('ul li a:eq('+i+')').text();
			if(currentText.length > currentLength){
				currentLength = currentText.length;
			}
		});
		
		$.each($(caller).find('ul li a'), function(i){
			$(caller).find('ul li a:eq('+i+')').width(currentLength * 9 + 10);
			$(caller).find('ul li:eq('+i+')').width(currentLength * 9 + 10);
			$(caller).find('ul').width(currentLength * 9 + 10);
		});
		
		$(caller).find('ul').show();
	},
	close : function(caller){
		$(caller).find('ul').hide();
	}
}


var obj = null;
var tooltipZindex = 3;

clothesViewer = {
	init : function(){
		$("a[@rel=plus]").hover(function() {
			if (obj) {
				obj.hide();
				obj = null;
			} //if
			$(this).parent().css('z-index',tooltipZindex++);
			$(this).next().show();
		},
		function() {
			obj = $(this).next();
			setTimeout("clothesViewer.checkHover()",1000);
		});
		
		$("a[@rel=plus]").next().hover(function() {
			clearTimeout();
			if (obj) {
				obj.hide();
				obj = null;
			} //if
			$(this).show();
		},
		function() {
			obj = $(this);
			setTimeout("clothesViewer.checkHover()",100);
		});
	},
	checkHover : function(caller){
		if(obj){
			obj.hide();
		}
	}
}

gallery = {
	init : function(){
		$("a[@rel=gallery]").hover(function() {
			if (obj) {
				obj.hide();
				obj = null;
			} //if
			$(this).parent().parent().parent().css('z-index',tooltipZindex++);
			$(this).parent().parent().next().show();    
		},
		function() {
			obj = $(this).parent().parent().next();
			setTimeout("gallery.checkHover()",1000);
		});
		
		$("a[@rel=gallery]").parent().parent().next().hover(function() {
			clearTimeout();
			if (obj) {
				obj.hide();
				obj = null;
			} //if
			$(this).show();
		},
		function() {
			obj = $(this);
			setTimeout("gallery.checkHover()",100);
		});
	},
	checkHover : function(caller){
		if(obj){
			obj.hide();
		}
	}
}

flyout = {
	open : function(){
		$('#flyoutBox').show();
	},
	close : function(){
		$('#flyoutBox').hide();
	}
}

blackBoxes = {
	init : function(){
		$('span.tags_loulou_btns').each(function(){
			if($(this).text() == ""){
				$(this).hide();
			}
		});
		
		//buy online
		var l = $('div.fRight div a:eq(0)').attr('href');
		if(l != undefined){
			var tar = $('div#specials > span.tags_loulou_btns:contains(Achetez en ligne)');
			$(tar).eq(0).wrap('<a href="' + l + '" class="noline" target="_blank"></a>');
		}
		
	}
}

mainMenu = {
	init : function(){
		var t = new Array();
		t.push('reportages');
		t.push('cuisine');
		t.push('modebeaute');
		t.push('sante');
		t.push('maison');
		t.push('argent');
		t.push('weekend');
		t.push('concours');

		for(var i = 0; i < t.length; i++)
			{
				if(location.href.indexOf("/" + t[i] + '/') >= 0){
					$('div.menu ul:not(.subitem) > li:eq(' + (i + 1) + ')').addClass('selected');
					return;
				}
			}
	}
}

/*Rajout par younes de l'ancien script.js
function open_print(){
//	alert(document.location.search);
	window.open('/shared/print.jsp'+document.location.search, 'print', 'scrollbars=yes,menubar=no,status=no,top=100px,left=100px,width='+(screen.width-200)+',height='+(screen.height-400));
}

function open_printoakley(){
//	alert(document.location.search);
	window.open('/shared/print_oakley.jsp'+document.location.search, 'print', 'scrollbars=yes,menubar=no,status=no,top=100px,left=100px,width=400,height=500');
}

function open_email(){
	lang = 'en';
	if(document.location.href.indexOf("/francais/")>0){
		lang = 'fr';
	}
	lang = '/shared/email_'+lang+'.jsp'+document.location.search;
	window.open(lang, 'email', 'scrollbars=yes,menubar=no,status=no,top=100px,left=100px,width=480,height=600');
}

function open_emailOakley(){
	lang = 'en';
	if(document.location.href.indexOf("/francais/")>0){
		lang = 'fr';
	}
	lang = '/shared/emailOakley_'+lang+'.jsp'+document.location.search;
	window.open(lang, 'email', 'scrollbars=yes,menubar=no,status=no,top=100px,left=100px,width=480,height=600');
}
/* function popup pour le formulaire de feedback.*/

function popfeedback() 
	{
	msg=window.open("http://www.louloumagazine.com/feedback/index.html","popv","toolbar=no,left=0,top=360,width=500,height=600,directories=no,status=no,scrollbars=yes,resize=yes,menubar=no");
}

function popfeedbackEn() 
	{
	msg=window.open("http://www.louloumagazine.com/feedback/index_en.html","popv","toolbar=no,left=0,top=360,width=500,height=600,directories=no,status=no,scrollbars=yes,resize=yes,menubar=no");
}

function openWindow(url, width, height) {
	leftPos   = (screen.availWidth-10  - width)  / 2;
	topPos    = (screen.availHeight-20 - height) / 2;
	features  = "width=" + width +",height=" + height;
	features += ",scrollbars=1,resizable=0,location=0";
	features += ",menubar=0,toolbar=0,status=1";
	var myWindow = window.open(url, name, features);
	myWindow.moveTo(leftPos, topPos);
}

  function ouvretoi(imgname)
  {
  var OpenWindow=window.open("", "newwin","height=660,width=640");
   OpenWindow.document.write("<div align=\"center\">" +imgname)
   OpenWindow.document.write("<br><br>")
   OpenWindow.document.write("<a href='javascript:self.close()' target='_self'>Fermer</a></div>")
   }
   
   function openPlayer(stationId, lang) {
  if(lang == null || lang == ''){
    lang='en';
  }
  var url = "http://loulou.rogers.icebergradio.com/loulou-radio-" + lang + ".html";
  if (stationId && stationId > 0) {
    url += "?station=" + stationId
  }

  var w = null;
  w = window.open(url, "PLAYER", "scrollbars=0,width=602,height=351");

  if (w){
    w.focus();
  } else {
    alert('player window failed to open.  perhaps your popup blocker blocked it?');
  }
}

//pour le pulldown menu
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function openMMV(l,h,url) {
hauteur=Math.round((screen.availHeight-h)/2);
largeur=Math.round((screen.availWidth-l)/2);
window.open(url, "site", "toolbar=0,location=0,directories=0,status=0, scrollbars=0,resizable=0,menubar=0,top="+hauteur+",left="+largeur+",width="+l+",height="+h);
}


CelebritylooksNav = {
	init : function(){
		shoppingAlerts.currentLi = 0;

		// Set all the li positions
		$.each($('#CelebritylooksNav ul li'), function(i){
			$('#CelebritylooksNav ul li:eq('+i+')').css({
				'position' : 'absolute',
				'left' : 120 * i
			});
		});
		
	},
	next : function(){
		$.each($('#CelebritylooksNav ul li'), function(i){
			$('#CelebritylooksNav ul li:eq('+i+')').animate({
			   left: (i * 120) - 120
			 }, 300, function(){
				$.each($('#CelebritylooksNav ul li'), function(i){
					$('#CelebritylooksNav ul li:eq('+i+')').css({
						'position' : 'absolute',
						'left' : 120 * i
					});
				});
			});
		});

		$('#CelebritylooksNav ul li:first-child').appendTo($('#CelebritylooksNav ul'));
	},
	previous : function(){
		$('#CelebritylooksNav ul li:last-child').css('left', - 120);
		$('#CelebritylooksNav ul li:last-child').prependTo($('#CelebritylooksNav ul'));
		
		$.each($('#CelebritylooksNav ul li'), function(i){
			$('#CelebritylooksNav ul li:eq('+i+')').animate({
			   left: (i * 120)
			 }, 300);
		});
	}
}

CelebritylooksNav_home = {
	init : function(){
		shoppingAlerts.currentLi = 0;

		// Set all the li positions
		$.each($('#CelebritylooksNav_home ul li'), function(i){
			$('#CelebritylooksNav_home ul li:eq('+i+')').css({
				'position' : 'absolute',
				'left' : 70 * i
			});
		});
		
	},
	next : function(){
		$.each($('#CelebritylooksNav_home ul li'), function(i){
			$('#CelebritylooksNav_home ul li:eq('+i+')').animate({
			   left: (i * 70) - 70
			 }, 300, function(){
				$.each($('#CelebritylooksNav_home ul li'), function(i){
					$('#CelebritylooksNav_home ul li:eq('+i+')').css({
						'position' : 'absolute',
						'left' : 70 * i
					});
				});
			});
		});

		$('#CelebritylooksNav_home ul li:first-child').appendTo($('#CelebritylooksNav_home ul'));
	},
	previous : function(){
		$('#CelebritylooksNav_home ul li:last-child').css('left', - 70);
		$('#CelebritylooksNav_home ul li:last-child').prependTo($('#CelebritylooksNav_home ul'));
		
		$.each($('#CelebritylooksNav_home ul li'), function(i){
			$('#CelebritylooksNav_home ul li:eq('+i+')').animate({
			   left: (i * 70)
			 }, 200);
		});
	}
}