	var is_print = 'none' == jQuery('.printcss').css('visible') ? true : false;


var refreshScrollableHeight = function (doUpdate, minHeight, maxHeight)
{
	
	if (is_print) return;
	
	if(undefined == minHeight) {
		minHeight = 563;
	}
	
	var offsetBottom 	= 19;
	if($('.main_content').attr('id') == 'main_content_popup') {
		offsetBottom = 40;
	}
	var headerHeight 	= $('.globalTinyScroller .viewport').offset().top;
	
	var minHeight = minHeight - headerHeight - offsetBottom;
	var bodyHeight 	 	= $('body').innerHeight();
	var overviewHeight 	= $("#overview").innerHeight();
	var scrollableHeight= bodyHeight - offsetBottom - headerHeight;
	
	var tmpHeight = (overviewHeight > scrollableHeight) ? scrollableHeight : overviewHeight;
	
	tmpHeight = (tmpHeight > minHeight) ? tmpHeight : minHeight;
	
	tmpHeight =  (0 < maxHeight && tmpHeight > maxHeight) ? maxHeight : tmpHeight;
	
	$(".globalTinyScroller .viewport").css("height",(tmpHeight)+"px");
	
	if (doUpdate) {
		globalTinyScroller.update();
	}
};

var refreshScrollable = function()
{
	return;
	
	if (is_print) return;
		
	var tPos = globalTinyScroller.getScrollPosition();
	refreshScrollableHeight(true);
	globalTinyScroller.scroll(tPos);
};



function fixBoxBorders()
{
	$('.box.border_right_1px:not(.no_border_fix)').each(function()
	{
		var row = $(this).parents('.row');
		var rowHeight = row.innerHeight();
		var rowTop =  row.offset().top;
		var thisTop = $(this).offset().top;
		var newheight = rowHeight + rowTop - thisTop; 		
		$(this).css('height', newheight) ;
	
	});
}

function fixBoxLeftBorders()
{
	$('.box.border_right_1px:not(.no_border_fix)').each(function()
				{
					$(this).css('height', 'auto') ;
					var row = $(this).parents('.row');
					var rowHeight = row.innerHeight();
					var rowTop =  row.offset().top;
					var thisTop = $(this).offset().top;
					var newheight = rowHeight + rowTop - thisTop; 		
					$(this).css('height', newheight) ;
				
				});
}

var initScroller = function()
{
	globalTinyScroller = {scroll:function(){}};
	return;
	
	globalTinyScroller = $(".globalTinyScroller");
	if(globalTinyScroller.hasClass('globalTinyScroller'))
	{
		refreshScrollableHeight();
		globalTinyScroller.tinyscrollbar({});
		
		var refreshTimeOut = false;
		
		$(window).resize(function() 
		{
				if (false !== refreshTimeOut) window.clearTimeout(refreshTimeOut);
				refreshTimeOut = window.setTimeout(function(){
					refreshScrollableHeight(true);
					refreshTimeOut = false;
				},100);
		});	
	}
}


function initMovieMouseOver() {
	$('.movie_over').bind('mouseover', function() 
	{
		var $this = $(this); 
		var over_element = $this.siblings('.over_element');
		if(!over_element.length>0) {
			over_element = $this.parent().siblings('.over_element');
		}
		if(!over_element.length>0) return;
		var maxRight = $('.main_content').offset().left;

		maxRight += $('#main_content_full .viewport').innerWidth();
		
		var right = $this.offset().left;
		right += over_element.outerWidth();
		
		if (maxRight < right)
		{
			over_element.children().children('.left').removeClass('left').addClass('right');
			over_element.children('.over_element_visible').addClass('over_element_visible_right');
			over_element.css({'left' : '-220px'});
		} 
		
			$this.css({'position': 'absolute'});
			$this.css({'z-index' : '3'});
			$this.siblings().css({'z-index' : '3'});
			$this.parent().css({'z-index' : '3'});
		
			if($page_language_code != "de")
				over_element.children('.over_element_visible').addClass('is_'+$page_language_code);
				
			over_element.show();
		
		
	});	/* end of mouseover function */
	
	$('.movie_over').bind('mouseout', function() 
	{
		var $this = $(this);
		if ($this.hasClass('hover_over')) {
			var foo = $this.parent().parent().parent();
			$this = $('.movie_over', foo);
		}
		$this.siblings('.over_element').hide();
		$this.parent().siblings('.over_element').hide();
		$this.css({'position': ''});
 		$this.css({'z-index' : '1'});
		$this.parent().css({'z-index' : '1'});
 		$this.siblings().css({'z-index' : '1'});
	});	/* end of mouseout function */
}


