jQuery(document).ready(function($) {
	
	var gallery = {
		pause: window.homesliderspeed,
		duration: 500,
		index: 0,
		times: null,
		change: function() {
			$('#mygallery .panel').css({'z-index': '10'}).fadeOut(gallery.duration);
			var current = $('#mygallery .panel').eq(gallery.index);
			current.css({'z-index': '5'}).show().fadeIn(gallery.duration);
			var h1_text = current.find('h1').text();
			var p_text = current.find('p').text();
			
			$('#mygallery-text').animate({'opacity': '0'}, gallery.duration/2, function() {
				$(this).find('h1').text(h1_text);
				$(this).find('p').text(p_text);
				$(this).animate({'opacity': '1'}, gallery.duration/2);
			});
		},
		prev: function() {
			clearTimeout(gallery.timer);
			if ( gallery.index <= 0 ) {
				gallery.index = $('#mygallery .panel').length-1
			} else {
				gallery.index -= 1;
			}
			gallery.change();
			gallery.timer = setTimeout(gallery.next, gallery.pause);
		},
		next: function() {
			clearTimeout(gallery.timer);
			if ( gallery.index >= $('#mygallery .panel').length-1 ) {
				gallery.index = 0;
			} else {
				gallery.index += 1;
			}
			gallery.change();
			gallery.timer = setTimeout(gallery.next, gallery.pause);
		}
	};
	
	$('#mygallery-nav .prev-btn').click(function() {
		gallery.prev();
		return false;
	});
	
	$('#mygallery-nav .next-btn').click(function() {
		gallery.next();
		return false;
	});
	
	if ( $('#mygallery').length &&  $('#mygallery img').length > 1 ) {
		$(window).load(function() {
			gallery.timer = setTimeout(gallery.next, gallery.pause);
		});
	} else {
		$('#mygallery-nav').remove();
	}


	$(".single-property .property-slider .slider-carousel ul").jcarousel({
		scroll:1,
		auto:4,
		wrap:"both",
        start: 1
	});

	$('.search-left form').jqTransform();

	$('.page-numbers a, .page-numbers span').wrap('<div class="number-wrap"></div>');

	$('#single-property-contact-form input, #properties-search-form input, #search-addendum input').focus(function() {
		if ($(this).val()==$(this).attr('title')) {
			$(this).val('');
		}
	}).blur(function() {
		if ($(this).val()=="") {
			$(this).val($(this).attr('title'));
		}
	});

	$('#menu-main-menu li:last').addClass('last');
	$('#menu-main-menu li').each(function() {
		var width=$(this).width();
		$(this).css({
			'display' : 'block',
			'width' : width,
		});
	});

	$(window).load(function() {
		var maxHeightServiceBox=0;
		$('.servicebox').each(function() {
			if ($(this).outerHeight()>maxHeightServiceBox) {
				maxHeightServiceBox=$(this).outerHeight();
			}
		});
		$('.servicebox').each(function() {
			$(this).height(maxHeightServiceBox-parseFloat($(this).css('padding-top'))-parseFloat($(this).css('padding-bottom')));
		});
	});
	
});

