/**
 * @package svn.de
 * @subpackage javascript
 * @file jquery.svn.js
 * contains all general javascript for svn.de
 * @author Arnold Knaub 
 */
/* GLOBALS */
// browser detection
var b_isBadBrowser = typeof(window.XMLHttpRequest) == 'undefined';
var b_isIEx        = (b_isIE6 == true || b_isIE7 == true || b_isIE8== true) ? true : false;

// general paths
var s_php_path = "../resources/_php";
// vars
var categories=[];
var stop=false;
var fp=null;

// for IE6 png-fix
var blank = new Image();
blank.src = "/resources/_img/system/transparent.gif";

// fotostrecke detect screen and browser window dimensions:
var i_screenWidth  = screen.width;
var i_screenHeight = screen.height;
var i_winOutWidth  = window.outerWidth;
var i_winInnWidth  = window.innerWidth;
var i_winOutHeight = window.outerHeight;
var i_winInnHeight = window.innerHeight;

//detect screen and browser window dimensions for IE6/7:
if(typeof(i_winInnWidth)  == 'undefined') {
	i_winInnWidth = document.documentElement.clientWidth;
}
if(typeof(i_winInnWidth)  == 'undefined') {
	i_winInnWidth = document.body.clientWidth;
}
if(typeof(i_winInnHeight) == 'undefined') {
	i_winInnHeight = document.documentElement.clientHeight;
}
if(typeof(i_winInnHeight) == 'undefined') {
	i_winInnHeight = document.body.clientHeight;
}

// kontaktformular
var a_contactFormValues   = new Array();
// bilderstrecke
var images    		  = new Array();
var fsElement = '.fotostrecke';
// searchengine
var newLabel              = '';


/* GLOBAL FUNCTIONS */
// class searchEngine
var searchEngine = function(s_target) {
	var s_mySearchEngine ='/resources/_php/searchengine.php';
	var s_myTarget       = '';
	if(typeof(s_target) != 'undefined') {
		s_myTarget       	 = s_target;
	}
	var s_mySuchBegriff  = '';
	var i_myOff          = 0;
	var i_myAnz          = 5;
	var file_filter ="";
	var url_filter="";
	
	this.setFileFilter=function(file_name){
	   		if(typeof(file_name) != 'undefined') {
			file_filter = file_name;
		}
	}
	
	var setSuchBegriff = function(s_suchBegriff) {
		if(typeof(s_suchBegriff) != 'undefined') {
			s_mySuchBegriff = s_suchBegriff;
		}
	}
	this.setSuchBegriff = setSuchBegriff;
	
	var getSearchData = function(i_offset, s_suchbegriff){
		if(typeof(i_offset) != 'undefined') {
			i_myOff = i_offset;
		}
		setSuchBegriff(s_suchbegriff);
		
		$('#searchresults').css("display","block");
		
		$(s_myTarget).html('<div id="search_wait"><img style="margin-bottom: 14px; margin-left: 150px;" src="/resources/_img/site/search_wait.gif"/></div>');
		$.post(s_mySearchEngine, {suchbegriff: s_mySuchBegriff, off: i_myOff, anz: i_myAnz,file_filter: file_filter,url_filter:url_filter}, function(data){$(s_myTarget).html(data);});
	}
	this.getSearchData = getSearchData;
	
	this.setSearchEngine=function(engine_path){
	    s_mySearchEngine=engine_path;
	}
		
	
	this.getSearchEngine=function(){
	  // console.log( s_mySearchEngine);
	}
	
	this.setUrlFilter=function(data){
	if(data && data!='undefined'){
	url_filter=data;
	}
	else{
	url_filter="";
	}
	}
		
}
var se = new searchEngine('#searchresults');

// feedparser
var feedparser = function(s_feedurl, s_target){
	var s_myParser  = '/resources/_php/feedparser.php';
	var s_myFeedurl = s_feedurl;
	var s_myTarget  = s_target;
	var s_mySuchstr = '';
	var i_myIndex   = 0;
	var i_myMax     = 5;
	
	var loadData    = function(i_index, s_suchstring){
		if(typeof(i_index) != 'undefined') {
			i_myIndex   = i_index;
		}
		if(typeof(s_suchstring) != 'undefined') {
			s_mySuchstr = s_suchstring;
		}
		$.post(s_myParser, {myurl:s_myFeedurl,pre:i_myIndex,max:i_myMax,such:s_mySuchstr}, function(data){$(s_myTarget).html(data);});
	}
	this.loadData   = loadData;
	
	var setMax      = function(i_max) {
		if(typeof(i_max) != 'undefined') {
			i_myMax   = i_max;
		}
	}
	this.setMax = setMax;
	
	var setSuchstring = function(s_suchstring) {
		if(typeof(s_suchstring) != 'undefined') {
			s_mySuchstr = s_suchstring;
		}
	}
	this.setSuchstring = setSuchstring;
}

