var SlideSpeed = 400;
$(document).ready(function(){
	
	$('INPUT.auto-hint').each(function(i, el){
        if($(this).val() == ''){
            $(this).val($(this).attr('title'));
        }
        $(el).focus(function(){
            if ($(this).val() == $(this).attr('title')) {
                $(this).val('');
            }       
        });
        $(el).blur(function(){
            if ($(this).val() == '') {
                $(this).val($(this).attr('title'));
            }
        });
    });
	
	/* Gategories Titles */
	$('.nav-title').each(function(){
		var title = $(this).children('H3').html();
		if (title == 'News') $(this).addClass('black');
		if (title == 'City pages') $(this).addClass('city');
	});
	
	$('A[rel="external"]').attr('target', '_blank');
	
	if ($('.wpcf7').length > 0) {
		$('div.wpcf7-response-output').replaceWith('');
		$('.wpcf7').prepend('<div class="wpcf7-response-output wpcf7-display-none"></div>');
	};
	
	$('#menu-top-menu LI:first').addClass('no-border');
	$('.navigator .box .bottom UL').each(function(i){
		if ($(this).children('LI').children('UL.children').length == 0) 
			$(this).children('LI:last').children('A').addClass('last');
	});	
	$('#header ul.main-menu .sub-main-menu ul li').each(function(){
		if ($(this).children('A').attr('title') != '')	$(this).addClass($(this).children('A').attr('title'));
	});
	$('#header UL#menu-top-menu LI A').each(function(){
		if (($(this).attr('title') != '') && ($(this).attr('title') == 'thickbox')) {
			tb_init($(this));
			//$(this).addClass($(this).attr('title'));
		}
	});
	
	Cufon.replace('#content H2')('#content H3')('#header .call-us ')('#menu-top-menu li a', {hover: true})
				 ('#breadcrumbs .arrow-gradient')('#content A.orange-button')('#content BUTTON')('#content .navigation', {hover: true})
				 ('#contactusform H2');
	
	/* Styling menu */
	$('ul.header-top-menu li:first').addClass('no-border');
	$('ul.main-menu .sub-main-menu ul li:last-child').addClass('last');

	$('ul.main-menu>li').hover(function(){
		
		if ($(this).find('ul').hasClass('hover-sub-menu')) return false;
			
		$(this).find('ul').addClass('hover-sub-menu');
	
		$(this).find('.sub-main-menu').stop(false, true).slideDown(SlideSpeed);
		$('li.find-agent').hover(function(){
			$(this).children('a').addClass('hover-sub-menu-a');
			$(this).find('ul').slideDown(SlideSpeed);
		}, function(){
			$(this).children('a').removeClass('hover-sub-menu-a');
			$(this).find('ul').slideUp(SlideSpeed);
		});
	}, function(){
		$(this).find('.sub-main-menu').stop(true, true).slideUp('fast', function(){
			$(this).find('ul.hover-sub-menu').removeClass('hover-sub-menu');
		});
	});
	
	/* Slider */
	$('#slider').removeClass('loading');
	if ($('#slider').length) {
		$('#slider').before('<div id="nav">').cycle({ 
				fx:     'fade', 
				speed:  500, 
				timeout: 5000, 
				pager:  '#nav' 
			});
	}
	
	$('.last-news ul').cycle({
		fx:      'scrollDown',
		speed:    500,
		timeout:  5000
	});
	
	/* Styling selectbox */
	if ( $('select.style').length )$('select').selectbox({animationSpeed: 300});
	
	
	/* FAQ accardion */
	$('.faq-block dd').each(function(){
		$(this).show();
		$(this).height(parseInt($(this).height())+20);
		$(this).hide();
	});
	$('.faq-block dt').click(function(){
		$(this).next('dd').slideToggle('slow');
		return false;
	});
	
	/* Testimonials accardion */
	$('.agent-testimonials .more-content').each(function(){
		$(this).show();
		$(this).height(parseInt($(this).height())+5);
		$(this).hide();
	});
	$('.agent-testimonials .read-the-rest a').click(function(){
		var parent = $(this).parents('.description-col');
		var moreContent = $('.more-content:visible',parent);
		if ($(moreContent).length) {
			$(moreContent).slideUp();
			$(this).text($(this).attr('rel'));
		}else{
			var moreContent = $('.more-content',parent);
			$(moreContent).slideDown();
			$(this).attr('rel',$(this).text());
			$(this).text('Collapse');
		}
		return false;
	});
	
	$('#searchformhouse').attr('target','_blank');
	/*$('#searchformaction').change(function(){
		var new_action = $(this).val();
		$('#searchformhouse').attr('action',new_action);
	});*/
	$('#searchformhouse').submit(function(){
		var new_action = $('#searchformaction').val();
		$('#searchformhouse').attr('action',new_action);
		var keyword = $('input[name=keyword]',$(this));
		if ($(keyword).val() == $(keyword).attr('title')) $(keyword).val('');
		return true;
	});
	
	
	$('.sidebar.agent-box .widget-box:first').addClass('categories');
	$('.sidebar.agent-box .widget-box:last').addClass('no-bottom');
	$('.sidebar .widget-box:first .side-title').addClass('dark');
	$('.sidebar .categories LI:last').addClass('last');
	
	var select_count = $('.form-box').find('.jquery-selectbox').length;
	var select_i = 1;
	$('.form-box').find('.jquery-selectbox').each(function(){
		$(this).addClass('sleect-index-'+select_i).css('z-index', (select_count + 11) - select_i);
		$(this).parent().parent().css('z-index', (select_count + 11) - select_i);
		select_i++;
	});
	
	// Calculator Tabs
	$('#content .calculator .tabs LI A').click(function(){
		if ($(this).parent().hasClass('active-tab')) return false;
		$('#content .calculator .tabs LI.active-tab').removeClass('active-tab');
		$(this).parent().addClass('active-tab');
		$('#content .calculator .tabs-container .active-tab-cont').removeClass('active-tab-cont');
		$('#content .calculator .tabs-container '+$(this).attr('href')).addClass('active-tab-cont');
		return false;
	});
	
	// Image border 
	$('.image-area').each(function(){
		$(this).find('.image-size').css({width: $(this).find('IMG').width()+'px', height: $(this).find('IMG').height()+'px'});
		$(this).find('.imgage-border').show();
	});
	
	$('.navigator UL LI A').click(function(){
		if ($(this).parent().children('UL.children').length) {
			if ($(this).parent().hasClass('active')) {
				$(this).parent().removeClass('active').children('UL.children').slideUp(600);
			} else {
				$(this).parent().addClass('active').children('UL.children').slideDown(600);
			}
			return false;
		}
	});
		
});
