$(function () {
	//Header switch
	$('#header .switch a').click(function (e) {
		e.preventDefault();
		target = $(this).attr('href');
		var isNavigate = $(this).hasClass("navigate");

		$.cookie('pageType', $(target).attr('id'));

		if (isNavigate) {
			document.location.href = "/";
		} else {
			$(this).parent().siblings().removeClass('active');
			$(this).parent().addClass('active');
			$('.switch-content:visible').addClass('hide');
			$(target).removeClass('hide');

			if ($(target).attr('id') == 'homes') {
				$('.block.new-offer h2 a').attr('href', '/bestaand.aspx');
			} else {
				$('.block.new-offer h2 a').attr('href', '/bestaand-bog.aspx');
			}

			if ($('.home-image-block')) {
				$('.home-image-block:visible').addClass('hide');
				$('#image-' + $(target).attr('id') + '-block').removeClass('hide');
			}

			if ($('.block.info')) {
				$('.block.info:visible').addClass('hide');
				$('#home-tab-' + $(target).attr('id') + '-block').removeClass('hide');
			}
		}
	});


	//Watermark init
	$('.watermark input').each(function () {
		if ($(this).val() != '') {
			$(this).siblings('label').hide();
		}
	});
	//Watermark
	$('.watermark input').focus(function () {
		$(this).siblings('label').hide();
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).siblings('label').show();
		}
	});
	//Tabs
	$('.tab-list a').click(function (e) {
		e.preventDefault();
		var targetID = $(this).attr('href');
		$("#plcRoute").css('display', 'none');
		$(this).parent().siblings().removeClass('active');
		$(this).parent().addClass('active');
		$(this).parents('.tabs').children('.tab-content:visible').addClass('hide');
		$(targetID).removeClass('hide');
	});
	//Tab links
	$('.J_TabLink').click(function (e) {
		e.preventDefault();
		targetLink = $(this).attr('href');
		$('.tabs a').filter("[href=" + targetLink + "]:eq(0)").trigger('click');
	});
	//Dropdown-list
	$('#main .dropdown-list .dropdown-button').click(function () {
		$(this).parent().toggleClass('active');
	});
	$('#main .dropdown-list li a').click(function () {
		var city = $(this).text();
		var currentWrap = $(this).parents('.dropdown-list').find('.current-wrap');
		var currentTitleWrap = $(this).parents('.dropdown-list').find('.current');
		$(this).parent().siblings().removeClass('active');
		$(this).parent().addClass('active');
		currentWrap.text(city);
		currentTitleWrap.attr('title', city);
		$(this).parents('.dropdown-list').removeClass('active');
	});
	$('#main .dropdown-list .current').click(function () {
		if ($(this).children('.sort').hasClass('asc')) {
			$(this).children('.sort').removeClass('asc').addClass('desc');
		} else if ($(this).children('.sort').hasClass('desc')) {
			$(this).children('.sort').removeClass('desc').addClass('asc');
		}
	})
	$('#sidebar .dropdown-list').click(function () {
		$(this).toggleClass('active');
	});
	$('#sidebar .dropdown-list li a').click(function () {
		var city = $(this).text();
		var currentWrap = $(this).parents('ul').siblings('.current');
		$(this).parent().siblings().removeClass('active');
		$(this).parent().addClass('active');
		currentWrap.text(city);
	});

})