/**
 * class fotostrecke
 * @version 1.1 vom 12.05.2010
 * @author Juergen Arne Klein <juergen-arne.klein@unitb-consulting.de>
 */
var fotostrecke = function(fsElement) {
	/**
	 * members:
	 */
	var myElement   = fsElement;
	var e_stage     = null;
	var a_bigImgs   = new Array();
	var a_imgMap    = new Array();
	var i_ind       = 0;
	var i_aID       = 0;
	var s_actSrc    = '';
	
	/* function: */
	/** 
	 * @method init void
	 * @author Juergen Arne Klein <juergen-arne.klein@unitb-consulting.de>
	 * @access public
	 * @return void
	 */
	var init = function() {
		$(myElement).each(function() {
			f_setMainStage($(this), 0);
		});
	}
	this.init = init; // make init public
	
	/**
	 * @method f_loadImg
	 * @author Juergen Arne Klein <juergen-arne.klein@unitb-consulting.de>
	 * @access private
	 * @param DOM-Element target
	 * @param DOM-Element e_stage
	 * @return void 
	 */
	var f_loadImg = function(target, e_stage) {
		if(!b_isBadBrowser){$(target).blur();}
		var k = $(target).attr('rel');		
		f_setMainStage(e_stage, k);
	}
	
	var f_nextImg = function(e_stage) {
		if(!b_isBadBrowser){$(e_stage).find('div.next_ico a').blur();}
		var i_index = $(e_stage).find('.navigation > ul.index > li.active:first a').attr('rel');
		f_setMainStage(e_stage, parseInt(i_index) + 1);
	}

	var f_prevImg = function(e_stage) {
		if(!b_isBadBrowser){$(e_stage).find('div.prev_ico a').blur();}
		var i_index = $(e_stage).find('.navigation > ul.index > li.active:last a').attr('rel');
		f_setMainStage(e_stage, parseInt(i_index) - 1);
	}

	var f_setMainStage = function(e_stage, i_index) {
		var i_sID        = $(e_stage).attr('id');
		a_bigImgs[i_sID] = new Array();
		for(var y = 0;y < images[i_sID].length; y ++) {
			if(typeof(images[i_sID][y]['src_big']) != 'undefined' && images[i_sID][y]['src_big'] != '' && !images[i_sID][y]['src_big'].match(/\?\?\?/)) {
				a_bigImgs[i_sID].push(y);
			}
		}

		if(typeof(i_index) == 'undefined') {
			i_index = 0;
		}
		// hauptbild setzen
		$(e_stage).find('.main_img > img + img').attr('src', images[i_sID][i_index]['src_sml']);
		$(e_stage).find('.description').html(images[i_sID][i_index]['sub_sml']);

		// seitliche navigation aufbauen
		$(e_stage).find('div.prev_ico a').unbind('click').one('click',function() {f_prevImg(e_stage);}).hide();
		$(e_stage).find('div.next_ico a').unbind('click').one('click',function() {f_nextImg(e_stage);}).hide();

		// untere navigation aufbauen
		if(1 < images[i_sID].length) {
			$(e_stage).find('.navigation').html('<ul class="index"></ul>');
			for(var i = 0; i < images[i_sID].length; i++) {
				$(e_stage).find('.navigation > ul.index').append('<li><a title="'+images[i_sID][i]['tit_sml']+'" href="javascript:void(0);" rel="'+i+'">&nbsp;</a></li>');
			}
			var i_child = parseInt(i_index) + 1;
			$(e_stage).find('.navigation > ul.index > li:nth-child('+i_child+')').addClass('active');
			$(e_stage).find('.navigation > ul.index > li > a').each(function() {
				$(this).click(function(ev) {f_loadImg(ev.target, e_stage);});
			});
		}
		
		if(i_index > 0) {
			$(e_stage).find('div.prev_ico a').show();
		}
		if(i_index < (images[i_sID].length - 1)) {
			$(e_stage).find('div.next_ico a').show();
		} 

		// klick auf bild oeffnet overlay
		if(typeof(images[i_sID][i_index]['src_big']) != "undefined" && images[i_sID][i_index]['src_big'] != "" && images [i_sID][i_index]['src_big'].search('de.dsgv.template') == -1) {
			$(e_stage).find('.stage .main_img img:first').css({cursor:'pointer'}).click(function() {
				f_showOverlay(e_stage);
			});
		} else {
			$(e_stage).find('.stage .main_img img:first').css({cursor:'default'}).unbind('click');
		}
	}

	var f_setOverlay = function(e_stage, i_index) {
		var i_sID     = $(e_stage).attr('id');
		var i_myIndex = 0;
		var i_child   = 0;
		var i_myChild = 1;
		if(typeof(i_index) == 'undefined'){
			var i_index = $(e_stage).find('.navigation > ul.index > li.active:first a').attr('rel');
		}

		if(typeof(i_index) == 'undefined') {
			i_index = 0;
		}
		for(var b = 0; b < a_bigImgs[i_sID].length; b ++) {
			if(a_bigImgs[i_sID][b] == i_index){
				i_myIndex = i_index;
				i_myChild = parseInt(b)+1;
				
			}
		}

		$('#imgBox .lbStage .lbImg').html('<img src="'+images[i_sID][i_myIndex]['src_big']+'" alt="'+images[i_sID][i_myIndex]['alt_big']+'" title="'+images[i_sID][i_myIndex]['tit_big']+'" />');
		$('#imgBox .lbStage .subtitle').html(images[i_sID][i_myIndex]['sub_big']);

		// untere navigation aufbauen
		$('.lbStage > .navigation').html($('#'+i_sID+ ' > .navigation').html());
		$('.lbStage > .navigation > ul.index > li > a').unbind('click');
		for(var c = 0; c < images[i_sID].length; c ++) {
			if(typeof(images[i_sID][c]['src_big']) == 'undefined' || images[i_sID][c]['src_big'] == '') {
				i_child = parseInt(c)+1;
				$('.lbStage > .navigation > ul.index > li:nth-child('+i_child+')').hide();
			}
		}
		$('.lbStage > .navigation > ul.index > li.active').removeClass('active');
		i_child = parseInt(i_index) + 1;
		$('.lbStage > .navigation > ul.index > li:nth-child('+i_child+')').addClass('active');
		
		$('#imgBox .lbStage .navigation > ul.index > li:visible > a').each(function() {
			$(this).click(function() {f_setOverlay(e_stage, $(this).attr('rel'));});
		});

		// seitliche navigation aufbauen
		$('#imgBox div.bod_right a').unbind('click').hide();
		$('#imgBox div.bod_left a').unbind('click').hide();
		
		if(i_index > 0) {
			var i_prev = parseInt(i_index) - 1;
			if(!b_isBadBrowser){$('#imgBox div.bod_left a').blur();}
			for(var d = i_prev; d >= 0; d --) {
				if(typeof(images[i_sID][d]['src_big']) != 'undefined' && images[i_sID][d]['src_big'] != '') {
					$('#imgBox div.bod_left a').one('click',function() {f_setOverlay(e_stage, d);}).show();
					break;
				}
			}
		}

		if(i_index < (images[i_sID].length - 1)) {
			var i_next = parseInt(i_index) + 1;
			if(!b_isBadBrowser){$('#imgBox div.bod_right a').blur();}
			for(var e = i_next; e < images[i_sID].length;e ++) {
				if(typeof(images[i_sID][e]['src_big']) != 'undefined' && images[i_sID][e]['src_big'] != '') {
					$('#imgBox div.bod_right a').one('click',function() {f_setOverlay(e_stage, e);}).show();
					break;
				}
			}
		} 
	}

	var f_showOverlay = function(e_stage) {
		f_setOverlay(e_stage);
		$('#overBox').show().one('click', function() {f_hideOverlay(e_stage);});
		$('a.closebtn').one('click', function() {f_hideOverlay(e_stage);});
		$('#imgBox').show();
		$().unbind('keyup');
		$('').keyup(function (e) {
			switch(e.keyCode) {
				case 27:
					$('#overBox').click();
					break;
			}
		});
		f_center();
	}
	
	var f_center = function() {
		i_screenWidth  = screen.width;
		i_screenHeight = screen.height;
		i_winOutWidth  = window.outerWidth;
		i_winInnWidth  = window.innerWidth;
		i_winOutHeight = window.outerHeight;
		i_winInnHeight = window.innerHeight;

		//detect screen and browser window dimensions for IE6/7:
		if(typeof(i_winInnWidth) == 'undefined') {
			i_winInnWidth = document.documentElement.clientWidth;
		}
		if(typeof(i_winInnWidth) == 'undefined') {
			i_winInnWidth = document.body.clientWidth;
		}
		if(typeof(i_winInnHeight) == 'undefined') {
			i_winInnHeight = document.documentElement.clientHeight;
		}
		if(typeof(i_winInnHeight) == 'undefined') {
			i_winInnHeight = document.body.clientHeight;
		}

		var i_top  = (i_winInnHeight - $('#imgBox').height()) / 2;
		var i_left = (i_winInnWidth - $('#imgBox').width()) / 2;
		
		$('#imgBox').css({top: i_top+'px', left: i_left+'px'});
	}
	
	var f_hideOverlay = function(e_stage) {
		$().unbind('keyup');
		var i_index = $('#imgBox .lbStage .navigation > ul.index > li.active:first a').attr('rel');
		f_setMainStage(e_stage, i_index);
		$('#imgBox div.lbImg').html('');
		$('#imgBox, #overBox').hide();
	}
}
var fs = new fotostrecke(fsElement);


