


window.onload = function(){
	
	    var j = jQuery.noConflict();
	    
	    
		setTimeout(function(){
		
			//j('span.wpcf7-not-valid-tip-no-ajax').fadeOut(); 
		},3000);
/*** Event input mask ***/

		j('input[type=text],textarea').each(function(){
			j(this).attr('default',j(this).attr('value'));
		});
		
	    j('input[type=text], textarea').click(function(){
			
			j(this).val('');
			
		}).blur(function(){
			if (j(this).attr('default') == j(this).val()){
				j(this).val('');
			}else if (j(this).val() == '') {
				j(this).val(j(this).attr('default'));
			}
 
		});
		initCufon();
		
		/* event hover social btn */

		j('.social-link a').each(function(){
			
			var classIco = j(this).attr('class');
			
			j(this).find('img').hover(function(){
				j(this).attr('src',"http://ukhom.com/wp-content/themes/ukhom-teasing/images/"+classIco+"-hover.png");
			},function(){
				j(this).attr('src',"http://ukhom.com/wp-content/themes/ukhom-teasing/images/"+classIco+"-ico.png");
			});
			
		});
			j('.wpsb_form_btn').hover(function(){

				var url = "http://ukhom.com/wp-content/themes/ukhom-teasing/images/bt-ok-hover.png";
								
				j(this).css('background',"url("+url+")");
			},function(){
				var url = "http://ukhom.com/wp-content/themes/ukhom-teasing/images/bt-ok.png";
				j(this).css('background-image',"url("+url+")");
			});

		j('.wpcf7 input[type=submit]').hover(function(){
				var url = "http://ukhom.com/wp-content/themes/ukhom-teasing/images/bt-contact-hover.png";
				
				j(this).css('background',"url("+url+")");
			},function(){
				var url = "http://ukhom.com/wp-content/themes/ukhom-teasing/images/bt-contact.png";
				j(this).css('background',"url("+url+")");
			});

    /*
  	
  	
  	    
	    setTimeout(function(){
	    	j('.content-teasing').show('explode', { pieces: 12 }, 500,function(){
		    	j('#teasing form').animate({opacity : 1},200);
	    	});
	    },000);	
	    
	    setTimeout(function(){
	       j('#hp-text-left ').animate({ 	
        		right: "67%",
          		opacity : 1 
	        },{
    	        duration: 'slow',
        		easing: 'easeOutBounce',
		    });
	    },500);
	    	
	    setTimeout(function(){
	        j('#hp-text-right').animate({ 	
    	   		left: "67%",
	       		opacity : 1 
       		},{
        		duration: 'slow',
	    	    easing: 'easeOutBounce'
			});
			
	    },1000);
	
	    setTimeout(function(){
	        j('#contact-form').animate({ 	
    	   		top: "69%",
	       		opacity : 1 
       		},{
        		duration: 'slow',
	    	    easing: 'easeOutBounce'
			});
			
	    },1400);
	    
	    setTimeout(function(){
	        j('#footer').animate({ 	
    	   		height: "24px"
       		},{
        		duration: 'slow'
        	});
			
	    },00);

  	
	initCufon();
	//alert(j.browser.version.substr(0,1));
	if ( (!j.browser.msie) || ( (j.browser.msie) && (j.browser.version.substr(0,1)>8) ) ){
	//if ( (!j.browser.msie) ){
		
		j('#main div#slogan,#main-nav').css('margin-top','500px');
		j('#branding').css('opacity','0');
		j('#main').css('height','0%');
		j('body').css('overflow','hidden');
		j('#header').css('height','100%');
		j('#access').css({height :'-80px', opacity : 0});
		j('#footer').css({width :'100%', opacity : 0});

	    j('#branding').animate({
	            opacity : '1'
	    });
	
	    setTimeout(function(){
	    	initPage();
	    },2000);
	
	    initAjaxNav();
	    //initImage();
	    
	   
	    
	    //accelerometer(); 
	 	j("#access .menu ul li:eq(3) a").click(function(){
	 	
			//initRefPageEvent();
		});
		
		j("#access .menu ul li:eq(1) a").click(function(){
	 	
			initUkhomPageEvent();
		});
		//Reference
		j("#access .menu ul").lavaLamp({ fx: "linear", speed: 200 });
		initHomePage();
		
	}else{
  		
  		//j("#access .menu ul").lavaLamp({ fx: "linear", speed: 200 });
	}
	
	j(".list-categ-service,.list-categ-activite").hover(function(){
		j(this).animate({height : "100%"},200);
	},function(){ 
		j(this).animate({height : "25px"},200);
	});
	
    j('ul').each(function(){
		j(this).find('li.cat-item:first > a').append('<img style="margin-bottom:4px;margin-left:20px;" src="http://ukhom.com/wp-content/themes/ukhom/images/listarrow.png" />');
    });
    
    j('body #wrapper').append(j('.middleline'));
    
 
	*/		
};


