$(document).ready(function(){
	$('#Cities a.item:last').addClass('last');
	/*$('a.active').hover(function() {
		$(this).removeAttr('href');
	});
	$('li.active a').hover(function() {
		$(this).removeAttr('href');
	});
	$('div.active a').hover(function() {
		$(this).removeAttr('href');
	});*/
	$('#Navigation li.active a').hover(function() {
		$(this).removeAttr('href');
	});
	$('.order_propose_button a.active').hover(function() {
		$(this).removeAttr('href');
	});
	$('.ad-thumb-list .zoom').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	$('.ad-thumb-list .zoom').click(function() {
		$.fancybox ({
			type: 'image',
			href: $(this).parent().attr('href')
		});
	});
	
	// Buildings submenu
	$('.Buildings li.haschildren').hover(function() {
		$(this).find('ul').show();
		$(this).addClass('hover');
	}, function() {
		$(this).find('ul').hide();
		$(this).removeClass('hover');
	});
	$('.Buildings li li:first').addClass('first');
	
	// Animation for certificate button
	$('.certificate a').hover(function() {
	  $(this).find('img.anmg').animate({top:'-10px'},{queue:false,duration:200});
	  $(this).find('span.anmsh').addClass('hover');
	}, function(){
		$(this).find('img.anmg').animate({top:'0px'},{queue:false,duration:200});
		$(this).find('span.anmsh').removeClass('hover');
	});
	
	$('.property-filter .close').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	$('.city').hover(function() {
		$(this).css({opacity: 1})
	}, function() {
		$(this).css({opacity: 0.5})
	});
	
	/*
	/// Advantages ***** Boxes \\
	$('.advantages .item span.trigger').click(function() {
		$('.advantages .Box').hide();
		if ($(this).parent().children('.Box').is(':visible')) {
			$(this).parent().children('.Box').hide();
		}
		else {
			$(this).parent().children('.Box').show();	
		}
	});
	$('.advantages .item .Box .close span').click(function() {
		$(this).parent().parent().parent().parent('.Box').hide();
	});
	$('body').click(function() {
		$('.advantages .Box').hide();
	});
	$('.advantages').click(function(event){
		event.stopPropagation();
	});
	*/
	
	$('.advantages .item span.trigger').bind('mouseover', function() {
		$(this).parent().children('.Box').show();
	});
	$('.advantages .item span.trigger').bind('mouseout', function() {
		$(this).parent().children('.Box').hide();
	});
	
	
	// Call me ***** \\
	$('#CallMe_Trigger').click(function() {
		$('.Property_Valuation').hide();
		$('.Property_Valuation_Called').show();
	});
	$('.Property_Valuation_Called .pvc_close_trigger').click(function(){
		$('.Property_Valuation_Called').hide();
		$('.Property_Valuation').show();
	});
	$('.cmf_defv').each(function() {
    var default_value = this.value;
    $(this).focus(function() {
        if(this.value == default_value) {
            this.value = '';
			$(this).addClass('focus');
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            this.value = default_value;
			$(this).removeClass('focus');
        }
    });
	});
	
	// Contacts ***** \\
	$('.contact_mainb .item a.trigger').click(function() {
		$('.contact_mainb .item .cvis').addClass('hidden');
		$('.contact_mainb .item a.trigger').removeClass('current');
		if (!$(this).siblings('.cvis').hasClass('hidden')) {
			//$(this).siblings('.cvis').addClass('hidden');
			$(this).removeClass('current');
		}
		else {
			$(this).siblings('.cvis').removeClass('hidden');
			$(this).addClass('current');
		}
	});
	
	// Property ***** \\
	$('#Property_Wrapper .info_property table tr:odd').addClass('odd');
	$('#Property_Wrapper .info_property table tr td:first-child').addClass('first');
	
	//$("span[class='checkbox']").addClass("unchecked");
	$(".checkbox input").each(function(){
		if($(this).attr('checked'))
			$(this).parent().addClass("checked");
		else
			$(this).parent().addClass("unchecked");
	});

	$(".checkbox").click(function(){

		if($(this).children("input").attr("checked")){
			// uncheck
			$(this).children("input").attr({checked: ""});
			$(this).removeClass("checked");
			$(this).addClass("unchecked");
		}else{
			// check
			$(this).children("input").attr({checked: "checked"});
			$(this).removeClass("unchecked");
			$(this).addClass("checked");
		}

		$(".property-filter-form form").submit();
	});
	$('.property-filter-form form label').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	/* Tabs */
	$(".tab_content").addClass('hidden'); //Hide all content
	$("ul.photos-plans-tabs li:first").addClass("active"); //Activate first tab
	$(".tab_content:first").removeClass('hidden'); //Show first tab content

	//On Click Event
	$("ul.photos-plans-tabs li").click(function() {

		$("ul.photos-plans-tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").addClass('hidden'); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).removeClass('hidden'); //Fade in the active ID content
		return false;
	});
	
	/* Create p if it does not exist */
	if (!$('.additional_info .par p').length) { 
			var addinfop = $('.additional_info .par').text();
    		$('.additional_info .par').empty().append('<p>' + addinfop + '</p>');
	  }
	  
	  // Table highlight
	  $('.flats_table td').live('mouseover', function(){
			var i = $(this).prevAll('td').length;
			$(this).parent().addClass('on')
			//$($cols[i]).addClass('on');

		}).live('mouseout', function(){
			var i = $(this).prevAll('td').length;
			$(this).parent().removeClass('on');
			//$($cols[i]).removeClass('on');
		});
});