/* LISTENERS */
$().ready(function() {
	/* SCROLLBALKEN */
//	$('#tabs_content.scroll_special > div').jScrollPane({showArrows:false, scrollbarWidth: 13, scrollbarMargin: 15})
//	$('#tabs_content.scroll_special > .jScrollPaneContainer').hide();
//	$('#tabs_content.scroll_special > .jScrollPaneContainer:first').show();

	/* FOTOSTRECKE */
	fs.init();
	
	/* SEARCHENGINE */
	// label lÃƒÂ¶schen
	$('#suchbegriff_o.ini, #suchbegriff.ini, #dlsuchbegriff.ini').each(function() {
		$(this).one('focus', function() {
			$(this).attr('value', '').removeClass('ini');
		});
	});

	// label einfÃƒÂ¼gen
	$('#suchbegriff_o, #suchbegriff, #dlsuchbegriff').each(function() {
		if($(this).attr('value') == '') {
			if(typeof($(this).attr('title')) == 'undefined' || $(this).attr('title') == '') {
				newLabel = lang == 'en' ? 'Search ' + $(this.parentNode.parentNode.parentNode).find('h1:first').text() : $(this.parentNode.parentNode.parentNode).find('h1:first').text() + ' durchsuchen';
			} else {
				newLabel = $(this).attr('title');
			}
			$(this).attr('value', newLabel);
		}
		$(this).blur(function() {
			if($(this).attr('value') == '') {
				if(typeof($(this).attr('title')) == 'undefined' || $(this).attr('title') == '') {
					newLabel = lang == 'en' ? 'Search ' + $(this.parentNode.parentNode.parentNode).find('h1:first').text() : $(this.parentNode.parentNode.parentNode).find('h1:first').text() + ' durchsuchen';
				} else {
					newLabel = $(this).attr('title');
				}
				$(this).attr('value', newLabel).addClass('ini').one('focus', function() {
					$(this).attr('value', '').removeClass('ini');
				});
			}
		});
	});

	$('#pressform, #appointmentsform, #newsform, #suchform, #dlsform').submit(function() {
		return false;
	});
	$('#suchform_o').submit(function() {
		history('false');
	        $("body").attr("onunload","history('false');"); 
		if($('#suchbegriff_o').hasClass('ini') || $('#suchbegriff_o').attr('value') == '') {
			return false;
		}
	});

	if(typeof($('#suchbegriff').attr('value')) != 'undefined' && $('#suchbegriff').attr('value').match(/[^\ ]+/) && !$('#suchbegriff').hasClass('ini') && typeof(se.setSuchBegriff) != 'undefined'){
	        $('#spdf').attr('checked')?se.setFileFilter("pdf"):$('#sart').attr('checked')?se.setFileFilter("html"):se.setFileFilter("none"); 
		se.setSuchBegriff($('#suchbegriff').attr('value'));
	}

	$('#searchsubmit').click(function() {
		if(!b_isBadBrowser) {$(this).blur();}
		if($('#suchbegriff').attr('value').match(/[^\ ]+/) && !$('#suchbegriff').hasClass('ini')){
			se.setSuchBegriff($('#suchbegriff').attr('value'));
			$('#spdf').attr('checked')?se.setFileFilter("pdf"):$('#sart').attr('checked')?se.setFileFilter("html"):se.setFileFilter("none");
			se.getSearchData(0);
			return false;
		}
	});
	
	
	$('#suchbegriff').keypress(function(e) {
           if(!b_isBadBrowser) {$(this).blur();}
		    var characterCode = 0;

                  if (e && e.which) {
                      characterCode = e.which;
                  } else {
                    characterCode = e.keyCode;
                          }

                  if (characterCode == 13) {
		      if($('#suchbegriff').attr('value').match(/[^\ ]+/) && !$('#suchbegriff').hasClass('ini')){
			se.setSuchBegriff($('#suchbegriff').attr('value'));
			$('#spdf').attr('checked')?se.setFileFilter("pdf"):$('#sart').attr('checked')?se.setFileFilter("html"):se.setFileFilter("none");
			$('#url_filter').attr('value')?se.setUrlFilter($('#url_filter').attr('value')):se.setUrlFilter("");
			se.getSearchData(0);
			return false;
		       }
                   }
               $(this).focus();
	  });	
	
	
	
	
	
	/* FEEDPARSER */	
	var dlp = new feedparser('/de/downloads.rss', '#dlresults_list');
	$('#dlsearchsubmit').click(function() {
		if(!b_isBadBrowser) {$(this).blur();}
		if($('#dlsuchbegriff').attr('value').match(/[^\ ]+/) && !$('#dlsuchbegriff').hasClass('ini')) {
			dlp.loadData(0,$('#dlsuchbegriff').attr('value'));
		}
	});
	
	$('#cont_main.press a#searchsubmit, #cont_main.appointments a#searchsubmit, #cont_main.newslist a#searchsubmit').click(function() {
		if(!b_isBadBrowser){$(this).blur();}
		if(!$('#suchbegriff').hasClass('ini') && $('#suchbegriff').attr('value').match(/[^\ ]+/)){
			fp.loadData(0,$('#suchbegriff').attr('value'));
		}
	});
	
	$('#searchsubmit_feed').click(function() {
	   	if(!b_isBadBrowser){$(this).blur();}
		if(!$('#suchbegriff').hasClass('ini') && $('#suchbegriff').attr('value').match(/[^\ ]+/)){
		    if(!fp || fp=='undefined'){
		    fp=new feedparser('/sparkassengeschichten/geschichten/feed.rss', '#press_list');
		    }
			fp.loadData(0,$('#suchbegriff').attr('value'));
		}
	});


	/* RECHTE BOXEN */
	$('.marg_box.mb_2').each(function() {
		$(this).find('.acc_item .acc_head').show();
		$(this).find('.acc_item .mb_cont').hide();
		$(this).find('.acc_item:first .acc_head').hide();
		$(this).find('.acc_item:first .mb_cont').show();
		
		$(this).find('.acc_head a').mouseover(function() {
			if(!$(this.parentNode).hasClass('lock')) {
				$(this.parentNode.parentNode.parentNode).find('.acc_head').addClass('lock');
				$(this.parentNode.parentNode.parentNode).find('.acc_item .mb_cont:visible').slideUp('fast');
				$(this.parentNode.parentNode.parentNode).find('.acc_item .acc_head:hidden').slideDown('fast');
				$(this.parentNode.parentNode).find('.mb_cont:hidden').slideDown('fast');
				$(this.parentNode.parentNode).find('.acc_head:visible').slideUp('fast', function() {$('h4.acc_head.lock').removeClass('lock');});
			}
		});
	});
	
   $('.marg_box.mb_stories').each(function() {
        $(this).find('.acc_item .acc_head').show();
        $(this).find('.acc_item .mb_cont').hide();
        $(this).find('.acc_item:first .acc_head').hide();
        $(this).find('.acc_item:first .mb_cont').show();

        $(this).find('.acc_head a').mouseover(function() {
            if(!$(this.parentNode).hasClass('lock')) {
                $(this.parentNode.parentNode.parentNode).find('.acc_head').addClass('lock');
                $(this.parentNode.parentNode.parentNode).find('.acc_item .mb_cont:visible').slideUp('fast');
                $(this.parentNode.parentNode.parentNode).find('.acc_item .acc_head:hidden').slideDown('fast');
                $(this.parentNode.parentNode).find('.mb_cont:hidden').slideDown('fast');
                $(this.parentNode.parentNode).find('.acc_head:visible').slideUp('fast', function() {
                    $('h4.acc_head.lock').removeClass('lock');
                });
            }
        });
    });

	/* DOWNLOADLIST */
	$('ul.dlmainmenu > li > a').click(function() {
		if(!b_isBadBrowser) {$(this).blur();}
		$('ul.dlmainmenu > li').removeClass('active');
		$(this.parentNode).addClass('active');

		if($(this.parentNode).attr('id') == 'rbs') {
			$('#downloadsearch').hide();
			$('#downloadslist').show();
		} else if($(this.parentNode).attr('id') == 'sws') {
			$('#downloadsearch').show();
			$('#downloadslist').hide();
		}
	});
	
	
	$('#cont_main.downloads #downloadslist li.topic a').click(function(ev) {
		if(!b_isBadBrowser){$(ev.target).blur();}
		$('#downloadslist li.active ul.lev2:visible').slideUp('fast', function() {
			$('#downloadslist li.active').removeClass('active');
		});
		if(!$(ev.target.parentNode).is('.active')) {
			$(ev.target.parentNode).find('ul.lev2').slideDown('fast', function() {
				$(ev.target.parentNode).addClass('active');			
			});
		}
	});

	/* KONTAKTFORMULAR */
	// beim Start die initial-Werte der Felder sammeln:
	$('.kontaktform input[type!="radio"][type!="checkbox"], .kontaktform textarea, .kontaktform select').each(function() {
		if(typeof(a_contactFormValues[$(this).attr('name')]) == 'undefined') {
			a_contactFormValues[$(this).attr('name')] = $(this).attr('value');
		}
	});
	$('.kontaktform input[type="radio"], .kontaktform input[type="checkbox"]').each(function() {
		if($(this).attr('checked') && typeof(a_contactFormValues[$(this).attr('name')]) == 'undefined') {
			a_contactFormValues[$(this).attr('name')] = $(this).attr('value');
		}
		
	});
		
	// beim fokusieren die Vorbelegung lÃƒÂ¶schen:
	$('.kontaktform input.ini').one('focus', function() {
		$(this).removeClass('ini');
		if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
			$(this).attr('value', '');
		}
	});
	

	// beim Verlassen den vorbelegungswert wiedereinfÃƒÂ¼gen:
	$('.kontaktform input').blur(function() {
		if($(this).attr('value') == ''){
			var myVar = '';
			if(typeof(a_contactFormValues[$(this).attr('name')]) == 'undefined') {
				myVar = $(this).attr('title');
				if($(this).is('.pflicht')) {
					myVar +='*';
				}
			} else {
				myVar = a_contactFormValues[$(this).attr('name')];
			}

			$(this).attr('value',myVar).addClass('ini').one('focus', function() {
				$(this).removeClass('ini');
				if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
					$(this).attr('value', '');
				}
			});
		}
	});

	// beim klick auf den Resetbutton:
	$('.kontaktform a.resetbtn').click(function() {
		if(!b_isBadBrowser){$(this).blur();}

		// Fehlerhinweise entfernen:
		$('h2.error_headline, h2.email_error_headline').slideUp('fast');
		$('.kontaktform .error').removeClass('error');
		
		// werte zurÃƒÂ¼cksetzen:
		$('.kontaktform input, .kontaktform textarea, .kontaktform select').each(function() {
			var myVar2 = '';
			if(typeof(a_contactFormValues[$(this).attr('name')]) == 'undefined') {
				myVar2 = $(this).attr('title');
				if($(this).is('.pflicht')) {
					myVar2 +='*';
				}
			} else {
				myVar2 = a_contactFormValues[$(this).attr('name')];
			}

			$(this).addClass('ini').one('focus', function() {
				$(this).removeClass('ini');
				if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
					$(this).attr('value', '');
				}
			});

			// Textfelder zurÃƒÂ¼cksetzen
			if(!$(this).is('[type="radio"]')) {
				$(this).attr('value',myVar2);
			}

			// radio und checkboxen zurÃƒÂ¼cksetzen
			if($(this).is('[type="radio"], [type="checkbox"]')) {
				$(this).removeAttr('checked');
				if(typeof(a_contactFormValues[$(this).attr('name')]) != 'undefined' && a_contactFormValues[$(this).attr('name')] == $(this).attr('value')) {
					$(this).attr('checked', 'checked');
				} 
			}
			
			// selectboxen zurÃƒÂ¼cksetzen
			if($(this).is('select')){
				var myOvar = '';
				if(typeof(a_contactFormValues[$(this).attr('name')]) != 'undefined') {
					myOvar = a_contactFormValues[$(this).attr('name')];
					$(this).find('option').each(function() {
						$(this).removeAttr('selected');
						if(myOvar == $(this).attr('value')) {
							$(this).attr('selected', 'selected');
						}
					});
				}
			}
		});
	});
	
	// beim Klick auf den Submitbutton:
	$('.kontaktform a.submitbtn').click(function() {
		if(!b_isBadBrowser){$(this).blur();}
		$('h2.email_error_headline, h2.error_headline').hide();
		$('.kontaktform .error, label.error').removeClass('error');
		
		$('.emailadress').each(function() {
			if(!$(this).attr('value').match(/^[a-zA-Z0-9äöüßÄÖÜ\_\.\-]+@[a-zA-Z0-9\_\.\-]+\.[a-z]{2,4}$/)) {
				$('h2.email_error_headline').slideDown('fast');
				$(this).addClass('error').addClass('ini').attr('value', $(this).attr('title')+'*').one('focus', function() {
					$(this).removeClass('ini');
					if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
						$(this).attr('value', '');
					}
				});
			}
		});
		
var date_correct=false;

$('input[name="von"]').each(function() {
 if(!checkDate($(this))){
   $('h2.date_error_headline').slideDown('fast');
 $(this).addClass('error').addClass('ini').attr('value', $(this).attr('value')).one('focus', function() {
	$(this).removeClass('ini');
	if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
	$(this).attr('value', '');
			}
		});
   }
   else{
   $(this).removeClass('error');
    $('h2.date_error_headline').hide();
    date_correct=true;
  }
});
		
