/*	JQUERY ACTION!
 *	(c) Copyright & Created 2008 by fiveandfriends.com
 *	more infos @ http://www.interaktionsdesigner.de
 */

//Standardschriftgröße
var bodyFontSize = 0.8;

//Maximale Grenzen
var maxSize = 1;
var minSize = 0.7;

//für einen bugfix vom internet explorer
var baseurl = 'http://www.aberdeen-immobilien.de/';

Hyphenator.run();

$(document).ready(function() {
  var IE6 = $.browser.msie && $.browser.version < 7 ? true : false;
  
  if(IE6) {
  	$('#center')
  	  .css('position', 'absolute')
  		.css('left', ( $(window).width() - $('#center').width() ) / 2+$(window).scrollLeft() + "px");
  }
  
  if($.browser.msie && $('.news-list-container').length > 0) {
  	$('.news-list-container a').each(function() {
  		href = $(this).attr('href');
  		$(this).attr('href', baseurl+href);
  	});
  }
  
  /* Print & Bookmarkmenü. Funktioniert nur mit JS und wird deshalb mit JS eingefügt */
  $('#footer .menu')
  	.css({width: '80%'})
  	.before('<ul class="action"><li><a href="#" class="print">Drucken</a></li><li><a href="#" class="bookmark">Bookmark</a></li></ul>');
  $('#footer .action a').live('click', function() {
  	type = $(this).attr('class');
  	switch(type) {
  		case 'print':
  			window.print();
  			break;
  		
  		case 'bookmark':
  			var url = window.location;
				var title = $('title').text();
				var comment = 'Aberdeen Immobilien '+title;

  			if (window.sidebar) {
			    // firefox
			    window.sidebar.addPanel(title,url,comment);
		    }
			  else if(window.opera && window.print) {
			    // opera
			    var elem = document.createElement('a');
			    elem.setAttribute('href',url);
			    elem.setAttribute('title',title);
			    elem.setAttribute('rel','sidebar');
			    elem.click();
		    }
			  else if(document.all) {
			    // ie
			    window.external.AddFavorite(url, comment);
		    }
  			break;
  	}
  	return false;
  });
  
  /* Erste Headline kennzeichnen */
  //$('#middle :header:first').addClass('first');
  

	/** FÜR DAS GLOSSAR */
	//Benötigte CSS Dateien nachladen
	$("head").prepend("<link rel='stylesheet' href='fileadmin/template/css/glossar-js.css'>");
	
	$("dl.glossar dt").click(function() {
		$("dl.glossar dt.aktiv").removeClass("aktiv").next().hide().find("h2").remove();
		$(this).addClass("aktiv").next().prepend("<h2>"+$(this).text()+"</h2>").fadeIn();
	});
	
	//$("dl.glossar dd:first").css("display", "block");
	
	/** GLOSSAR ENDE */	
	
	
	//Für das kleine Suchfeld
	$('#left .search .sword')
	.click(function() {
		standard = $(this).attr('standard');
		value = $(this).val();
		
		if(value == standard) {
			$(this).removeClass('standard');
			$(this).val('');
		}
	})
	.blur(function() {
		standard = $(this).attr('standard');
		value = $(this).val();
		
		if(value == '') {
			$(this).addClass('standard');
			$(this).val(standard);
		}
	});
	
	/* anklickbare boxen */
	$('#content .box.clickable').clickbox();
	//kleiner workaround damit auch der ie6 farbige hintergründe bla
	$('#content .box.background.clickable').hover(function() {
		$(this).addClass('background-clickable-hover');
	}, function() {
		$(this).removeClass('background-clickable-hover');	
	});

	/* Tabellenzeilen Klickbar machen. Killer! */
	$("#content table:not(.styleme) tr").clickbox();
	
	/* Cooler Menüeffekt */
	$(".navigation a").click(function(event) {
		$(this).addClass('aktiv').parent().siblings().find('a').removeClass('aktiv');
	});
		
	/* Downloadlist */
	$("#content #middle ul.ddl_file_list li").clickbox();
	
	/* Suchergebnisse */
	$("#content #middle .tx-indexedsearch-res .result").clickbox();
	
	/* Newseinträge Übersicht */
	//$("#content #middle .news-list-container .item").clickbox();
	
	/* Tabellen im Inhaltsbereich */
	$("#content #middle .contenttable tbody tr").hover(function() {
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	});
	
	/*
	 *	Grafikaustausch für die Wertentwicklungsgrafiken
	 */
	$("#content #middle .wertentwicklung .menu li a").click(function() {
		var fonds = $(this).parent().parent().parent();
		var imgUrl = "fileadmin/wertentwicklung/"+$(fonds).attr("rel")+"/wertentwicklung-"+$(this).attr("rel")+".gif";
		
		//aktivklassen löschen / setzen
		$(".menu li a", fonds).removeClass("aktiv");
		$(this).addClass("aktiv");
		
		//neue grafik laden
		var bild = $(".grafik img", fonds);
		$(bild).fadeOut(function() {
			$(bild).attr("src", imgUrl).fadeIn();
		});
		
		$(this).blur();
		return false;
	});
	
	
	/*
	 *	Gleiche Höhe für Boxen in einer Reihe
	 */
	var width = 0;
	var height = 0;
	var one_row = new Array();
	var withSidebar = $('#middle').is('.withSidebar');
	
	if(withSidebar)
		var _100 = 75;
	else
		var _100 = 100;
	
	$('#middle .box').each(function() {
		if($(this).is('.einviertel'))
			width = width+25;
		else if($(this).is('.zweiviertel'))
			width = width+50;			
		else if($(this).is('.dreiviertel'))
			width = width+75;
		else
			width = -1;
		
		if(width > 0) {		
			if(height < $(this).height())
				height = $(this).height();
			one_row.push($(this));
			
			if(width == _100 || width == (_100-1)) {
				//bilder bringen unkalkulierbaren abstand
				/*has_img = false;
				$.each(one_row, function() {
					if($('img', this).length > 0) {
						has_img = true;
						return false;
					}
				});
				
				if(has_img)
					height = height;*/
				
				height = height - 15;
				
				$.each(one_row, function() {
					$('.padding', this).height(height);
				});
				
				one_row.pop().addClass('box-last');
				width = 0;
				height = 0;
				one_row = new Array();
			}
		}
	});
	
	
	$('#center').removeClass('noscript')/*.hide();
	window.setTimeout(function() { $('#center').slideDown() }, 500)*/;
});


function setSizeCookie(fontSize) {
	//alert("Neuer Wert: "+fontSize);
	$.cookie('degi-bodyFontSize', fontSize, { expires: 7 });
}

function getSizeCookie() {
	return $.cookie("degi-bodyFontSize");
}