	// schlagerwebring framework.js
	// ver 0.8

	// tabView 1.0
	jQuery.fn.tabView = function (map) {
		var $this=this;
		var $tabContent=$('<DIV class="tabContent ui-helper-clearfix"></DIV>').appendTo ($this);		
		$('li a', $this).bind ('click', function () {
		
			if ($(this).hasClass ('noAjax')) {
			} else {
				$('li', $this).removeClass ('active');
				$(this).parent ().addClass ('active');
				$tabContent.ajaxStart (function () {
					$(this).html ('<DIV id="loadingTabContent"><IMG src="/_lib/img/ajax_wait.gif">Einen Moment bitte...</DIV>');
				});
				$tabContent.load (this.href, function () {	
					$('a[target=tab]', $tabContent).click(function() { 
						$tabContent.load(this.href); 
						return false; 
					});
					$('body').trigger ('tabLoaded');
				});
				return false;
			}

		});
		$('li a:eq(0)', $this).trigger ('click');
	}
	jQuery.fn.tabLink = function (map) {
		var $this=this;
		$this.bind ('click', function () {
			$('.tabContent').load (this.href);
			return false;
		});		
	}
	
	// expandableView
	jQuery.fn.expandableView = function (map) {
		var $this=$(this);
		var $headLine=$(':first', $this);
		$headLine.addClass (($this.hasClass ('minified')?'expandable-icon-minified':'expandable-icon-expanded'));
		$headLine
			.addClass ('clickable')
			.bind ('click', function () {
				$headLine.next ().toggle ('slow', function () {
					$('body').trigger ('expandableChanged');
				});
				$headLine.toggleClass ('expandable-icon-expanded').toggleClass ('expandable-icon-minified');
				$this.toggleClass ('minified');
			})
		;
	}
	

		


	// STATUSMESSAGE
	jQuery.fn.showMessage = function (html) {
		$('<DIV class="statusMessage">'+html+'</DIV>')
			.appendTo (this)
			.position ({
				my: 'center bottom',
				at: 'center bottom',
				of: this
			})
		;
	}

	jQuery.fn.hideMessage = function (html) {
		$('.statusMessage', this).remove ();
	}
	

	// DOCUMENT-READY
	$(document).ready (function () {
	
		jQuery.ideagento.browser.dim.windowHeight=$(window).height ();
		jQuery.ideagento.browser.dim.windowWidth=$(window).width ();
		
		// TABS
		$('.tabContainer').each (function () {
			$(this).tabView ();			
		});
		$('a[target=tabContainer]').each (function () {
			$(this).tabLink ();
		});
		
		// EXPANDABLE
		$('.expandable').each (function () {
			$(this).expandableView ();
		});		
		
		// LAUFLEISTE
		$.getJSON ('/_data/ticker/idgTicker.json', function (data) {
			if (data.message.length) {
				tickerPos=996;
				$('#ticker').append ('<SPAN id="tickertext" style="position: absolute; left:'+tickerPos+'px">'+data.message+'</SPAN>')
				window.setInterval ("animateTicker ()", 40);
			}
		});
		
		// NEWS
		if (typeof (newsCategory)=='string') {
			$.getJSON (jQuery.ideagento.libs.news.dataPath+'entries/all.json', function (data) {
				if (data.length) {
					var from={title: $('title').text (), href: window.location.href};
					$newsContainer=$('<DIV><DIV class="content"></DIV></DIV>');
					var now=new Date ().getTime ();
					var ids4FullView=[];
					for (var i=0, j=0; i<data.length && j<jQuery.ideagento.libs.news.entries4NewsBox; i++) {
						if (1000*data[i]['date']<now && 1000*data[i]['expiration_date']>now) {
							j++;
							var datum=new Date (1000*data[i]['date']);
							var entry=$('<P entry="'+data[i]['id']+'" view="'+newsCategory+'" class="ui-helper-clearfix"></P>');
							entry.html ('<strong>'+datum.strdate ('%d.%m.%Y')+'</strong><br>'+data[i]['title']+data[i]['teaser']+'<A target="_blank" href="'+strip_tags (data[i]['content'], '')+'" class="right">mehr</A>');
							
							$('.content', $newsContainer).append (entry);
						}
					}
										
					$newsContainer
						.appendTo ('#smagoNews');
					;
					$('.footer a[href^="/extras/news/"]', $newsContainer).click (function () {
						var $form=$('#newsForm');
						$('input[name=entry]', $form).val ('');
						$('input[name=view]', $form).val (newsCategory);
						$form.submit ();
						return false;
					});
				}
			});
		
		}		
				
	});
	
	