$('input[name="bis"]').each(function() {
 if(!checkDate($(this))){
   $('h2.date_error_headline').slideDown('fast');
 $(this).addClass('error').addClass('ini').attr('value', $(this).attr('value')).one('focus', function() {
	$(this).removeClass('ini');
	if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
	$(this).attr('value', '');
			}
		});
   }
   else{
   $(this).removeClass('error');
   if(date_correct){
    $('h2.date_error_headline').hide();
    }
  }
});
		

		$('.kontaktform .pflicht').each(function() {
			if($(this).is('input[type="checkbox"], input[type="radio"]') && !$(this).is(':checked') && $('.kontaktform').find('[name="'+$(this).attr('name')+'"]:checked').length < 1) {
				$('.kontaktform label[for="'+$(this).attr('id')+'"]').addClass('error');
			}
			
			if($(this).attr('value') == '' || $(this).attr('title') == $(this).attr('value').replace(/\*$/, "")){
				$('h2.error_headline').slideDown('fast');
				$(this).addClass('error').addClass('ini').attr('value', $(this).attr('title')+'*').one('focus', function() {
					$(this).removeClass('ini');
					if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
						$(this).attr('value', '');
					}
				});
				if($(this).is('textarea')) {
					$(this).attr('value','');
				}
			}
		});

		if($('.kontaktform .error').length < 1){
			$('.kontaktform .ini').each(function() {
				if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
					$(this).attr('value', '');
				} 
			});
			$('.kontaktform form').submit();
		}
	});

