jQuery(document).ready(function(){

	jQuery('.wanted_contact').click(function(){
		var temp = jQuery(this).attr("href");
		var infos = temp.split('|');
		
		var id = infos[0];
		var type = infos[1];
		var model = infos[2];
		var contact = infos[3];
		
		
  		jQuery.ajax({

			type: "POST",
			url: "contact.php",
			data: "id="+id+"&type="+type+"&model="+model+"&contact="+contact+"&action=request",
			success: function(msg){
			
				jQuery('#osx-modal-data7').html(msg);
				jQuery('body').css("overflow","hidden");
				
				var OSX7 = {
					container: null,
					open: function (d) {
						var self = this;
						self.container = d.container[0];
						d.overlay.fadeIn('slow', function () {
							jQuery("#osx-modal-content7", self.container).show();
							var title = jQuery("#osx-modal-title7", self.container);
							title.show();
							d.container.slideDown('slow', function () {
								setTimeout(function () {
									var h = jQuery("#osx-modal-data7", self.container).height()+ title.height()	+ 20; // padding
									d.container.animate(
										{height: h}, 
										200,
										function () {
											jQuery("div.close", self.container).show();
											jQuery("#osx-modal-data7").show();
										}
									);
								}, 300);
							});
						});
					},
					close: function (d) {
						var self = this;
						d.container.animate(
							{top:"-" + (d.container.height() + 20)},
							500,
							function () {
								self.close();
								jQuery('body').css("overflow","auto");
								// or jQuery.modal.close();
							}
						);
					}
				};
				
				jQuery("#osx-modal-content7").modal({
					overlayId: 'osx-overlay7',
					containerId: 'osx-container7',
					closeHTML: '<div class="close"><a href="#" class="simplemodal-close">x</a></div>',
					minHeight:80,
					opacity:65, 
					position:['0'],
					overlayClose:true,
					onOpen:OSX7.open,
					onClose:OSX7.close
				});
				
			}
				
		});
		return false;
	});
	
	
	jQuery(function(){
		if(typeof(jQuery("#id_contact").attr("value"))=="undefined" || jQuery("#id_contact").attr("value")==""){
			//alert("hehehe");
		}else{
			//alert(jQuery("#id_contact").attr("value"));
			contact(jQuery("#id_contact").attr("value"));
		}
	});
	
	function contact(temp){
		
		var infos = temp.split('|');
		
		
		var id = infos[0];
		var type = infos[1];
		var model = infos[2];
		var contact = infos[3];
		
		jQuery.ajax({

			type: "POST",
			url: "contact.php",
			data: "id="+id+"&type="+type+"&model="+model+"&contact="+contact+"&action=request",
			success: function(msg){
			
				jQuery('#osx-modal-data7').html(msg);
				//Function mail contact
				jQuery('#contact').click(function(){
					var donnees = jQuery('#osx-modal-data7 .customForm').serialize();
					jQuery.ajax({
						type: 'POST',
						url: 'contact.php',
						data: donnees,
						success: function(data){
							jQuery('#osx-modal-data7').html(data.msg);
						},
						dataType: 'json'
				 	});
					

																			   
					return(false);															   
				});
				jQuery('body').css("overflow","hidden");
				
				var OSX7 = {
					container: null,
					open: function (d) {
						var self = this;
						self.container = d.container[0];
						d.overlay.fadeIn('slow', function () {
							jQuery("#osx-modal-content7", self.container).show();
							var title = jQuery("#osx-modal-title7", self.container);
							title.show();
							d.container.slideDown('slow', function () {
								setTimeout(function () {
									var h = jQuery("#osx-modal-data7", self.container).height()+ title.height()	+ 20; // padding
									d.container.animate(
										{height: h}, 
										200,
										function () {
											jQuery("div.close", self.container).show();
											jQuery("#osx-modal-data7").show();
										}
									);
								}, 300);
							});
						});
					},
					close: function (d) {
						var self = this;
						d.container.animate(
							{top:"-" + (d.container.height() + 20)},
							500,
							function () {
								self.close();
								jQuery('body').css("overflow","auto");
								// or jQuery.modal.close();
							}
						);
					}
				};
				
				jQuery("#osx-modal-content7").modal({
					overlayId: 'osx-overlay7',
					containerId: 'osx-container7',
					closeHTML: '<div class="close"><a href="#" class="simplemodal-close">x</a></div>',
					minHeight:80,
					opacity:65, 
					position:['0'],
					overlayClose:true,
					onOpen:OSX7.open,
					onClose:OSX7.close
				});
				
			}
				
		});
		return false;
	};
	
	
	

		jQuery("#contact_wanted").live('click',function(){
			if (jQuery("#form_contact #email").attr("value") != ""){
				jQuery.ajax({
					type: "POST",
					url: "contact.php",
					data: jQuery('#form_contact').serialize(),
					success: function(data){
						if(data.state == '1')
							jQuery('#form_contact').html(data.msg);
						else
							jQuery('#form_contact').html(data.msg);
					},
					dataType: 'json'
				});
			}
		});



});
		