/* Animation d�saturate */



var j = jQuery.noConflict();
/*
var paircount = 0;
function initImage()
{
    j('#main-nav img').each(function(){

        var obj = this;

        j(this).addClass('des');

        obj.onload = null;
        var newthis = j(obj);
        if (j.browser.msie)
        {
          // You need this only if desaturate png with aplha channel
          newthis = j(newthis).desaturateImgFix();
        }
        // class for easy switch between color/gray version
        j(newthis).addClass("pair_" + ++paircount);
        var cloned = j(newthis).clone().attr('id', '');
        // reset onload event on cloned object
        j(cloned).get(0).onload = null;
        // add cloned after original image, we will switch between
         // original and cloned later
        j(cloned).insertAfter(newthis).addClass("color").hide();
        // desaturate original
        newthis = j(newthis).desaturate();

        j(cloned).hover(function(){
        },function(){
           j(this).fadeOut(200);
        });
        j(newthis).hover(function(){
           j(this).next().fadeIn(200);
        });
    });
   
};



*/
function initPage(){
	var j = jQuery.noConflict();
	
	
	
	j('#page-ref').animate({opacity:0},200);
	j('#branding img,#footer').animate({
		opacity : '1'
	},500);
	j('#access li a').css('color','#252525');
	Cufon.refresh('#access');
		
	j('#header').animate({
		height : '49%',
		top :0
	},500);
	
	
	j('body').animate({
		backgroundColor : "#252525"
	},500);
	
	j('#footer,#footer a').animate({
		
		color : "#DCD6C6"
	},500);
	
	j('#main').animate({
		height : '49%',
		color:'#DCD6C6',
		backgroundColor : "#FF4500"
	},500,function(){
		initIndex();
		
					
	});
	
	
}

function initUkhomPageEvent(){

	j('#main').animate({
		height : '40%',
		backgroundColor : "#DCD6C6",
		color:'#252525'
	},500);
	j('body').animate({
		backgroundColor : "#DCD6C6",
		color:'#252525'
	},500);
	j('#footer,#footer a').animate({
		color:'#252525'
	},500);
	j('#header').animate({

		height : '40%'
	},500);
	
	
}

function initRefPageEvent(){

	/*
	j('#header').animate({
		height : '100%',
		top : '24px'
	},500);
	j('#main').animate({
		height : '0%'
	},500);
	
	j('#access li a').css('color','#DCD6C6');
	Cufon.refresh('#access');
	
	j('#branding img').animate({
		opacity : '0'
	},500);
	j('#footer').animate({
		opacity : '1'
	},500);
	j('#footer').css('color','#DCD6C6').css('background','#252525');
	j('#header').animate({
		height : "-=24px"
	},0);
	
	j('#masthead').fadeOut();
	
	*/
	
	j('#main').animate({
		height : '48%'
	},500);
	
	j('#header').animate({
		height : '48%'
	},500);
}

function initIndex(){

	var j = jQuery.noConflict();

	var sec= 250;
	j('.ukhom').animate({
		opacity : 1
	},0,function(){
		j('.services').animate({
			opacity : 1
		},0,function(){
			j('.contact').animate({
				opacity 	: 1
			},0,function(){
				j('#slogan').animate({
						marginTop : '0'
						
				},sec,function(){
					j('#access').animate({
						top : '0',
						opacity : '1'
					},sec);
					j('#main-nav').animate({
							marginTop : '0'
					},sec,function(){
						j('#main').css('overflow-y','visible');
				
					});
				});
			});
		});
	});
}

function initAjaxNav(){

    var j = jQuery.noConflict();

    j('#access  a').each(function(){
           setAjaxEvent(j(this),'#container',j(this).attr('href'),'access');
            j(this).attr('href','javascript:void(0)');
    });
    

                    
    j('#main-nav  td a').each(function(){
            setAjaxEvent(j(this),'#container',j(this).attr('href'),'main-nav');
            j(this).attr('href','javascript:void(0)');
    });	
 
}