/*LINKE BOX*/
	
	// accordeon for new stories
                     $('#accordeon').accordion({
                     active:false,
                     collapsible: true,
                     clearStyle: true,
                     animated: 'easeslide'
                      });	
	
	
});

function checkDate(elem){
elem=elem.val();
elem=elem.split("-");
if(typeof(elem)=="object"){
for(var s in elem){
      number=parseInt(elem[s]);
    if(!number){
        return false;
    }
}

return true;
}
if(parseInt(elem)){
number=parseInt(elem);
if (number<2050){
return true;
}
}

return false;
}

/**
 * the calendar section 
 */
 
var EventCalendar = function() {
  var loadCal = function(caldate) {
      $('#pane3').load(s_php_path + '/ajax/ajax.EventCalendar.php', {startMonth : ' '+caldate+' '}, function() {attatchHandler();});
  }
  this.loadCal = loadCal;
  
  var attatchHandler = function() {
    $('div.event').mouseover(function() {
      // var position = $(this).position();
      var position = getPosition(document.getElementById($(this).attr('id')));
      // var myid = $(this).attr('id');
      var myrel = $(this).attr('rel');
      positionBox(position, myrel);
    });  
  }
  this.attatchHandler = attatchHandler;
  
  var positionBox = function(myPosition, myRel) {
    var boxPositionL = 0;
    var boxPositionT = myPosition.top;
    if(myPosition.left > 190) {
      boxPositionL = myPosition.left - 188;
    } else {
      boxPositionL = myPosition.left + 30;
    }
    var myBox = $('div.event_box:first');
    $('div.event_box:first').remove();
    $('body').append(myBox);
    $('div.event_body').load(s_php_path + '/ajax/ajax.DayEvent.php', {events : myRel}, function() {
      $('div.event_box').css({'left' : boxPositionL+'px', 'top' : boxPositionT +'px'}).fadeIn('600', activateBox());
    });
  }
  
  var activateBox = function() {
    $('div.event_box').one('mouseenter', function() {
      $(this).one('mouseleave', function() {
        $(this).fadeOut('600');
      }); 
    });
  }
  
  var getPosition = function (obj) {
	  var pos = { left:0, top:0 };
	
	  do {
	    pos.left += obj.offsetLeft;
	    pos.top += obj.offsetTop;
	  } while (obj = obj.offsetParent);
	
	  return pos;
  }

}
var ec = new EventCalendar();
$().ready(function() {
  ec.attatchHandler();
});


