$(document).ready(function(){
	$('.autoclear').autoclear();
	
	$('#search .replaceselect select').repSelectbox();
	
	$("aside nav a").hover(function () {
		$(this).stop().animate({ 
		        paddingLeft: '13px'
		}, 150 );
	}, function () {
		$(this).stop().animate({ 
		        paddingLeft: '10px'
		}, 150 );
	});
	
	$("nav.services a").hover(function () {
		$(this).stop().animate({ 
		        marginTop: '2px'
		}, 150 );
	}, function () {
		$(this).stop().animate({ 
		        marginTop: '5px'
		}, 150 );
	});
	
	if (!$('a.services_link').parent().hasClass('on')) {
		$('a.services_link').toggle(function () {
			$(this).next().slideDown();
			return false;
		}, function () {
			$(this).next().slideUp();
			return false;
		});
	}
	
	$(".floorplan a").fancybox();
	
	$("a[rel=galeria]").fancybox();
	
	$(".property_list_navi div").tabs(".property_list > .property_page",{ history: true });
	
	if ($(".property_list_navi").length) {
		var api = $(".property_list_navi div").data("tabs");
		api.onClick(function(index) {
			var destination = $('#body').offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 500 );
		});
	}
	
	$('.property_list_navi a.prev,.property_list_navi a.next').click(function(){
		if($(this).hasClass('next')){
			var hash = $(".property_list_navi div a.current").next().attr('href');
			$(this).attr('href',hash);
		}
		else {
			var hash = $(".property_list_navi div a.current").prev().attr('href');
			$(this).attr('href',hash);
		}
		
		var destination = $('#body').offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 500 );
		return true;
	});	
	
	$("a.form_submit").live("click", function(){
		$(this).closest('form').submit();
		return false;
	});	
	
	$('.locationbox p').toggle(function(){
		$('.select_box').css('overflow', 'hidden'); 
		$(this).parent().css('overflow', 'visible'); 
	}, function(){ 
		$(this).parent().css('overflow', 'hidden'); 
		var elm = $(this);
		$(this).html('');
		var text = $(this).parent().find('option:selected').each(function(){
			var text = $(this).text();
			elm.append(text+', ');
		});
		var text = elm.text();
		if (text.length > 40) {
			elm.html(text.substr(0,40));
			elm.append('...');
		}
	});
	
	$('.locationbox a').click(function(){
		$('.locationbox p').trigger('click');
		return false;	
	});
	
	$('.property .text').click(function(){
		window.location = $(this).parent().find('.image a').attr('href');
	});
	
	$(".design_refurb_top .scrollable").scrollable({speed:1000,circular: true, mousewheel: true}).navigator().autoscroll({
			interval: 4000
		});
	$("a[rel=galeria]").fancybox();
	$("a[rel=galeria_after]").fancybox();
	$("a[rel=galeria_before]").fancybox();
	
	
	$(".property_top .thumbs .scrollable").scrollable({ vertical: true, mousewheel: true });
	
	$(".property_top .thumbs .scrollable .items").tabs(".property_top .images .items div", {event:'mouseover'});
	
	$(".property_top .map a").fancybox({
		'padding'       : 0,
		'type'          : 'iframe',
		'width'         : 840,
		'height'        : 500
	});

	$('a.back').click(function(){
		history.go(-1);
		return false;
	});
	
	$(".property_top .thumbs .scrollable .items a").click(function(){
		return false;
	});
	
	$(".intereted_buttons").tabs(".interested_tabs .tab", {effect:'fade',current:'current'});

	//Focusok
	if($('#contact').length){
		$('#contact input').first().focus();
	}
	
	if($('.interested_aside').length){
		$('.interested_aside input').first().focus();
	}

	//Our Customer Says hover
	$(".our_customer_say").hover(function () {
		$(this).stop().animate({
			color: "#333333"
		}, 300 );
	}, function () {
		$(this).stop().animate({
			color:'#bfbfbf'
		},300);
	});
	
	if ($('.our_customer_container').length){
		$(".our_customer_container").scrollable({circular: true,speed:1400}).autoscroll({
			interval: 7000		
		});
		$('.our_customer_container').height($('.our_customer_container .items').height());
		var api = $(".our_customer_container").data('scrollable');
		$(".our_customer_say").click(function(){
			api.next();
		});
	}
});	

// ---------------- S E L E C T  B O X E S -----------------
(function (a) {
    a.fn.repSelectbox = function () {
        return this.each(function () {
            var d = a('<div class="select_box"><p></p><ul></ul></div>').insertAfter(a(this));
            var b = a('<input type="hidden" name="' + a(this).attr("name") + '">').insertAfter(a(d));
            a(this).children().each(function () {
                var e = a("<li>" + a(this).text() + "</li>").appendTo(a(d).children("ul"));
                a(e).data("val", a(this).val());
                a(e).click(function () {
                    a(this).parent("ul").prev().text(a(this).text());
                    a(b).attr("value", a(e).data("val"))
                })
            });
            a(d).children("p").html(a(d).find("li:first").text());
            if (a(this).find("option:selected").length) {
                var c = a(this).find("option:selected").index();
                a(d).find("li").eq(c).click()
            } else {
                a(d).find("li:first").click()
            }
            a(d).toggle(function (e) {
            	$('.select_box,.locationbox').css("overflow", "hidden");
                a(this).css("overflow", "visible");
                e.stopPropagation();
                a("body").click(function () {
                    a(d).css("overflow", "hidden");
                    a("body").unbind("click");
                    return false
                })
            }, function (e) {
                a(this).css("overflow", "hidden");
                e.stopPropagation();
                a("body").click(function () {
                    a(d).css("overflow", "hidden");
                    a("body").unbind("click");
                    return false
                });
                a("body").unbind("click");
            });
            a(this).remove()
        })
    }
})(jQuery);	

