// moo! moo! moo!

window.addEvent('domready', function(){
	
	/*uarv3AutoPadding();*/
	theBigPicturesResize()
	window.addEvent('resize', function(){ theBigPicturesResize(); });
	window.addEvent('keyup', function(){ theBigPicturesResize(); });
	window.addEvent('scroll', function(){ theBigPicturesResize(); });
	
	/*window.addEvent('resize', function(){ uarv3AutoPadding(); });
	window.addEvent('keyup', function(){ uarv3AutoPadding(); });
	window.addEvent('scroll', function(){ uarv3AutoPadding(); });*/
	
	
	
	
	// +-- give the ul / li some magics
	
	var indexUl = $$('.index')[0];
	var indexLis= $$('.index li');
	
	indexLis.setOpacity(0.5);
	
	indexUl.addEvents({
		'mouseleave': function(){
			indexLis.setOpacity(0.5);
		}
	});
	
	indexLis.each(function(el){
			
		currentLiId = el.getProperty('id');
		
		el.addEvents({
			'mouseenter': function(){
				indexLis.setOpacity(0.5);
				el.setOpacity(0.9);
			},
			'mouseleave': function(){
				el.setOpacity(0.2);
			}
		});

		
	});
	
	// +-- give the <a href> gallery links some magics
	
	var gals= $$('.gallery');
	$$('.the_big_picture').setOpacity(0);
	$$('.the_big_picture').setStyle('display','block');
	
	gals.each(function(gal){
			
		var itemId = gal.getProperty('id');
		//console.log(gId);
		var tbpId = $$('#'+itemId+' .tbpId')[0].innerHTML;
		//console.log(tbpId);
		var gId = $$('#'+itemId+' .gId')[0].innerHTML;
		
		// +-- href links change (more socializable)
		
		gal.setProperty('href','home.html');
		
		// +-- the big picture fx
		
		var BigPictureFx = new Fx.Styles($(tbpId), {duration:400,wait:false});
		
		gal.addEvents({
			'mouseenter': function(){
				
				//var BigPictureFx = new Fx.Styles($(tbpId), {duration:200,wait:false});
				BigPictureFx.start({'opacity': 1});
				
			},
			'mouseleave': function(){

				//var BigPictureFx = new Fx.Styles($(tbpId), {duration:400,wait:false});
				BigPictureFx.start({'opacity': 0});

			}
		});

		
	});
	
		
});

function theBigPicturesResize(){

	var maxheight = window.getHeight();
	maxheight = maxheight - 0; // preserve the header
	var maxwidth = window.getWidth();
	
	// choose the right big pic
	$$('.the_big_picture .bigpix').setStyle('display','none');
	if(maxwidth<=1024) $$('.the_big_picture .bigpix_1024').setStyle('display','block');
	else if(maxwidth>1680) $$('.the_big_picture .bigpix_1920').setStyle('display','block');
	else $$('.the_big_picture .bigpix_1280').setStyle('display','block');
	
	$$('.the_big_picture').setStyle('width',maxwidth+'px');
	$$('.the_big_picture').setStyle('height',maxheight+'px');
	
	// small delay & redo to prevent some bugs
	(function(){
		$$('.the_big_picture').setStyle('width',maxwidth+'px');
		$$('.the_big_picture').setStyle('height',maxheight+'px');
	}).delay(50);

}

function uarv3AutoPadding(){

	//window.alert(window.getHeight()+'px');
	height = window.getHeight();
	if(height<600) $$('.uarv3boxs')[0].setStyles({'padding-top': 20});
	if(height>650) $$('.uarv3boxs')[0].setStyles({'padding-top': 50});
	if(height>700) $$('.uarv3boxs')[0].setStyles({'padding-top': 80});
	//if(height>800) $$('.uarv3boxs')[0].setStyles({'padding-top': 110});
}

function genLangSwitch(lang){
	
	
	// -- contact form
	
	// header shortcut
	$$('.langswitch')[0].removeEvents();
	$$('.langswitch')[0].setProperty('href', 'javascript:void(0)');
	
	// contact_btn_send
	$('contact_btn_send').removeEvents();
	$('contact_btn_send').addEvent('click', function(){	contactSendMsg(lang); });
	
	
	// Language switch
	
	
	//console.log("genLangSwitch / lang="+lang);
	
	// sets new cookie
	Cookie.set('lang', lang);
	
	
	if(lang=='fr')
	{
		
		$$('.langswitch')[0].addEvent('click', function(){
			uarModalFlash();
			// on passe en US
			$$('.langfr').each(function(el){ el.addClass('hidden'); });
			$$('.langus').each(function(el){ el.removeClass('hidden'); });
			document.title = "UN AUTRE REGARD = HOME";
			genLangSwitch("us");
		});
		
		
	}else{
		
		$$('.langswitch')[0].addEvent('click', function(){
			uarModalFlash();
			// on passe en FR
			$$('.langus').each(function(el){ el.addClass('hidden'); });
			$$('.langfr').each(function(el){ el.removeClass('hidden'); });
			document.title = "UN AUTRE REGARD = ACCUEIL";
			genLangSwitch("fr");
		});
		
	}
	
}