function initHomePage(){
	j("#main-nav a").each(function(){

		setAjaxEvent(j(this),'#container',j(this).attr('href'));
     	j(this).attr('href','javascript:void(0)');
		
		
		j(this).hover(function(){
			j(this).find('img').animate({opacity :0.5},200);
		},function(){
			j(this).find('img').animate({opacity :1},200);
		});
	});
}


function setAjaxEvent(elt,container,url,src){

    j(elt).click(function(src){
		
		j('#main').css('overflow-y','hidden');
		j('#header').css('overflow-y','hidden');
		
		j('.middleline').remove();		
		
		if(!j(elt).parent().hasClass('cat-item'))
			j('#menu-ref').remove();		
			
        var current = j('.current_page_item');
        j(current).removeClass('current_page_item').addClass('page_item');
        var wanted = j(elt).parent().attr('class');
      	
        switch(wanted) {

                case "ukhom" :
                		initUkhomPageEvent();
                        j("#access li:eq(1)").addClass("current_page_item");
                        j("#access li:eq(1)").click();   
                        var iconame = "ajax-loader.gif";    
                                 
                        break;
                case "services" :
                        j("#access li:eq(2)").addClass("current_page_item");
                        j("#access li:eq(2)").click();
                        //initPage();
                         var iconame = "ajax-loader.gif";
                        break;	
                case "reference" :     
               				                  
							initRefPageEvent();
							j("#access li:eq(3)").addClass("current_page_item");
                        	j("#access li:eq(3)").click();
                        	var iconame = "ajax-loader.gif";
                     		
                        break;
                default :
              
                        j(elt).parent().addClass('current_page_item current');
                        if(j(elt).parent().hasClass('cat-item')){
                        	var iconame = "ajax-loader.gif";
						}else{
							j('#page-ref').animate({opacity:0},200);
                        	initPage();
                        	var iconame = "ajax-loader.gif";
                        }
                       
                        break;
       			 }
		
		
		
				if(j(elt).parent().hasClass('page-item-8') || (wanted=='reference')){
	
					// var margeAfter ="0";	
					
					//var optionsContainer = { opacity:'0'};
					var optionsContainer = {marginLeft:'-2000px', opacity:'0'};
					var margeAfter ="2000px";

				}else{
					j('#page-ref').html('');
					var optionsContainer = {marginLeft:'-2000px', opacity:'0'};
					var margeAfter ="2000px";	
					
										
				}

			j(container).animate(optionsContainer,'speed',function(){
     		
            j('body').append('<img class="ajaxloader" style="bottom:25%;left :50%;margin-left:-32px;position:absolute;width : 64px" src="http://ukhom.com/wp-content/themes/ukhom/images/'+iconame+'" />');
            j(container).css('margin-left',margeAfter);
            j.ajax({
                url : url,
                async : true,
                method:'POST',
                success : function(data){
                    
					var html = j(data).find('#container').html();
					if(j(elt).parent().hasClass('page-item-8') || (wanted=='reference')){
					
						//REFERENCES PAGE
								
						var html = j(data).find('#content-page-ref').html();
	                    setTimeout(function(){
	                    
	                 	   j(container).html(html);
	                 	  
    	             	  j(container).animate({marginLeft:'-475px', opacity:'1'},'speed');
    	             	   j('.cat-item a').each(function(){
						        setAjaxEvent(j(this),'#post-thumbnail',j(this).attr('href'));
						        j(this).attr('href','javascript:void(0)');
						    });	
    	             	   initCufon();                    
                  		   initIndex();
              		 		j(".list-categ-service,.list-categ-activite").hover(function(){
								j(this).animate({height : "100%"},200);
							},function(){ 
								j(this).animate({height : "25px"},200);
							});
              		 		j('ul').each(function(){
              		 			j(this).find('li.cat-item:first > a').append('<img style="margin-top:8px;margin-left:20px;" src="http://ukhom.com/wp-content/themes/ukhom/images/listarrow.png" />');
              		 		});
              		 		
              		 		initToolTip();
              		 		j('body #wrapper').append(j('#menu-ref'));
              		 		
              		 		j('#header').css('overflow-y','visible');
                  		  	                  		  
                    	},500);
                    	
					}else{
					
						if(j(elt).parent().hasClass('cat-item')){
							
							//ARTICLES REFERENCES
							
							html = j(html).find('#post-thumbnail').html();
	    	                
	    	                j(container).html(html);
							j(container).animate({marginLeft:'-515px', opacity:'1'},'speed');
							initCufon();  
							initToolTip();
						  	   
						}else{
						
							// PAGES OTHER
						
							j(container).css('opacity',0).css('marginLeft','1000px'); 
							j(container).html(html);
							j('#masthead').fadeIn();
							j(container).animate({marginLeft:'-480px', opacity:'1'},'speed');
							initCufon();  
							                  
	                 	    j('.middleline').hide();
	                 	    j('body #wrapper').append(j('.middleline'));
	                 	    
	                 	    j('.middleline').fadeIn();
	                 	    j('.middleline').animate({
								display : 'block',
								backgroundColor : '#252525'
							},500);
	                 	    
	                    }	
						initHomePage();				
					}
					setTimeout(function(){j('#main').css('overflow-y','visible');},500);
						
	                    
                    j('#main-nav a').each(function(){
                        
                    	
                    }); 
					
                    if(j("#main-nav").length>0){
						//HOME PAGE
						initHomePage();
					}
                 	
                 	initwpcf7();
                 	j('.ajaxloader').remove();
                    
                }
            });

		
        });

    });
}