function animateTicker () {
	tickerPos--;
	$('#tickertext').css ('left', tickerPos+'px');
}	
	
	
function clone(obj) {
	if (obj == null || typeof (obj) != 'object') return obj;
	var c = new obj.constructor();
	for(var key in obj) c[key] = clone(obj[key]);
	return c;
}

Date.prototype.strdate = function(retValue) {

  
  if (this.getYear ()<999) intAddYears=1900; else intAddYears=0;

  retValue=retValue.replace (/%m/g, (1+this.getMonth ()).toString ().strpad (2, '0', 1));
  retValue=retValue.replace (/%d/g, this.getDate ().toString ().strpad (2, '0', 1));
  retValue=retValue.replace (/%Y/g, (intAddYears+this.getYear ()));

  retValue=retValue.replace (/%H/g, (this.getHours ().toString ().strpad (2, '0', 1)));
  retValue=retValue.replace (/%i/g, (this.getMinutes ().toString ().strpad (2, '0', 1)));
  retValue=retValue.replace (/%s/g, (this.getSeconds ().toString ().strpad (2, '0', 1)));
  
  return (retValue);
}

String.prototype.strpad = function () {

  var STR_PAD_RIGHT=0, STR_PAD_LEFT=1, STR_PAD_BOTH=2;
  var retValue=new String(this);

  switch (arguments.length) {
    case 0:	return (retValue);
    		break;
    case 1: strPadChar=' ';
            intPadLength=arguments[0];
            strPadPosition=STR_PAD_RIGHT;

            break;
    case 2: strPadChar=arguments[1].substr (0,1);
            intPadLength=arguments[0];
            strPadPosition=STR_PAD_RIGHT;
            break;
    case 3: strPadChar=arguments[1].substr (0,1);
            intPadLength=arguments[0];
            strPadPosition=arguments[2];
            break;
  }

  switch (strPadPosition) {
    case 0: for (var dummy=this.length; dummy<intPadLength; dummy++) {
              retValue+=strPadChar;
            }
            break;
    case 1: for (var dummy=this.length; dummy<intPadLength; dummy++) {
              retValue=strPadChar+retValue;
            }
            break;
    case 2: for (var dummy=this.length; dummy<intPadLength; dummy+=2) {
              retValue+=strPadChar;
              if (retValue.length==intPadLength) break;
              retValue=strPadChar+retValue;
            }
            break;

  }

  return (retValue);
}

	
	
function strip_tags (input, allowed) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Marc Palau
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Eric Nagel
    // +      input by: Bobby Drake
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Tomasz Wesolowski
    // +      input by: Evertjan Garretsen
    // +    revised by: Rafal Kukawski (http://blog.kukawski.pl/)
    // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
    // *     example 4: strip_tags('1 < 5 5 > 1');
    // *     returns 4: '1 < 5 5 > 1'
    // *     example 5: strip_tags('1 <br/> 1');
    // *     returns 5: '1  1'
    // *     example 6: strip_tags('1 <br/> 1', '<br>');
    // *     returns 6: '1  1'
    // *     example 7: strip_tags('1 <br/> 1', '<br><br/>');
    // *     returns 7: '1 <br/> 1'
    allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
    var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
        commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
    return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
        return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
    });
}	
