var ie6 = false;
$(document).ready(function () {
	if(jQuery.browser.version == "6.0" && jQuery.browser.msie){
		ie6 = true;
	}
	
});

window.onload = function() {

	$('a[href*=#p],#btnWorks').click(function() {
		$(window).scrollTo( ''+$(this).attr("href")+'', 500 );
		return false;
	});
	$('#btnContact').click(
		function() {
			
			if($("#contact").css("display") == 'none')  {
				$(this).css("text-transform","uppercase");
			}
			else{
				$(this).css("text-transform","capitalize");
			}
			$("#contact").slideToggle("normal");
		}
	);
	
	

	
	
	var emailLinkElm = $("#contactLink");
	var newText = emailLinkElm.text();
	var anchorLink = emailLinkElm.attr("href"); 
	var fakeMailExploded = anchorLink.split('[AT]');
	var standardMail = fakeMailExploded[0]+'@'+fakeMailExploded[1];
	emailLinkElm.attr("href",standardMail);
	emailLinkElm.html(standardMail);
	

	var newText2 = newText.split('[AT]');
	var newText3 = newText2[0]+'@'+newText2[1];
	emailLinkElm.text(newText3);	
}






function popin(){
	

		
	this.popin_type;
	this.popin_link;
	this.popin_node;
	this.popin_title;
	
	this.build = function(popin){
		$(document.body).append('<div id="overlay"></div>');
		var elm_window_width = $(document.body).innerWidth();
		var elm_window_height = $(document.body).innerHeight();
		$("#overlay").css({'width' : elm_window_width,'height' : elm_window_height});


	
	
		 var target_elm =  $(document.body); 
		if(ie6) {
			target_elm =  $(".msie6"); 
		}
		target_elm.append('<div class="'+this.popin_type+'"><div id="popin"><a class="btnClose" href="#">Close </a><p class="popinTitle">'+this.popin_title+' <span>Vidéo</span></p><div class="popinN1"><div class="popinN2"></div></div></div></div>');
		var video = this.popin_node.clone();
		$("#popin .popinN2").append(video);
		$("#popin .media").media();
		

		
		$("#popin .btnClose").bind("click",function(){
			popin.close(popin);
			return false;
		});					
	 
	}
	this.remove = function(){
		$("#overlay").remove();
		$("#popin").remove();
	}
	this.close = function(popin){	
		if($.browser.msie){
			$("#popin").css('display','none');
			popin.remove();
		}
		else{
			$("#popin").fadeOut("fast",function () {
				popin.remove();
			});
		} 
		$("#overlay").fadeTo("slow", 0);
	}
	this.open = function(){
		
		$("#overlay").css('display','block');
	
		$("#overlay").css("opacity", 0.7);
		$("#overlay").fadeTo("fast", 0.7);
		
		if($.browser.msie){
			$("#popin").css('display','block');
		}
		else{
			$("#popin").fadeIn("slow",function () {
			});
		} 
		//557
		$("#popin").css("top",$(window).scrollTop() - ( (557 - $(window).height())  / 2) ); 
	}

	this.init = function(popin){
		$(".media").bind("click",function(){

			popin.popin_type = $(this).attr("rel");
			popin.popin_link = $(this).attr("href");
			popin.popin_title = $(this).attr("title");
			popin.popin_node = $(this);
			popin.build(popin);
			popin.open();
			
			return false;
		});
		
	}
	
	
	
	this.successForm = function(popin){
		popin.remove(popin);	
		popin.build(popin);
		popin.open();
	}

}

$(document).ready(function () {

	var popins = new popin();
	popins.init(popins);
	
});