function initToolTip(){

	j('.tooltip').html("");
	j("#post-thumbnail div img").each(function(){
		
		j(this).hover(function(){
			j(this).animate({opacity :0.5},200);
			//j(this).parent().append('<img class="btnShow" style="z-index:32000;position:absolute;margin-top:-60px;margin-left:60px;" src="http://ukhom.com/wp-content/themes/ukhom/images/details.png" />');
		},function(){
			j(this).parent().find('.btnShow').remove();
			j(this).animate({opacity :1},200);
		});
		
		var url = j(this).attr('url');
		j(this).find('img').tooltip({ 
			effect: 'slide',
			onShow: function(){
				j('.tooltip').html('<img class="ajaxloader" style="bottom:45%;left :50%;width : 64px;margin-left:-32px;position:absolute;" src="http://ukhom.com/wp-content/themes/ukhom/images/ajax-loader.gif" />');
	 	
		 		j.ajax({
	                url : url,
	                async : true,
	                method:'POST',
	                success : function(data){
		 				j(data).find('.entry-content').hide()
		 				j('.tooltip').html(j(data).find('.post').html());
		 				//j('.tooltip .entry-content').fadeIn();
		 				
		 			}
		 		});
		 	},
		 	onHide : function(){
		 		j('.tooltip').html("");
		 	},
		 	onBeforeShow : function(){
			 	j('.tooltip').html("");
		 	}
		});
	});	
}

function initCufon(){

	if(!j.fontAvailable('Futura')) {
	

	    Cufon.set('fontFamily', 'Futura Std').replace('.title');
	    Cufon.set('fontFamily', 'Futura Std').replace('.share-ukhom');
   	    Cufon.set('fontFamily', 'Futura Std').replace('.catchphrase');
	    
    }
    
}


/* Animations contact form */

function initContactForm(){
	jQuery('#header').animate({height : "29%"});
	jQuery('#branding img').animate({
		height : "150px",
		marginTop : "35%",
		marginLeft : "33%",
		width : "150px",
		bottom : '0%'
	},"linear");
	jQuery('#main').animate({height:"69%"});
}

function resetContactForm(){

	jQuery('#header').animate({height : "49%"});
	jQuery('#branding img').animate({
		height : "260px",
		width : "264px",
		marginTop : "0%",
		marginLeft : "0%",
		clear : "both"
	},"linear");
	
	jQuery('#main').animate({height:"45%"});
}


/* Accelerometer */

function accelerometer() {
    
	window.addEventListener("MozOrientation", onMozOrientation, false);
	
}

//var cptRotate;

function onMozOrientation(event) {

  
	    var x = event.x;
    	if((x > 0.07) || (x < -0.03)){
	    	var leftPct = (47 + 47 * x) + "%";
	    	var degPct = (47 + 47 * x);
	    	j('#logo').css('-moz-transform','rotate('+(degPct-50)+'deg)');

	    
	    }
}

