
/**
 *
 * @author Martin Modlich [http://www.marseo.de]
 * @version 1.0
 */
(function($) {
	$.fn.sliderClose = function(settings) {
		var settings = $.extend({
			object:	null, // Object ID
			preClose: null,
			cssDefault: null,
			cssAktiv: null,
			speedUp: 500,
			speedDown: 500,
			lastOpen:null
		}, settings);
		$(settings.preClose).slideUp(settings.speedUp, function() {
			$(this).sliderPointer(settings);
		});
	}
	$.fn.sliderOpen = function(settings) {
		var settings = $.extend({
			object:	null, // Object ID
			preClose: null,
			cssDefault: null,
			cssAktiv: null,
			speedUp: 500,
			speedDown: 500
		}, settings);
		if(settings.preClose) {
			$(settings.preClose).sliderClose(settings);
		}
		$(this).slideDown(settings.speedDown, function() {
			$(this).sliderPointer(settings);
		});
	}
	$.fn.sliderPointer = function(settings) {
		var settings = $.extend({
			object:	null, // Object ID
			preClose: null,
			cssDefault: null,
			cssAktiv: null,
			speedUp: 500,
			speedDown: 500
		}, settings);
		return $('.ref-top').each(
			function(intIndex){
				$('#' + $(this).attr('id') + 'bottom').is(':visible')
					? $('#' + $(this).attr('id') + 'pointer')
						.removeClass(settings.cssDefault)
						.addClass(settings.cssAktiv)
					: $('#' + $(this).attr('id') + 'pointer')
						.removeClass(settings.cssAktiv)
						.addClass(settings.cssDefault);
			}
		);
	}
})(jQuery);


function check_ajax_true() {
	return !userID
			&& m__ajax
			&& !($.browser.msie && $.browser.version.substr(0,1)<7)
				? true
				: false;
}

function ajax(href) {
	if(!check_ajax_true()) return true;

	var ajaxcontent = '#ajax';
	var content = '#content';

	aktuelle_url = href;
	$('#indikator').addClass('content-load');
	$(content).fadeTo(200, 0.1, function () {
		$.ajax({
			dataType: 'html',
			async: false,
			url:aktuelle_url,
			data: '' ,
			beforeSend: function(){

			},
			success: function(data){
				$(ajaxcontent).html(data);
			},
			complete: function() {
				$(content).fadeTo(350, 1, function () {
					if(jQuery.browser.msie) {
   						this.style.removeAttribute('filter');
					}
					$(document).ready(function() {
						seite_geladen();
						$('#indikator').removeClass('content-load');
					});
				});
			}
		});
	});
	return false;
}


function seite_geladen() {

	// if ($.browser.msie && $.browser.version.substr(0,1)<7) {
	//alert($.browser.version.substr(0,1));
	jQuery('a.nachricht').mEmail({'pre':'name','post':'rel'});

	//$.historyInit(pageload, '/kunden/immobilienshop-rostock.de/');

    $(".ajax").click(function () {
    	if(this.href) {
			if(!check_ajax_true()) {
				return true;
			}
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a new page.
			// pageload is called at once.
			// hash don't contain "#", "?"
			$.historyLoad(hash);
			return false;
    	}
	});

	$('.ref-top').click(function() {

		if($(this).attr('id')) {
			var config = {
				'object'	: '#' + $(this).attr('id'),
				'preClose'	: '.ref-bottom',
				'cssDefault': 'ref-pointer',
				'cssAktiv'	: 'ref-pointer-aktiv',
				'speedDown'	: 250,
				'speedUp'	: 650
			}
			$('#' + $(this).attr('id') + 'bottom').is(':visible')
				? $('#' + $(this).attr('id') + 'bottom').sliderClose(config)
				: $('#' + $(this).attr('id') + 'bottom').sliderOpen(config);
		}

	});
	$("a.gruppe").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Bild ' +  (currentIndex + 1) + '/' + currentArray.length + ' ' + (title ? '' + title : '') + '</span>';
		}
	});


	if($('#monat').attr("checked")) {
		$('.immo_beschreibung').slideDown();
	}else{
		$('.immo_beschreibung').slideUp();
	}
	$('#monat').click(function() {
		if($(this).attr("checked")) {
			$('.immo_beschreibung').slideDown();
		}else{
			$('.immo_beschreibung').slideUp();
		}
	});

	// tel
	$('input[name=tel]').keyup(function(){
		$('.fade').slideDown(750, function() {
			// Animation complete
		});
	});

	$('#fade-2').click(function(){
		$('.fade-2').slideToggle(750, function() {
			$(this).is(':visible')
				? $('#fade-2')
					.removeClass('a-pointer')
					.addClass('a-pointer-aktiv')
				: $('#fade-2')
					.removeClass('a-pointer-aktiv')
					.addClass('a-pointer');
		});
	});



	var textareaText = 'Sehr geehrte Damen und Herren,\n\n\n\nMit freundlichen Gr' + String.fromCharCode(252, 223) + 'en,\n\n';
	if(jQuery('textarea[name=kontakt]').val() == '') {
		jQuery('textarea[name=kontakt]').val(textareaText);
	}
	var row_default = 9;
	var row_reserve = 2;
	jQuery('textarea[name=kontakt]').keyup(function () {
		var arr_row = this.value.split('\n');
		this.rows = (arr_row.length >= (row_default - row_reserve))
			? (arr_row.length + row_reserve)
			: row_default;


	});
}


// PageLoad function
// This function is called when:
// 1. after calling $.historyInit();
// 2. after calling $.historyLoad();
// 3. after pushing "Go Back" button of a browser
function pageload(hash) {
	// alert("pageload: " + hash);
	// hash doesn't contain the first # character.
	if(!hash) {
		return false;
	}

	return ajax(hash);
}

$(document).ready(function() {
	//$.historyInit(pageload, 'http://localhost/kunden/immobilienshop-rostock.de/');
	$.historyInit(pageload, 'immobilienshop-rostock.de/');
	//$.historyInit(pageload, '/kunden/immobilienshop-rostock.de/');

	seite_geladen();

	if (!($.browser.msie && $.browser.version.substr(0,1)<7) ) {
		$('#header').flash({
			src: ROOT + 'inc/swf/banner.swf?v2',
		    width: 967,
		    height: 158,
		    wmode: 'transparent'
		});
	}

});