function removeGalleryPopup(element){
    $(element).parent().siblings('.bg_black_trans').remove();
    $(element).parent().remove();
}


var csMovieHandlerObject = null;
var currentFilmTrailer = false;

function initProjekktorPlayer(_page_id,_cinema_id,_page_url,_ivw_code,_playerDisplayTyp,_currentFilmTrailer,forceToPlay)
{
 	var tCsConfig 						= new Object();
	tCsConfig.hasPrerollAlreadyPlayed 	= false; 
	
	currentFilmTrailer 					= _currentFilmTrailer
	
    csMovieHandlerObject = new csMovieHandler_TrailerCenter(	$("#mediathek_player") , 
    															(forceToPlay)?currentFilmTrailer:false , 
    															tCsConfig, 
    															$("#mediathek_player_titleBar") 
    														);
 
    csMovieHandlerObject.kino_id 				= _cinema_id;
    csMovieHandlerObject.page_id 				= _page_id;
    csMovieHandlerObject.playerDisplayTyp 		= _playerDisplayTyp;
    csMovieHandlerObject.page_url				= _page_url;    
    csMovieHandlerObject.ivwCode 		  		= _ivw_code;

	csMovieHandlerObject.create();

	if(!forceToPlay)
	{
		$('.projekktor').live('click.firstStart',function()
		{
			$('.projekktor').die('click.firstStart');
			csMovieHandlerObject.playMovie(currentFilmTrailer);
	
			return false;
		});
	}

	$(".resolution_switch_mediathek img").click(function()
	{ 
		if(!$(this).hasClass("res_active"))
		{
			var res_active = $(".resolution_switch_mediathek img.res_active");
			
			var nextImgO = res_active.attr("src").replace("_active","");
			
			res_active.attr("src",nextImgO);	 
			res_active.removeClass("res_active");
			 				
			var nextImg = $(this).attr("src").replace(".png","_active.png");
			
			$(this).attr("src",nextImg);
			$(this).addClass("res_active");
		
			
			if(csMovieHandlerObject.projekktor.getIsPlaying())
			{
				csMovieHandlerObject.changeFileSize( $(this).attr("alt") );
				csMovieHandlerObject.projekktor.setPlay();
			}else
			{
				csMovieHandlerObject.currentFileSize = $(this).attr("alt");
			}	
		}
	
	});
}

function initProjekktorChapterPlayer(_page_id,_cinema_id,_page_url,_ivw_code,_playerDisplayTyp,_currentFilmTrailer,_forceToPlay,_chapters,_eventsObject)
{
 	var tCsConfig 						= new Object();
	tCsConfig.hasPrerollAlreadyPlayed 	= true; 
	
	currentFilmTrailer 					= _currentFilmTrailer
    
	csMovieHandlerObject = new csMovieHandler_ChapterPlayer($("#mediathek_player"),currentFilmTrailer,tCsConfig,$("#mediathek_player_titleBar"),_eventsObject );
	csMovieHandlerObject.justPlayOneChapter		= true;
    csMovieHandlerObject.kino_id 				= _cinema_id;
    csMovieHandlerObject.page_id 				= _page_id;
    csMovieHandlerObject.page_url				= _page_url;   
    csMovieHandlerObject.playerDisplayTyp 		= _playerDisplayTyp;
    csMovieHandlerObject.ivwCode 		  		= _ivw_code;
	
	csMovieHandlerObject.setChapterArray( _chapters);
	
	csMovieHandlerObject.create();
	console.log("done initProjekktorChapterPlayer");	
}

function openFAQentry(tThis)
{
	$(tThis).siblings().toggle();

	if(!DetectAllMobileDevices())
	{
		refreshScrollable();
	}

	return false;
}

function Set_Cookie( value)
{
name='KINOID';
expires = 365;
path = '/';
domain = '.cinestar.de';
secure = false;
/* set time, it's in milliseconds */
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
} 

