// JavaScript Document
$(document).ready(function() {

	var baseh = $('.bg').height();
	var basew = $('.bg').width();
	function firstresize(ct){
		
	//	alert(center);
		 baseh = $('.bg').height();
	 	 basew = $('.bg').width();
		$('.bg').each(function() {
				
       		
				var stawid=$(window).width();
				var stahei=$(window).height();
				
				var cpX=stawid/2;
				var cpY=stahei/2;
				
			
				
				$(this).css("width", stawid); // Set new width
				
				var rapport = basew/stawid;
				
				var newhei=baseh/rapport;
				$(this).css("height", newhei);  // Scale height based on ratio
				
				
				var diff=(newhei-stahei)/2;
				$("#display").text("case 1 - " + diff);
				$(this).css("position","relative");
				$(this).css("top",-diff);
				$(this).css("left","0px");
					
				if (newhei<stahei) {
					
					$(this).css("height", stahei);
					rapport = baseh/stahei;
					var newwid=basew/rapport;
					$(this).css("width", newwid);
					
					
					var diff=(newwid-stawid)/2;
					var diffh=(newhei-stahei)/2;
					$("#display").text("case 2 - "+diff);
					
					$(this).css("position","relative");
					$(this).css("left",-diff);
					$(this).css("top","0px");
					/*if(ct=="center"){
						$("#display").text('"'+diff+'px"');
					$(this).css("left",'"'+diff+'px"');
					}else{
						$(this).css("left","0px");
						$("#display").text('"'+0+'px"');
					}*/
						
					
					
				}
				 
   			 });
		
		};
		
		$(window).resize(function(){firstresize();});
		

	function resizec(amt){
		
		 $('#contenu').stop().animate(
            {height: (180+amt)+'px'},
            {queue: false,
            duration: 800,
            easing: 'easeOutCirc'
        })
		 $('#uppermenu').stop().animate(
            {bottom: (204+amt)+'px'},
            {queue: false,
            duration: 800,
            easing: 'easeOutCirc'
        })
		  $('#wrapmenu').stop().animate(
            {bottom: (180+amt)+'px'},
            {queue: false,
            duration: 800,
            easing: 'easeOutCirc'
        })
		  
	}

	function displayh(){
	
		$hc=$('#texte').height();
		//$("#display").text($hc);
			if($hc>148){
				
				$diff=$hc-148;
				
				resizec($diff);
				
				
			}else{
				resizec(0);
				}

		}
		
	function selection(el){
		$('li').removeClass('sel');
		el.addClass('sel');
		}
	function displaycontent(ct,cb,bg,img,copyr,center){
				$('#homepic').html('<div id="teampic"><img src="img/'+img+'" width="226" height="152" /></div>');
		
				$('a').removeClass('selected');
				$("#texte").load(ct,function(){displayh();});
				cb.addClass('selected');
				$('#bg').load(bg,function(){firstresize(center);});
				
				//displayh();
				if(copyr=="copyr"){
					$('#copyright').html('photo:&copy;whitevision');
					}else{
							$('#copyright').html('');
						}
			
		}

	$('#chome').click(function(){
			displaycontent('contents/chome.html',$(this));
			
	});
	$('#cqui').click(function(){
			
			displaycontent('contents/cqui.html',$(this),'bg/bg04.html','miniQuiSommesNous.png');
	});
	$('#cmagasins').click(function(){
			
				displaycontent('contents/cmagasins2.html',$(this),'bg/bg08.html','miniMagasin.png');
	});
	$('#cuccle').click(function(){
			
			displaycontent('contents/cuccle.html',$(this),'bg/bg04.html','magaUccle.png');
	});
	$('#cwaterloo').click(function(){
			
			displaycontent('contents/cwaterloo.html',$(this),'bg/bg04.html','magaWaterloo.png','copyr');
	});
	$('.cwaterloo').click(function(){
			
			displaycontent('contents/cwaterloo.html',$(this),'bg/bg04.html','magaWaterloo.png','copyr');
	});
	$('#cmarques').click(function(){
			
			displaycontent('contents/cmarques.html',$(this),'bg/bg05.html','miniMontures.png');
	});
	
	
	$('#cmontures').click(function(){
		
			displaycontent('contents/cmontures.html',$(this),'bg/bg05.html','miniMontures.png');
	});
	$('#cverres').click(function(){
			
			displaycontent('contents/cverres.html',$(this),'bg/bg09.html','miniVerres.png');
	});
	$('#clentillesmarques').click(function(){
			
			displaycontent('contents/clentillesmarques.html',$(this),'bg/bg05.html','miniLentilles.png');
	});
	
	
	$('#cequipe').click(function(){
			
			displaycontent('contents/cequipe.php',$(this),'bg/bg04.html');
	});
	
	$('#cpourquoi').click(function(){
			
			displaycontent('contents/cpourquoi.html',$(this),'bg/bg10.html','miniSatis.png','','center');
	});
	$('#cequipement').click(function(){
			
			displaycontent('contents/cequipement.html',$(this),'bg/bg04.html','miniEquipementsTech.png');
	});
	$('#csatisfaction').click(function(){
			
			displaycontent('contents/csatisfaction.html',$(this),'bg/bg07.html','miniSatis.png');
	});
	$('#cmyopie').click(function(){
			
			displaycontent('contents/cmyopie.html',$(this),'bg/bg02.html','miniVue.png');
	});
	$('#chypermetropie').click(function(){
			
			displaycontent('contents/chypermetropie.html',$(this),'bg/bg02.html','miniVue.png');
	});
	$('#castygmatisme').click(function(){
			
			displaycontent('contents/castygmatisme.html',$(this),'bg/bg02.html','miniVue.png');
	});
	$('#cpresbytie').click(function(){
			
			displaycontent('contents/cpresbytie.html',$(this),'bg/bg02.html','miniVue.png');
	});
	$('#clunettes').click(function(){
			
			displaycontent('contents/clunettes.html',$(this),'bg/bg03.html','miniSolutions.png');
	});
	$('#clentilles').click(function(){
			
			displaycontent('contents/clentilles.html',$(this),'bg/bg03.html','miniLentilles2.png');
	});
	$('#coperation').click(function(){
			
			displaycontent('contents/coperation.html',$(this),'bg/bg03.html','miniSolutions.png');
	});
	$('#coptometrie').click(function(){
			
			displaycontent('contents/coptometrie.html',$(this),'bg/bg03.html','miniSolutions.png');
	});
	$('#cophtalmo').click(function(){
			
			displaycontent('contents/cophtalmo.html',$(this),'bg/bg03.html','miniSolutions.png');
	});
	$('#ccontact').click(function(){
			
			displaycontent('contents/ccontact.html',$(this),'bg/bg11.html','contactmini.png','','center');
	});
	$('#cemploi').click(function(){
			
			displaycontent('contents/cemploi.html',$(this),'bg/bg08.html','miniVI.png','','center');
	});
	
	$('#ccredits').click(function(){
			
			displaycontent('contents/ccredits.html');
	});
	

		//displaycontent('contents/chome.html',$(this));
		firstresize();
 });
