/* Author: Gaëtan Janssens, gaetan.janssens@milpix.com
*/
//var htmlid;

function jqueryLoaded() {
	var language = $('#lang').val();
	if (!language){
		var language = "fr";
	}
	SnapABug.setLocale(language);
	SnapABug.addButton("d9128274-5d1f-4225-af06-a6421a03687a","1","55%");
	$('#gallerie').slides({
		preload: true,
		generateNextPrev: true,
		play:5000
	});
	$(".encart").addClass("grid_12");
	$(".encart").css("margin-left","-5px");
	htmlid = $('html').attr("id");
	//checkHtmlIdChange(htmlid);
	if (language=='en'){
		$('.moreinf').css("font-size","18px");
		$('.btncontact').css("font-size","22px");
	}
	$('.btncontact').click(function(){
		SnapABug.startLink();
	});
	$('.open').click(function(){
		SnapABug.startLink();
	});
	$('a.email_popup').click(function(){
		SnapABug.startLink();
		$(this).trigger("SnapPopup");
		return false;
	});

	$('#SnapABug_WP').on("click",function(){
		$(this).append($('#SnapABug_email').next().clone(false).css("top","0").find("input").removeAttr("name").attr("name","name"));
		$(this).append($('#SnapABug_email').clone(false).css("top","0").removeAttr("id").attr("id","SnapABug_name"));
	});

	$("body").on("SnapPopup", "#SnapABug_WP", function(){
		alert("hello");	
		$(this).find("form").prepend('<div class="SnapABug_added"><div id="SnapABug_name">Votre nom :</div><div><input type="text" id="name" name="name" value="" size="10"></div></div>');
	});

	$('#calltoaction').find("img").each(function(){
		$(this).css("width",($(this).parent().width()+10));
	});
	$('a').each(function(){
		if ($(this).attr("href") == '#') {
			$(this).css("color","#BDCCD4");
		}
	});
	var url = $.url(); //the current page url
	//var tmp = url.attr('path');
	var file = url.attr('file');
	switch(language){
		case "en":
			$('body').prepend('<div class="switchlang"><a href="/fr/'+file+'">FR</a></div>');
			break;
		case "fr":
			$('body').prepend('<div class="switchlang"><a href="/en/'+file+'">EN</a></div>');
			break;
	}
};

function checkJquery() {
	if (window.jQuery) {
		jqueryLoaded();
	} else {
		window.setTimeout(checkJquery, 100);
	}
};
/*function checkHtmlIdChange() {
	if (htmlid == $('html').attr("id")) {
		window.setTimeout(checkHtmlIdChange, 100);
	} else {
		//$('.slides_container').height("250px");
		htmlid = $('html').attr("id");
		checkHtmlIdChange(htmlid);
	}
};*/

checkJquery();

$.fn.copyCSS = function(source){
    var dom = $(source).get(0);
    var style;
    var dest = {};
    if(window.getComputedStyle){
        var camelize = function(a,b){
            return b.toUpperCase();
        };
        style = window.getComputedStyle(dom, null);
        for(var i = 0, l = style.length; i < l; i++){
            var prop = style[i];
            var camel = prop.replace(/\-([a-z])/g, camelize);
            var val = style.getPropertyValue(prop);
            dest[camel] = val;
        };
        return this.css(dest);
    };
    if(style = dom.currentStyle){
        for(var prop in style){
            dest[prop] = style[prop];
        };
        return this.css(dest);
   };
   if(style = dom.style){
      for(var prop in style){
        if(typeof style[prop] != 'function'){
          dest[prop] = style[prop];
        };
      };
    };
    return this.css(dest);
};