/*
 * KINOAUSWAHL SEITE
 */
var show_cinemaselection = function () 
{
	if(DetectAllMobileDevices())
	{
		$(this).hide();
		$("#mobile_cinema_selection, #mobile_cinema_selection_start").show();
		
	}else
	{
		$('#content').css({'background': 'url(/ccds_tpl_img/vorschalt_top_bg.png) no-repeat top center'});
		
			
		$('#logo').removeClass("margin_bottom_l margin_top_l").addClass("margin_top");
		$('#content_selection').show().css({'height': '600px'});
		$('#content_row').css({'height': '600px', 'background': 'url(/ccds_tpl_img/vorschalt_bg.png) no-repeat bottom center'});
		$('#pre_text').hide();
		$('#button_cinema_selection').hide();
		$("#content_bottom").hide();
		$("#kino_name").hide();
		$('#content_top').hide();
		$('#content').animate({"width": '901px'}, 100);
		$('#content').animate({ "height": '680'}, 500, 
		function(){
			globalTinyScroller = $(".globalTinyScroller");
			if(globalTinyScroller.hasClass('globalTinyScroller'))
			{
				refreshScrollableHeight();
				globalTinyScroller.tinyscrollbar({});
				
				var refreshTimeOut = false;
				
				$(window).resize(function() 
				{
						if (false !== refreshTimeOut) window.clearTimeout(refreshTimeOut);
						refreshTimeOut = window.setTimeout(function(){
							refreshScrollableHeight(true);
							refreshTimeOut = false;
						},100);
				});	
			}
		});			
	}
	
	return false;
};
	
var show_cinemadetails = function () 
{
	if($('#content').css('width') != '901px' )
	{
		$('#pre_text').hide();
		$('#content').css("width", '901px');
	}
	
	$('#content_row').css({'height': '227px', 'background': 'none'});
	$('#content').css({'background': 'url(/ccds_tpl_img/vorschalt_bg.png) no-repeat top center'});
	$('#logo').addClass("margin_bottom_l margin_top_l").removeClass("margin_top");
	$("#content").animate({"height": "450px"});
	$("#content_bottom").css({"height": "227px"});
	$("#content_bottom").show();
	$("#kino_name").show();
	$('#content_selection').hide();
	$('#content_top').show();
	fixBoxBorders();
};				
	     
var mobile_change_cinema = function(cinemaParamString)
{
	var params = cinemaParamString.split('|');
	
	Set_Cookie(params[1]); 
	window.location.pathname = params[0];
};


var generateTrackingPixel = function(src) {
	var img = $("<img />");
	img.attr('src', src);
	img.addClass("invisible");
	$("body").append(img);
}

function killVideoPlayer(player)
{
	player.projekktor._detachPlayerObject();
	
	var tPlayer 					= player.projekktor.environment.playerDom;
	
	$(tPlayer).replaceWith(player.domObj);
	
	player.projekktor = null;
	player	  			= null;
}

function onclickJobLink($div_container_id)
{
	if($('a#'+$div_container_id+'_link').length > 0)
	{
		$('.job_link').removeClass('underlined');
		$('a#'+$div_container_id+'_link').addClass('underlined');
	
		$('div.jobs_right_row > div').hide();
		$('div.jobs_right_row div#'+$div_container_id).show();
		if(typeof(globalTinyScroller) != "undefined")
			globalTinyScroller.scroll(0);
		
		location.hash = $div_container_id;
	}else
		location.hash = '';
		
	 
	return false;
}

function openFancyIframe($url,$title,$height,$width)
{
	
	$.fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'title'			: $title,
		'width'			: $width,
		'height'		: $height,
		'href'			: $url,
		'type'			: 'iframe'
	});
	
	return false;
}

function openFilmDetailSidebarElement($type)
{
	$("#sb_"+$type).children('.sBox').slideToggle(refreshScrollable);
	
	var $arrow = $("#sb_arrow_"+$type);
	
	if($arrow.attr('src') == "/ccds_tpl_img/arrow_close.png")
	{
		$arrow.attr('src','/ccds_tpl_img/arrow_open.png');
	}	
	else
	{
		$arrow.attr('src','/ccds_tpl_img/arrow_close.png');
	}
	
	//refreshScrollable();
	
	return false;
}

