$('document').ready(function(){

});

$("#twitter").live('click',function(){
    var width  = 575,
        height = 250,
        left   = ($(window).width()  - width)  / 2,
        top    = ($(window).height() - height) / 2,
        url    = "http://twitter.com/share?url="+document.location+"&text="+document.title,
        opts   = 'status=1' +
                 ',width='  + width  +
                 ',height=' + height +
                 ',top='    + top    +
                 ',left='   + left;
	window.open(url, 'twitter', opts);

		return false;
		});

$("#facebook").live('click',function(){
    var width  = 575,
        height = 350,
        left   = ($(window).width()  - width)  / 2,
        top    = ($(window).height() - height) / 2,
        url    = "https://www.facebook.com/sharer/sharer.php?u="+document.location,
        opts   = 'status=1' +
                 ',width='  + width  +
                 ',height=' + height +
                 ',top='    + top    +
                 ',left='   + left;
	window.open(url, 'facebook', opts);

		return false;
		});


$("#googleplus").live('click',function(){
    var width  = 575,
        height = 350,
        left   = ($(window).width()  - width)  / 2,
        top    = ($(window).height() - height) / 2,
        url    = "https://m.google.com/app/plus/x/?v=compose&content="+document.title+" "+document.location,
        opts   = 'status=1' +
                 ',width='  + width  +
                 ',height=' + height +
                 ',top='    + top    +
                 ',left='   + left;
	window.open(url, 'facebook', opts);

		return false;
		});


$(function(){
    $("#mlist").multiselect({
        selectedText: "# sur # sélectionné",
        checkAllText: "Toutes",
        uncheckAllText: "Aucune",
        noneSelectedText: "Les listes"
    });
});


$("#mailing-register input[type=text]").live('focus',function(){
    var curVal = $(this).val();
    var defVal = $(this).attr("defval");
    if (curVal===defVal){
        $(this).val("");
    }
});

$("#mailing-register input[type=text]").live('blur',function(){
    var curVal = $(this).val();
    var defVal = $(this).attr("defval");
    if (curVal===""){
        $(this).val(defVal);
    }
});


$("#mailing-register-btn").live('click',function(){
    var formData = $('#mailing-register-form').serialize();
    $.ajax({
       url: "/mailing_register.php",
       type: "POST",
       dataType: "json",
       data: formData,
       success: function(){

       }
    });
});

$('#envoi').live('click',function(){
    var formData = $("form#contact-form").serialize();
    $.ajax({
        url: "/contact_submit.php",
        type: "post",
        dataType: "json",
        data: formData,
        success: function(contactReturn){
            if(contactReturn.ok==="ok") {
                $('.contact_site_right').html(contactReturn.message);
            }
            else {
                alert(contactReturn.message);
            }
        }
    });
    return false;
});
$('#divers').live('click', function () {
   $.ajax({
	url: "/page.php?app=article&id=32&print=1",
	dataType: "html",
	type: "GET",
	success: function (getData) {
	    var w = $(document).width();
	    var h = $(document).height();
	    var s1 = window.pageYOffset + 30;
	    
	    $('<div style="background-color: #000000;height:'+h+'px;left: 0;position: absolute;top: 0;width:'+w+'px;z-index: 90;opacity: 0.8;"></div>').appendTo('body');
	    $('<div style="position:absolute; top: '+s1+'px; left:0; width:'+w+'px;z-index: 100;background-color: #FFF;height:200px;"></div>').appendTo('body');
	}
   });
   return false;
});

$('ul.level0 li').live('mouseover',function(){
    $('ul.level1',this).show();
    // alert(t);
});
$('ul.level0 li').live('mouseout',function(){
    $('ul.level1',this).hide();
    // alert(t);
});


$('#fiat-logo').live('mouseover',function(){
	$(this).animate({
		"width": "150px",
		"height": "150px"
	});
});

$('#fiat-logo').live('mouseout',function(){
	$(this).animate({
		"width": "88px",
		"height": "88px"
	});
});


$('#lancia-logo').live('mouseover',function(){
	$(this).animate({
		"width": "150px",
		"height": "150px"
	});
});

$('#lancia-logo').live('mouseout',function(){
	$(this).animate({
		"width": "88px",
		"height": "88px"
	});
});

$('#alfa-romeo-logo').live('mouseover',function(){
	$(this).animate({
		"width": "150px",
		"height": "150px"
	});
});

$('#alfa-romeo-logo').live('mouseout',function(){
	$(this).animate({
		"width": "88px",
		"height": "88px"
	});
});

$('#fiat-pro-logo').live('mouseover',function(){
	$(this).animate({
		"width": "155px",
		"height": "150px"
	});
});

$('#fiat-pro-logo').live('mouseout',function(){
	$(this).animate({
		"width": "91px",
		"height": "88px"
	});
}); 

$('#ada-loc-logo').live('mouseover',function(){
	$(this).animate({
		"width": "197px",
		"height": "150px"
	});
});

$('#ada-loc-logo').live('mouseout',function(){
	$(this).animate({
		"width": "116px",
		"height": "88px"
	});
});


$('.logos a').live('click',function(){
	$(this).blur();
});


$("#captchaimg").live('click',function(){
	$(this).attr('src','/captcha/img.php?v='+randomString());
});
function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
};


$("#rechercheroccasion").live('click',function(){
	$('#rechercheoccasion').toggleClass("hidden");
	return false;
});



$('#interet').live('click', function(){
	$('input[name=url]').val(document.location);
	$('#carform').toggleClass("hidden");
	return false;
});


$('#submit-car-form').live('click',function(){
    var formData = $('form#contact-car-form').serialize();
    $.ajax({
       url: "/interet_occasion.php",
       dataType: "json",
       type: "POST",
       data: formData,
       success: function(fResponse){
           if (fResponse.ok==="ok") {
               $('#carform').toggleClass("hidden");
           }
         alert(fResponse.message);
       }
    });
    // alert(formData);
    return false;
});