/**
 * Apply a default value to text fields quickly &amp; easily.
 *
 * The easiest way to use is $('your-selector').autoclear(). All the defaults
 * in the settings object are used. For more advanced cases, and complete
 * reference, @see http://www.mattlunn.me.uk/projects/autoclear
 *
 * @author Matt Lunn
 * @version 6
 * @param  Object / String
 * @return Object jQuery
 * @see http://www.mattlunn.me.uk/projects/autoclear
 * @see README
 */
(function(b){var e=jQuery.fn.val;var d=[].slice;jQuery.fn.autoclear=function(f){var g={defaultClass:"default",otherClass:"other",defaultValue:"",useDefaultOnReset:true,clearDefaultOnSubmit:true};if(arguments.length){switch(typeof f){case"string":g.defaultClass=f;break;case"object":g=jQuery.extend(g,f);break}}this.filter("input:text,textarea").each(function(){var i=b(this);var k=i.closest("form");var j=jQuery.trim(c(i));var h=i.attr("title");if(a(h)){if(j===""){h=g.defaultValue}else{h=j}}i.data("default.autoclear",h);k.bind("reset.autoclear",function(){var l;if(g.useDefaultOnReset){l=""}else{l=i.attr("defaultValue")}i.val(l)});if(g.useDefaultOnReset||a(jQuery.trim(i.attr("defaultValue")))){i.attr("defaultValue",h).val(j)}if(g.clearDefaultOnSubmit){k.bind("submit.autoclear",function(){i.trigger("focus.autoclear")})}}).bind({"focus.autoclear":function(){var h=b(this);if(h.val()===""){c(h,"").trigger("other.autoclear")}},"blur.autoclear":function(){var h=b(this);var i=jQuery.trim(h.val());if(i===""){h.trigger("default.autoclear")}else{h.trigger("other.autoclear")}},"default.autoclear":function(){var h=b(this).removeClass(g.otherClass).addClass(g.defaultClass);c(h,h.data("default.autoclear"))},"other.autoclear":function(){var h=b(this);h.removeClass(g.defaultClass).addClass(g.otherClass)}}).trigger("blur.autoclear");return this};jQuery.fn.val=function(){var f=e.apply(this,arguments);var g;if(typeof f==="string"){g=this.first().data("default.autoclear");if(g!==undefined&&f===g){f=""}}else{this.each(function(){var i=b(this);var h=i.data("default.autoclear");if(h!==undefined&&i.val()===""){i.trigger("default.autoclear")}else{i.trigger("other.autoclear")}})}return f};function a(f){return f===undefined||f===""}function c(f){return e.apply(f,d.call(arguments,1))}}(jQuery));

/*!
 * Color animation jQuery-plugin
 * http://www.bitstorm.org/jquery/color-animation/
 * Copyright 2011 Edwin Martin <edwin@bitstorm.org>
 * Released under the MIT and GPL licenses.
 */
(function(d){function i(){var b=d("script:first"),a=b.css("color"),c=false;if(/^rgba/.test(a))c=true;else try{c=a!=b.css("color","rgba(0, 0, 0, 0.5)").css("color");b.css("color",a)}catch(e){}return c}function g(b,a,c){var e="rgb"+(d.support.rgba?"a":"")+"("+parseInt(b[0]+c*(a[0]-b[0]),10)+","+parseInt(b[1]+c*(a[1]-b[1]),10)+","+parseInt(b[2]+c*(a[2]-b[2]),10);if(d.support.rgba)e+=","+(b&&a?parseFloat(b[3]+c*(a[3]-b[3])):1);e+=")";return e}function f(b){var a,c;if(a=/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/.exec(b))c=
[parseInt(a[1],16),parseInt(a[2],16),parseInt(a[3],16),1];else if(a=/#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/.exec(b))c=[parseInt(a[1],16)*17,parseInt(a[2],16)*17,parseInt(a[3],16)*17,1];else if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(b))c=[parseInt(a[1]),parseInt(a[2]),parseInt(a[3]),1];else if(a=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([01\.]*)\s*\)/.exec(b))c=[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10),parseFloat(a[4])];return c}
d.extend(true,d,{support:{rgba:i()}});var h=["color","backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","outlineColor"];d.each(h,function(b,a){d.fx.step[a]=function(c){if(!c.init){c.a=f(d(c.elem).css(a));c.end=f(c.end);c.init=true}c.elem.style[a]=g(c.a,c.end,c.pos)}});d.fx.step.borderColor=function(b){if(!b.init)b.end=f(b.end);var a=h.slice(2,6);d.each(a,function(c,e){b.init||(b[e]={a:f(d(b.elem).css(e))});b.elem.style[e]=g(b[e].a,b.end,b.pos)});b.init=true}})(jQuery);