//// feedparser home reiter
var feedparser_homepage= function(s_feedurl, s_target,tab_type,items_anz){
	var s_myParser  = '/resources/_php/feedparser_home.php';
	var s_myFeedurl = s_feedurl;
	var s_myTarget  = s_target;
	var i_myIndex   = 0;
	var i_myMax     = items_anz;
        var s_type=tab_type;

	var loadData    = function(i_index, s_suchstring){
		if(typeof(i_index) != 'undefined') {
			i_myIndex   = i_index;
		}
		if(typeof(s_suchstring) != 'undefined') {
			s_mySuchstr = s_suchstring;
		}
		$.post(s_myParser, {myurl:s_myFeedurl,pre:i_myIndex,max:i_myMax,tab_type:s_type}, function(data){
		  $(s_myTarget).html(data); 
		 $(s_myTarget).parent().jScrollPane({showArrows:false, scrollbarWidth: 13, scrollbarMargin: 15});
		});
	}
	this.loadData   = loadData;

	var setMax      = function(i_max) {
		if(typeof(i_max) != 'undefined') {
			i_myMax   = i_max;
		}
	}
	this.setMax = setMax;

}

// Timeline

function loadTimeLine(){



    eventSource = new Timeline.DefaultEventSource();

    var theme = Timeline.ClassicTheme.create();
    theme.event.bubble.width = 350;
    theme.event.bubble.height = 200;
    theme.event.track.height = 10;
    theme.event.track.gap= 5;
    theme.event.tape.height = 15;
    
    
    var d = Timeline.DateTime.parseGregorianDateTime("2011")
    var bandInfos = [
    Timeline.createBandInfo({
        eventSource:    eventSource,
        date : "Jun 1 2011 00:00:00 GMT",
        width:          "85%",
        intervalUnit:   Timeline.DateTime.YEAR,
        theme : theme,
        intervalPixels: 80
    }),
    Timeline.createBandInfo({
        overview:       true,
        eventSource:    eventSource,
        date : "Jun 1 2011 00:00:00 GMT",
        width:          "15%",
        intervalUnit:   Timeline.DateTime.YEAR,
        theme: theme,
        intervalPixels: 40
    })
    ];

bandInfos[1].syncWith = 0;
bandInfos[1].highlight = true; 


tl = Timeline.create(document.getElementById("timeline"), bandInfos);
    loadData("/resources/_php/timeline_feed.php");


$('.timeline-band-0 .timeline-ether-bg').css("background-image","url(/resources/_img/system/geschichten_bg.jpg)");
$('.timeline-band-1 .timeline-ether-bg').css("background-color","red");
$('.timeline-band-0 .timeline-date-label').css("color","black");
$('.timeline-band-1 .timeline-date-label').css("color","white");
$('.timeline-band-0 .timeline-ether-lines').css("border-color","Silver");
$('.timeline-band-1 .timeline-ether-lines').css("border-color","white");

// overwrite bubble

Timeline.DefaultEventSource.Event.prototype.fillInfoBubble = function(element, theme, labeller) {
var content=this.getImage()?'<img class="img_bubble" src="'+this.getImage()+'">':'';
content+=this.getImage()?'<div class="content_bubble">':'<div class="content_bubble_no_image">';
content+=this.getText()?'<div class="titel_bubble">'+this.getEarliestEnd().getFullYear()+'-'+this.getText()+'</div>':'';
content+=this.getDescription()?'<div class="description_bubble">'+this.getDescription()+'</div>':'';
//content+=this.getEarliestEnd()?'<div class="date_bubble">'+this.getEarliestEnd().getFullYear()+'</div>':'';
content+=this.getLink()?'<div class="link_bubble"><a href="'+this.getLink()+'">mehr ...</a></div>':'';
content+='</div>';
jQuery(element).html(content);
  };


}
var resizeTimerID = null;
function onResize() {
    if (resizeTimerID == null) {
        resizeTimerID = window.setTimeout(function() {
            resizeTimerID = null;
            tl.layout();
        }, 500);
    }





  
}

