jQuery(document).ready(function(){
	/* Old array used for debug keep here in case of trouble
	var countries = {
		"France": {
			"French Riviera" : ["Cannes", "Cap d'Ail", "Cap d'Antibes", "Cap Ferrat", "Eze", "Grasse", "Monaco", "Mougins", "Nice", "Saint-Tropez", "Villefrance sur Mer"]
		}
	};*/
	/* This is basic - uses default settings */
	
	if(jQuery('#country').length > 0){
	jQuery('#country').change(function(){
		jQuery('#region').html('<option selected="selected" value="">All regions</option>');
		jQuery(this).css('color','blue');
		for (var key in countries[jQuery('#country option:selected').val()])
			jQuery('#region').append('<option>' + key + '</option>');
	});
	}
	
	if (jQuery('#region').length > 0){
	jQuery('#region').change(function(){
		jQuery('#location').html('<option selected="selected" value="">All locations</option>');
		jQuery(this).css('color','blue');
		var length = countries[jQuery('#country option:selected').val()][jQuery('#region option:selected').val()].length;
		var val;
		for (var i = 0; i < length; i++){
			val = countries[jQuery('#country option:selected').val()][jQuery('#region option:selected').val()][i];
			jQuery('#location').append('<option>' + val + '</option>');
		}
	});
	}
	
	if (jQuery('select').length > 0){
	jQuery('select').change(function(){
		jQuery(this).css('color','#004687');
	});
	
	}
	if (jQuery('.gallery_image_fancybox').length > 0){
		jQuery('.gallery_image_fancybox').fancybox();
	}
	try{
		initialize_this_map();
		

	}catch(e){
	}
	
	if (jQuery('.property_content_description').length > 0){
	var description_height = jQuery('.property_content_description').height();
	
	if (description_height > 130){
		jQuery('.property_content_description').css('height','130px');
		
		jQuery('#show_content_description').click(function(){
			if (jQuery('.property_content_description').hasClass('opened')){
				jQuery('.property_content_description').removeClass('opened');
				jQuery('.property_content_description').addClass('closed').animate({
					'height' : '-=' + (- (130 - description_height))
				},500);
			}else{
				jQuery('.property_content_description').removeClass('closed');
				jQuery('.property_content_description').addClass('opened').animate({
					'height' : '+=' + (description_height - 130)
				},500);
			}
		});
	}else{
		jQuery('#show_content_description').remove();
	}
	}else {
		jQuery('#show_content_description').hide();
	}
	
	
	if (jQuery('.tradeshow_buttons').length > 0){
	jQuery('.tradeshow_buttons').click(function(){
		if (jQuery(this).parent().parent().hasClass('tradeshow_list')){
			jQuery('.tradeshow_list').fadeOut(400,function(){
				jQuery('.tradeshow_list2').fadeIn(400);
			});
		}else{
			jQuery('.tradeshow_list2').fadeOut(400,function(){
				jQuery('.tradeshow_list').fadeIn(400);
			});
		}
	});
	}
	if (jQuery('.add_beauchamp a').length > 0 && jQuery('.thumb-bloc .gallery-image1').length > 0){
	jQuery('.add_beauchamp a').click(function(e){
		e.preventDefault();
		var of1 = jQuery('.thumb-bloc .gallery-image1').offset();
		var of2 = jQuery('.my_beauchamp_link').offset();
		var newLeft = '-=' + (of1.left - of2.left);
		var newTop = '-=' + (of1.top - of2.top);
		jQuery('body').append(jQuery('.thumb-bloc .gallery-image1').clone().css('width','124px').css('position','absolute').css('z-index','1000').css('left',(of1.left+2)+'px').css('top',(of1.top+2)+'px').attr('id','specialaddingbeauchamp'));
		jQuery('#specialaddingbeauchamp').animate({ left : newLeft, top : newTop},500, function(){jQuery(this).fadeOut(400,function(){jQuery(this).remove(); 
		window.location = jQuery('.add_beauchamp a').attr('href');
		});});
	});
	}
	if (jQuery('a.add_beauchamp').length > 0 && jQuery('.wpp_overview_left_column').length > 0){
	jQuery('.add_beauchamp').click(function(e){
		e.preventDefault();
		var link = jQuery(this).attr('href');
		var prev = jQuery(this).parent().siblings('.wpp_overview_left_column').find('img');
		var of1 = prev.offset();
		var of2 = jQuery('.my_beauchamp_link').offset();
		var newLeft = '-=' + (of1.left - of2.left);
		var newTop = '-=' + (of1.top - of2.top);
		jQuery('body').append(prev.clone().css('width','124px').css('position','absolute').css('z-index','1000').css('left',(of1.left+2)+'px').css('top',(of1.top+2)+'px').attr('id','specialaddingbeauchamp'));
		jQuery('#specialaddingbeauchamp').animate({ left : newLeft, top : newTop},500, function(){jQuery(this).fadeOut(400,function(){jQuery(this).remove(); 
		window.location = link;
		});});
	});
	}
	
	if(jQuery('.iframe').length > 0){
	jQuery(".iframe").fancybox({ 'width': 315, 'height': 390 });
	}
	
	
});

jQuery(window).load(function() {
	if (jQuery('#slider').length > 0){
	jQuery('#slider').show();
    jQuery('#slider').nivoSlider({
        effect: 'boxRandom', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 500, // Slide transition speed
        pauseTime: 3000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: false, // Next & Prev navigation
        directionNavHide: true, // Only show on hover
        controlNav: false, // 1,2,3... navigation
        keyboardNav: false, // Use left & right arrows
        pauseOnHover: false, // Stop animation while hovering
        captionOpacity: 0.8, // Universal caption opacity
        randomStart: true // Start on a random slide
	});
	}
	if ( navigator.userAgent.toLowerCase().indexOf( "safari" ) != -1){
		jQuery('.menu-deroulant li ul').css('top','15px');
	}
}); 
