
var orte ={};

orte.init = function (o) {
	this.timer=null;
	this.isLive=($('#ytclip').length>0)?1:0;
	this.check();
}
orte.check=function() {
	var that=orte;
	var checkRef=orte.check;
	$.get( 'request_handler.php?action=check', function(data) {
		var data=parseInt(data);

		if((data==0 || data==1) && that.isLive!=data) {
			//console.log('refresh');
			that.isLive=parseInt(data)
			that.refresh();
		}
	});
	this.timer= window.setTimeout(checkRef, 15000);

}
orte.refresh=function() {
	tb_cClose();
	$.ajax({
		url: "request_handler.php?action=get_video_content",
		cache: false,
		success: function(data){
			$('#termin_akt').html(data);
			// Load Video after video content, cause video cotent writes trailer url to cachefile
			$.ajax({
				url: "request_handler.php?action=get_video",
				cache: false,
				success: function(data){
					$('#video_box').html(data);
					// init thickbox
					tb_init('a.thickbox');
				}
			});
		}
	});

	$.ajax({
		url: "request_handler.php?action=get_termine",
		cache: false,
		success: function(data){
			$('#termin_liste').html(data);
		}
	});
/*
	$.get( 'request_handler.php?action=get_video', function(data) {
		$('#video_box').html(data);
	});
	$.get( 'request_handler.php?action=get_video_content', function(data) {
		$('#termin_akt').html(data);
	});
	$.get( 'request_handler.php?action=get_termine', function(data) {
		$('#termin_liste').html(data);
	});
*/
}

orte.archiv=function() {
	//console.log('archiv');

	$('.list_img_item a').each(function(index, obj){
		//console.log(index, obj);
		$('body').append(
			'<div id="ytclip_'+index+'" class="clip" style="display:none;">'+
			'	<div id="ytclip_src_'+index+'"></div>'+
			'	<div style="text-align:center; padding:8px 0px 8px 0px;"><a href="javascript:tb_cClose()"><img src="images/12Orte_Button.png" title="Zurück zu www.12orte.de" alt="Zurück zu www.12orte.de"/></a></div>' +
			'</div>'
		);
		var href=$(this).attr('href');
		//console.log(href);
		swfobject.embedSWF(
			'/flash/mediaplayer/player.swf',
			'ytclip_src_'+index,
			'640',
			'379',
			'9.0.0',
			'',
			{
				'file':href,
				'autostart':'true'
			},
			{
				'allowfullscreen':'true',
				'allowscriptaccess':'always'
			}
		);

		$(this)
		.attr({
			'class': 'thickbox'
			,'href': '#TB_inline?height=640&amp;width=580&amp;inlineId=ytclip_'+index
		});

	})
	// init thickbox
	tb_init('a.thickbox');
}


$(function(){
	orte.init({});
})