$().ready(function(){
   $('.mb_item input').click(function(){
   
         category=$(this).attr("name");
         
         if(category=="alle"){
           
            $('.mb_item input').each(function(){
            $(this).attr("checked",false);         
            });
             $(this).attr("checked",true);
          categories=[];
          loadData("/resources/_php/timeline_feed.php?category="+category);
          return;
         }
         
          $('.mb_item input[name="alle"]').attr("checked",false);
         
         ins=$(this).attr("checked");

if(ins){
    categories[category]=category;
   // console.log(categories);
  //  console.log(categories.length);
}
else{
   delete categories[category];
}


if(categories && !$.isEmptyObject(categories )){
     category="";
    for (var v in categories) {
    category=category+v+",";
                }
          category=category.substr(0, category.length-1);     
} else{
    category="alle";
}
      
       loadData("/resources/_php/timeline_feed.php?category="+category);
   });
});

function loadData(url){
   Timeline.loadXML(url, function(xml, url) {
    eventSource.clear();
    eventSource.loadXML(xml, url);
    $('.timeline-event-icon img').css("margin","-5px")
    });
   
}

function loadStoriesFromCategory (category,index){
           $.post("/resources/_php/feedparser_category.php", {
            myurl:"/sparkassengeschichten/geschichten/feed.rss",
            pre:index,
            max:5,
            category:category
        }, function(data){
            $('#press_list').html(data);
        });
}

function moveTimeLine(position,event){
if(event=='onmousedown'){
  if(!stop) {
  var olddate=tl.getBand(0).getCenterVisibleDate();
var diff=position=="left"?-7:7;
olddate=olddate.setFullYear(olddate.getFullYear()+(diff),1,1);
tl.getBand(0).setCenterVisibleDate(olddate);
 setTimeout("moveTimeLine('"+position+"','onmousedown');", 500);
  }
  stop=false;
  $('.timeline-event-icon img').css("margin","-5px")
}

}

// back search
function history(elem){
$.ajax({
  url: "/resources/_php/searchengine.php",
  async :false,
  data:{"back":elem},
  success: function(){
  }
});
}
