/*jshint asi: false, bitwise: true, boss: false, curly: true, debug: false, devel: false, eqeqeq: true, evil: false, forin: true, immed: true, laxbreak: false, newcap: true, noarg: true, noempty: true, nonew: true, nomen: true, onevar: true, plusplus: true, regexp: false, undef: true, sub: false, strict: true, white: false*/
/*global jQuery, console, baseUrl, window, document, initInput */

if (window.location.href.indexOf("www.") === -1) {
	baseUrl	=	baseUrl.replace("www.", "");
}

(function ($) {
	"use strict";

	$("html").addClass("js");
		
	//
	// salesRentals
	//
	if ($(".search")[0]) {
		(function ( ) {
			var $search	=	$(".search"),
			    $srSelects	=	$search.find("select[name=koophuur]"),
			    $sales	=	$search.find(".sales"),
			    $rentals	=	$search.find(".rentals");
			
			$(document).ready(function ( ) {
				if ($srSelects.filter(":first").val() === "koop") {
					$sales.show().find("select").each(initInput);
					$rentals.hide();
				} else {
					$sales.hide();
					$rentals.show().find("select").each(initInput);
				}
			});
			
			$srSelects.change(function ( ) {
				var value	=	$(this).val();
				
				$srSelects.find("option").each(function ( ) {
					var $this	=	$(this);
					console.log($this.val(), value, $this.val() === value);
					if ($this.val() === value) {
						$this.attr({"selected": "selected"});
					} else {
						$this.removeAttr("selected");
					}
				});
			
				if (value === "koop") {
					$sales.show().find("select").each(initInput);
					$rentals.hide();
				} else {
					$sales.hide();
					$rentals.show().find("select").each(initInput);
				}
			});
		}());
	}
}(jQuery));

