//	=============================================================== //
// 	fontsizer 
//	mail@breitnerundbreitner.de 2009
//	=============================================================== //

var currfontsize = 78; 	//set to default css-body-fontsize-value
var defaultSize = 78;	//set to default css-body-fontsize-value
var maxSize = 200;
var minSize = 60;

function applyFontSize(size) {
	$('body').css("font-size",size + "%");
}

function fontSizer(inc) {
	if (!document.getElementById) return;

	currfontsize += inc;
	if (currfontsize < minSize ) {
		currfontsize = minSize;
	}
	if (currfontsize > maxSize ) {
		currfontsize = maxSize;
	}
	applyFontSize(currfontsize);
	$.cookie('tab-fontsize', currfontsize, { path: '/' });
}

function fontSizerReset() {
	if (!document.getElementById) return;

	applyFontSize(defaultSize);
	$.cookie('tab-fontsize', null, { path: '/' });
}



$(function(){
	var cookieFontSize = $.cookie('tab-fontsize');
	if (cookieFontSize && cookieFontSize > 0) {
		currfontsize = parseInt(cookieFontSize);
		applyFontSize(currfontsize);
	}

 	$('.fontsize').css('display','block');
});


//	=============================================================== //
// 	styleswitcher
//	mail@breitnerundbreitner.de 2009
// 	inspired from http://www.alistapart.com/stories/alternate/
//	============================================================== //
function addPrintButton() {
	$('<a id="call-printer" href="#">' + (lang == 'de' ? 'Drucken' : 'Print') + '</a>')
		.click(function(){window.print();})
		.appendTo('#backfromprint');
}

function applyStyleSheet(title) {
	$('link[rel*=style][title]').each(function(i)
	{
		// Only disable style sheets for media screen
		if (this.media.indexOf('screen') != -1) {
			this.disabled = true;
			if (this.getAttribute('title') == title) this.disabled = false;
		}
	});

}

function setActiveStyleSheet(title) {
	applyStyleSheet(title);
	if (title == 'Printpreview') {
		if (lang == 'de') {
			$('<div id="backfromprint"><a href="javascript:backToScreenView()">Zurück zur Standardansicht</a></div>').prependTo('body');
		} else {
			$('<div id="backfromprint"><a href="javascript:backToScreenView()">Revert to default style</a></div>').prependTo('body');
		}

		$(function(){
			addPrintButton();
		});
	}
}


function getActiveStyleSheet() {
  return $('link[rel*=style][@title][not(disabled)]').title;
}; 

// return to user default view from print preview
function backToScreenView() {
	$('#backfromprint').remove(); 	
	setActiveStyleSheet('Standardlayout');
}; 

// to be called by onload
$(function () {
	$('.print').css('display','block');
}); 


//	=============================================================== //
// 	enable table-helper when javascript is available 
//	=============================================================== //
$(document).ready(function(){
	$('div.help').css('display','block');
});


//	=============================================================== //
// 	jquery colorbox
//	=============================================================== //
$(document).ready(function(){
	$(".lightbox").colorbox({
		/* maxWidth: "700px",  */
		scalePhotos: false,
		transition: 'none',
		close: "Schließen"
	});

	$(".lightbox.tab-gmap").colorbox({
		width: "760px",
		height: "570px", 
		scalePhotos: false,
		transition: 'none',
		close: 'Schließen', 
		iframe: true
	});

});

//	=============================================================== //
// 	jquery beauty tip
//	=============================================================== //
$(document).ready(function(){ 
	$('.quickinfo').bt({
		ajaxPath: ["$(this).attr('href')"], 
		ajaxCache: false, 
		trigger: 'click', 
		clickAnywhereToClose: true,  
		closeWhenOthersOpen: true,  
		shrinkToFit: true,
		positions: 'left, bottom', 
		width: 250,
		fill: '#F6F7F9'
	});
});





//	=============================================================== //
// 	tablesorter: cookie widget
//	=============================================================== //
$(function () {
	$.tablesorter.addWidget({
	      // give the widget a id
	      id: "sortPersist",
	      // format is called when the on init and when a sorting has finished
	      format: function(table) {

	          var COOKIE_NAME = 'TAB_tablesortcookie';
	          var cookie = $.cookie(COOKIE_NAME);
	          var options = {path: '/'};

	          var data = [];
	          var sortList = table.config.sortList;
	          var id = $(table).attr('id');
	                   // If the existing sortList isn't empty, set it into the cookie and get out
	          if (sortList.length > 0) {
	              if (typeof(cookie) == "undefined" || cookie == null) {
	                  data = {};
	              }
	              else {
	                  data = $.evalJSON(cookie);
	              }
		      data[id] = sortList;
	              $.cookie(COOKIE_NAME, $.toJSON(data), options);
	          }
	          // Otherwise...
	          else {
	              if (typeof(cookie) != "undefined" && cookie != null) {
	                  // Get the cookie data
	                  var data = $.evalJSON($.cookie(COOKIE_NAME));
	                  // If it exists
	                  if (typeof(data[id]) != "undefined" && data[id] != null) {
	                      // Get the list
	                      sortList = data[id];
	                      // And finally, if the list is NOT empty, trigger the sort with the new list
	                      if (sortList.length > 0) {
	                          //table.config.sortList = sortList;
	                            $(table).trigger("sorton", [sortList]);
	                      }
	                   }
	              }
	          }

	      }
	});
}); 