function faqOverviewClick($faq_id)
{
	$('.faqOverview_a').hide();
	$('.faqOverview_q').parent().removeClass('active');

	$('#faqOverview_a_'+$faq_id).show();
	$('#faqOverview_q_'+$faq_id).parent().addClass('active');
	
}

function faqContactFormSearch($val)
{
	$('#faq_did_it_help').show();
	
	var noResults = true;
	$('.faqOverview_noResult').hide();

	if($val == "")
	{
		$(".faq_form_q").show();		
		return;
	}
	
	$(".faq_form_q").hide();
	
	$(".faq_question_question:contains('"+$val+"'), .faq_question_question:contains('"+$val.toUpperCase()+"') , .faq_question_question:contains('"+($val.charAt(0).toUpperCase() + $val.slice(1))+"')").each(function(e)
	{
		$(this).show();
		
		noResults = false;
	});
	
	$(".faq_form_a:contains('"+$val+"'), .faq_form_a:contains('"+$val.toUpperCase()+"') , .faq_form_a:contains('"+($val.charAt(0).toUpperCase() + $val.slice(1))+"')").each(function(e)
	{
		$faq_id = $(this).parent().parent().show();
		
		noResults = false;
	});
	
	if(noResults)
	{
		$('.faqOverview_noResult').show();
		$('#contact_form_container').show(); 
		$('#faq_did_it_help').hide();
		
	}
	
	fixBoxLeftBorders(); 
}

function faqOverviewSearch($val)
{
	
	var noResults = true;
	$('.faqOverview_noResult').hide()
	$('.faqOverview_q').parent().removeClass('active');
	$(".faqOverview_a").hide();
	
	if($val == "")
	{
		$(".faqOverview_q").show();		
		return;
	}
	
	$(".faqOverview_q").hide();
	
	$(".faqOverview_a:contains('"+$val+"')").each(function(e)
	{
		$faq_id = $(this).attr('id').replace('faqOverview_a_','');
		$('#faqOverview_q_'+$faq_id).show();
		
		noResults = false;
	});
	
	$(".faqOverview_q span.table-cell:contains('"+$val+"')").each(function(e)
	{
		$faq_id = $(this).parent().attr('id').replace('faqOverview_q_','');
		$('#faqOverview_q_'+$faq_id).show();
		
		noResults = false;
	});
	
	if(noResults)
		$('.faqOverview_noResult').show();
}

function get_cookie( cookieName )
{
    strValue = false;
    
    if( strCookie = document.cookie )
        {
            if( arrCookie = strCookie.match( new RegExp( cookieName + '=([^;]*)', 'g')))
                {
                    strValue=RegExp.$1;
                }
        }
    return(strValue);
}
    
    
    /**
      * Funktion:set_cookie()
      * setzt cookie
      * Parameter: cookie-Name,cookie-Wert,Haltbarkeit in Tagen
      * Rückgabewert: true/false
      **/
      
function setCookie(cookieName,cookieValue,intDays)
{
    if(!is_cookie_enabled())
        {
            return false;
        }
        
    objNow = new Date();
    strExp = new Date( objNow.getTime() + ( intDays * 86400000) );
    document.cookie = cookieName + '=' + 
                      cookieValue + ';expires=' + 
                      strExp.toGMTString() + ';';
    return true;
}
 
 
    /**
      * Funktion:delete_cookie()
      * Löscht cookie
      * Parameter: cookie-Name
      * Rückgabewert: true/false
      **/
 
function delete_cookie(cookieName)
{
    if(document.cookie)
        {
            document.cookie = cookieName + '=' +
                              get_cookie(cookieName) +
                              ';expires=Thu, 01-Jan-1970 00:00:01 GMT;'; 
            return true;
        }
    return false;
}
 
 
    /**
      * Funktion is_cookie_enabled()
      * prüft ob cookies erlaubt sind
      * Parameter: nix
      * Rückgabewert: true/false
      **/
      
function is_cookie_enabled()
{
    if(typeof navigator.cookieEnabled!='undefined')
        {
            return navigator.cookieEnabled;
        }
    
    set_cookie('testcookie','testwert',1);
    
    if(!document.cookie)
        {
            return false;
        }
    
    delete_cookie('testcookie');
    return true;        
}

