var imgPath = "/extension/carre/design/carre/images/";
var countProjects = 0;

$(document).ready(function(){
	
	/*Tooltip*/
	$('#left_btn a').easyTooltip({
		xOffset: -145,		
		yOffset: 50
	});
	$('.bloc h2').easyTooltip({
		xOffset: -145,		
		yOffset: 50
	});
	$('.top3 a').easyTooltip({
		xOffset: -145,		
		yOffset: 50
	});
	$('#imagecarousel a').easyTooltip({
		xOffset: -145,		
		yOffset: 50
	});

	/* prettycheckboxes */							 
	$('input[type=radio]').prettyCheckboxes({
	checkboxWidth: 19, // The width of your custom checkbox
	checkboxHeight: 19, // The height of your custom checkbox
	className : 'prettyCheckbox', // The classname of your custom checkbox
	display: 'inline' // The style you want it to be display (inline or list)
	});
	$('input.checkbox').prettyCheckboxes({
	checkboxWidth: 19, // The width of your custom checkbox
	checkboxHeight: 19, // The height of your custom checkbox
	className : 'prettyCheckbox', // The classname of your custom checkbox
	display: 'inline' // The style you want it to be display (inline or list)
	}); 

    $('.hided').hide();
	$('.expand').click(function(){
		$(this).next().slideToggle("slow");
	});
	/* select popup */
	$('.popup').hide();
	$('.txtentries').children().next().click(function(){
		if ($(this).is(':checked')) {
			$(this).prev().show();
		}else if ($('.txtentries').find('.popup')) {
			$('.popup').hide();
			$(this).prev().prev().fadeIn();
		}else{
			$(this).prev().hide();
		}
	});
	$('.crux').click(function(){
		$(this).parent().hide();
	});
	$('#research #budget input, #research #surface input').focus(function(){
		$('.popup').hide();
	});
	$('#research #budget h2').click(function(){
		$('#input1').focus();
	});
	/*Remove inputValue onfocus and recall default inputValue onblur*/
	$('#research #budget input, #research #surface input').focus(function() {
		value=$(this).val();
		if($(this).val()!=="0") {
			$(this).val(value);
		}else if($(this).val()=="0"){
			$(this).val("");
		}
		
	});
	$('#research #budget input, #research #surface input').blur(function() {
		value=$(this).val();
		if($(this).val()!=="") {
			$(this).val(value);
		}else if($(this).val()==""){
			$(this).val("0");
		}
	});
	
	$('#research #surface h2').click(function(){
		$('#input3').focus();
	});
	
	if($('input#office').is(':checked')){
		$('input#garage').parent().hide();
		$('input#parking').parent().hide();
	}
	 
	$('input#office').click(function(){
		if($('input#office').is(':checked')){
			$('input#garage').parent().hide();
			$('input#parking').parent().hide();
		}
	});
	
	$('input#house').click(function(){
		if($(this).is(':checked')){
			$('input#garage').parent().show();
			$('input#parking').parent().show();
		}
	});
	$('input#appart').click(function(){
		if($(this).is(':checked')){
			$('input#garage').parent().show();
			$('input#parking').parent().show();
		}
	});
	
	
	
	/*$.tablesorter.addParser({
		id: "integer",
		is: function(s) {
			return s.match(new RegExp(/^\d+$/));
		},
		format: function(s) {
			return $.tablesorter.formatInt(s);
		},
		type: "numeric"
	});
	
	$.tablesorter.addParser({
		id: "floating",
		is: function(s) {
			return s.match(new RegExp(/^(\+|-)?[0-9]+\.[0-9]+((E|e)(\+|-)?[0-9]+)?$/));
		},
		format: function(s) {
			return $.tablesorter.formatFloat(s.replace(new RegExp(/,/),""));
		},
		type: "numeric"
	});*/
	$('tr.hiddencell td').hide();
	$( "#resultat_resultats" ).collapsible().tablesorter();
	$('.photoyes').children().hide();
	$('.photoyes').hover(
		function(){$(this).children().show();},
		function(){$(this).children().hide();}
	);
	
	//Slideshow projet automatique
	
	$('#slideform').cycle({ 
	    fx:     'fade', 
	    speed:  'fast',	 
	    timeout: 0, 
	    next:   '#back', 
	    prev:   '#for' 
	});
	
	//SlideForm
	
	$('#slideproject').cycle({ 
	    fx:     'scrollHorz', 
	    speed:  'slow', 
	    timeout: 5000, 
	    next:   '#back', 
	    prev:   '#for' 
	});
	
	
		
	//jCarousel
	
	jQuery('#carousel').jcarousel();
	
	$('#carousel a').click(function(){
		$('#imagecarousel img').attr('src', this.href);
		$('.lightbox').attr('href', this.href.replace("http://www.carre.lu/var/carre/storage/easypilot/scale/", "http://www.carre.lu/var/carre/storage/easypilot/img/"));
		return false;	
	});
	
	// Lightbox
	$(function() {
        $('.lightbox').lightBox();
    });
	
	//height equal
	for ( var i = 1; i < countProjects; i = i + 2 ){
		var highest = 0;
		if ( document.getElementById( 'bloc_immo_' + i ) && document.getElementById( 'bloc_immo_' + ( i + 1 ) ) ){
			if ( document.getElementById( 'bloc_immo_' + i ).offsetHeight > highest ) highest = document.getElementById( 'bloc_immo_' + i ).offsetHeight;
			if ( document.getElementById( 'bloc_immo_' + ( i + 1 ) ).offsetHeight > highest ) highest = document.getElementById( 'bloc_immo_' + ( i + 1 ) ).offsetHeight;
			document.getElementById( 'bloc_immo_' + i ).style.height = document.getElementById( 'bloc_immo_' + ( i + 1 ) ).style.height = highest + "px";
		}
	}
	if ( document.getElementById( 'slideshow' )) document.getElementById( 'slideshow' ).style.visibility = 'visible';
});

function changeClassName( id, className ){
	var elt = document.getElementById( id );
	if ( elt && elt.className != className ) elt.className = className;
}