/**
 * WVG SPLENDID - jQuery Splendid Plugin
 * Copyright (C) 2010 portrix.net GmbH
 * j.scheurer and b.bartels
 **/
function FixSteelbooks(){
	jQuery('.frame_color_no-border img').each(function(){
		jQuery(this).attr('src',jQuery(this).attr('src').replace('splendid_th','dvd_th'));
		jQuery(this).parents('.Blu-ray').removeClass('Blu-ray').addClass('DVD');
	});
	jQuery('.3D').each(function(){
		jQuery(this).find('img[src*=dvd_th]').each(function(){
			jQuery(this).attr('src',jQuery(this).attr('src').replace("dvd_th","splendid_th"));
		});
	})
}

function getVersions(articleID) {
	if (jQuery('#versionnav').length < 1)
		return;
	jQuery.get('/ceemes/wvg/getotherversions/0/articleid=' + articleID + '/page=splendid_article',
		function(html) {
			jQuery('#versionnav').html(html);
		}
	);
}

$.fn.LoadMiniNews = function(){

		// if we are in germany remove the existing ones and smuggle the mininews inside
		jQuery('.mininewsNL').remove();
		
		// distracting the custom controls
		jQuery(this).html('<img src="/ceemes/webfile/show/2140" alt="loading" style="width:32px;height:32px;display:block;margin:60px auto;"/>');

		// getting date when to smuggle
		var myDate = new Date();
		var urlMonth = getURLMonth(myDate.getMonth());
		
		var prevMonth = 0;
		if(myDate.getMonth() > 0)
			prevMonth=myDate.getMonth()-1;
		else
			prevMonth = 11;
		var prevURLMonth = getURLMonth(prevMonth);

		// store calling element
		var handler = jQuery(this);
		// smuggelin
		jQuery.post("http://www.amasia-film.de/ceemes/page/show/splendid_news_"+urlMonth+myDate.getFullYear()+":mininews",function(data){
			var newsData = jQuery(data).not(':not(.mininews)');
			jQuery(handler).html(newsData);
			//jQuery(handler).append('<a class="small more" href="http://www.amasia-film.de/ceemes/page/show/splendid_news_'+urlMonth+myDate.getFullYear()+'">Mehr ..</a>');
			//DaySort(jQuery('.mininews'));
			
			

			jQuery.post("http://www.amasia-film.de/ceemes/page/show/splendid_news_"+prevURLMonth+myDate.getFullYear()+":mininews",function(data){
				var newsData = jQuery(data).not(':not(.mininews)');
				jQuery(handler).append(newsData);
				jQuery(handler).append('<a class="small more" href="http://www.amasia-film.de/ceemes/page/show/splendid_news_'+urlMonth+myDate.getFullYear()+'">Mehr ..</a>');
				DaySort(jQuery('.mininews'));
				// if we're on contact just equal 
				if(jQuery('a.set').text() == "Kontakt")
					EqualContainers();
			});
		});
		
};

function numsort(a,b){
   return a-b;
}

function DaySort(jq_objects){
   var dates = new Array();
   var elements = new Array();
   var counter = 0;
   // Collect and sort elements
   jQuery('.datesort').each(function(){
      var str_date = jQuery(this).text().split(".");
      var date = parseInt(str_date[2]+str_date[1]+str_date[0]);
      dates.push(date);
      if (typeof elements[date+"_"] == 'undefined')
        elements[date+"_"] = jQuery("<span></span>");
      elements[date+"_"] = jQuery(elements[date+"_"]).after(jQuery(jQuery(jq_objects)[counter]).clone());
      counter++;
   });
   dates.sort(numsort);
   // resort elements
   dates.reverse();
   elements.reverse();

   // reinsert
   var handle = jQuery(jq_objects).parent();
   jQuery(handle).html('');

   for(i=0;i<dates.length;i++)
      jQuery(handle).append(elements[dates[i]+"_"]);

}

$.fn.ArticlePreview = function(url, is_available){
    	var context = jQuery(this);
    	jQuery.post(url,function(html){
		var $temp_html = jQuery(jQuery(html).not(':not(div)')[0]);
    		$temp_html.find('.niceDate').each(function(){
    			jQuery(this).text(GetNiceDate(jQuery(this).text()));
    		});
    		
    		var m = '';
    		var m_prev = '';
		var i = 0;
		var final_html = [];
    		$temp_html.find('li').each(function(index) {
    			if(typeof final_html[i] == 'undefined') {
    				final_html[i] = '';
    			}
    			m = jQuery(this).find('.niceDate').text().split('.')[1];
    			if(m != m_prev) {				
    				if(index > 0) {
    					final_html[i] = '</ul>' + final_html[i];
    				}
    				i++;
    				final_html[i] = '<h3>' + getMonth(m) + '</h3><ul style="display: none;">';   				
    			}
    			jQuery(this).find('a').attr('href',jQuery(this).find('a').attr('href').replace('splendid_article','splendid_article:amasia'));
    			if(is_available) {
    				final_html[i] += '<li><a href="' + jQuery(this).find('a').attr('href') + '">' + jQuery(this).find('a').html() + '</a></li>'; 
    			}
    			else {
    				final_html[i] += '<li>' + jQuery(this).html() + '</li>';
    			}
    			m_prev = m;
    		});
    		final_html[i] += '</ul>';
    		for(var i=0; i < final_html.length; i++) {
    			jQuery(context).append(final_html[i]);
    		}		
    		jQuery(context).find('ul').show();
    		
    		// Content loaded completely, add equal class...
    		jQuery(context).parent().addClass('equal');
    		
    		// ...and equal the Height ...
    		//equalHeight(jQuery('.equal'));

    		// ...da nice way
    		EqualContainers();
    	});   
};

$.fn.Slider4Col = function(url) {
    	var context=jQuery(this);
    	jQuery(this).find('.holder').html('<img src="/ceemes/webfile/show/2425" alt="loading" style="width:32px;height:32px;display:block;margin:60px auto;"/>');
        jQuery.post(url,function(html){
        	jQuery(context).find('div.buffer').html(jQuery(html).not(':not(.elm)'));
        	if(jQuery(context).find('div.buffer .elm').length <= 4) {
        		jQuery(context).find('div.buffer').append(jQuery(context).find('div.buffer').html());
        	}
        	jQuery(context).find('.holder').html('<div class="content"></div>');
        	jQuery(context).find('div.buffer .elm a').each(function(){
        	        jQuery(this).attr('href',jQuery(this).attr('href').replace('splendid_article','splendid_article:amasia'));
        	});
        	jQuery(context).slider();
	},"html");
};
    
$.fn.Slider5Col = function(url) {
        var context=jQuery(this);
        jQuery(this).find('.holder').html('<img src="/ceemes/webfile/show/2425" alt="loading" style="width:32px;height:32px;display:block;margin:60px auto;"/>');
        jQuery.get(url,function(html){
        	var prefix=jQuery(context).find('h3').text();
        	prefix = prefix.split(' ');
        	html=html.replace(/##REPLACE##/g,prefix[0]);
        	jQuery(context).find('div.buffer').html(jQuery(html).not(':not(.elm)'));
        	jQuery(context).find('.holder').html('<div class="content"></div>');
        	jQuery(context).slider2();
	});
};


$.fn.Pager5Col = function(url) { 
    	var context = jQuery(this);
	jQuery(this).html('<img src="/ceemes/webfile/show/2425" alt="loading" style="width:32px;height:32px;display:block;margin:60px auto;"/>');
        jQuery.get(url,function(html){
    		var isTrailerPage=jQuery('div.trailer').length && jQuery('.pagename').text()=='splendid_trailer';
    		
    		jQuery(context).html(' ');
    		jQuery(context).html(jQuery(html).not(':not(.elm.rnd)'));
    		
    		// Manipulate buttons and functions on trailerpage 
    		if(isTrailerPage){
    			jQuery(context).find('.elm.rnd').each(function(){
    				var ean = jQuery(this).find('.ean').text();
    				var title = jQuery(this).find('.title').text();
    				var inhalt = jQuery(this).find('.inhalt_kurz').text();
    				var keyframe_url = ""+jQuery(this).find('.trailer_keyframe').text();
    				if(keyframe_url == "")
    					keyframe_url="/img/trailer_kf/"+ean+"_KF_0_00_06.jpg";
    				var movie_url = jQuery(this).find('a.btn').attr('href');
    				jQuery(this).find('a.btn span').text('Jetzt ansehen');
    				
    				jQuery(this).find('a.btn,a.img').click(function(){
    					jQuery('.teaser.info.float h1').text(title);
    					jQuery('.teaser.info.float p').text(inhalt);
    					jQuery('.teaser.info.float p').css('overflow','hidden');
    					jQuery('.float p').height(jQuery('.teaser.info.float').height()-jQuery('.teaser.info.float h1').height()-60);
    					if(!jQuery('.teaser.info.float .more').length)
    						jQuery('.teaser.info.float p').after('<span class="more">...<br/></span>');
    					jQuery('#sendmail input[name=notes]').val(movie_url);
    					
    					jQuery('#trailer div.mov.flv').remove();
    					jQuery('#trailer').html('<a href="/trailer_web/'+ean+'.flv" title="'+keyframe_url+'">trailer here</a>');
    					InitTrailerplayer();
    					return false;
    				});
    			});
    			// Show message when user already send an email
    			var message = window.location+"";
    			message = message.split('#');
    			if(message.length == 2)
    				jQuery('div.trailer div.float #sendmail').after(unescape(message[1]));
    		}
    		// Modify article detail view links
    		jQuery(context).find('.elm.rnd a').each(function(){
    			jQuery(this).attr('href',jQuery(this).attr('href').replace('splendid_article','splendid_article:amasia'));
    		});
    		jQuery(context).find('.elm.rnd:eq(4)').after('<br style="clear:both"/>');
  		jQuery(context).parent('div div.trailer-over').after(jQuery(html).not(':not(div.nav-page)'));
  		if(jQuery('div.nav-page').length>1)
  			jQuery('div.nav-page:last').remove();
    			
    		jQuery('div.nav-page a[href!=#]').each(function(){
    			var lnk_url = jQuery(this).attr('href');
    			jQuery(this).click(function(){
    				jQuery('.5ColPager').Pager5Col(lnk_url);
    				return false;
    			});
    			jQuery(this).attr('href','#');
    		});
    		
    		jQuery('div.nav-page span.currentPage').html('<a class="set">'+jQuery('div.nav-page span.currentPage').text()+'</a>');
    		if(!isTrailerPage){
    			if(jQuery('#search_result_info').length)
    				jQuery('#search_result_info').remove();
    			jQuery('#search-more').after(jQuery(html).not(':not(#search_result_info)'));
    			if(!jQuery('.nav-alpha a.set').length)
    				jQuery('#search_result_info').prepend('<h3 class="no-border">Titel mit den Anfangsbuchstaben: Neuerscheinungen</h3>')
    			else
    				jQuery('#search_result_info').prepend('<h3 class="no-border">Titel mit den Anfangsbuchstaben: '+jQuery('.nav-alpha a.set').text()+'</h3>')
    			jQuery('.nav-page.rnd div a.btn').css('margin-top','2px');    			
    			jQuery('.nav-page.rnd div').clone(true).prependTo('#search_result_info');

    		}
    		if(!jQuery(context).find('div.elm.rnd').length){
    			jQuery(context).html('<span>Leider erzielte Ihre Suche keine Ergebnisse.</span>');
    			jQuery('div.nav-page').html(' ');
    		}else if(jQuery('div.nav-page a').length>20)
    			for(var x = 1; x < jQuery('div.nav-page a').length/20;x++)
    				jQuery(jQuery('div.nav-page a')[(x*20)-1]).after('<br/>');

    		FixSteelbooks();
    	});
};

$.fn.TopSlider = function(url) { 
    	var context=jQuery(this);
    	//jQuery(this).find('.content').html('<img src="/ceemes/webfile/show/2425" alt="loading" style="width:32px;height:32px;display:block;margin:60px auto;"/>');
    	jQuery.get(url,function(html){
    		jQuery(context).find('.content ul').append(jQuery(html).not(':not(.MovieSlide)'));
    		jQuery(context).find('.MovieSlide a[href*=splendid_article]').each(function(){
    			jQuery(this).attr('href',jQuery(this).attr('href').replace('splendid_article','splendid_article:amasia'));
    		});
    		jQuery(context).find('.content').easySlider({
			auto: true,
			continuous: true,
			numeric: true,
			speed: 600,
			pause: 8000
		});
    	});
};
function ModifyArticle(){
var usdate=jQuery('.date').text();
		var x = usdate.split(' ');
		var d = x[0].split('-');
		jQuery('.date').text(d[2]+"."+d[1]+"."+d[0]);
		
		if(jQuery('#trailer').attr('title') == "")
			jQuery('#trailer').attr('title','/img/trailer_kf/'+jQuery(jQuery('.block.lft dl.info.clearfix dd')[1]).text()+'_KF_0_00_06.jpg');
		if(jQuery('#trailer_exists').text() == "200")
			InitTrailerplayer();
		else
			jQuery('#trailer').remove();

		// ExtendedSearch: Genre Dropdown
		if(jQuery('select[name="category[1]"]').length > 0)
			jQuery('select[name="category[1]"]').loadAllGenres();

		if(jQuery('.gal a.state200 img,.col.lft img.pic').length > 0) {
			jQuery('.gal a.state200 img,.col.lft img.pic').load(function(){
				images_loaded++;
				if(images_loaded == jQuery('.gal a.state200 img,.col.lft img.pic').length){
					jQuery('.gal a.state200 img').each(function(){
						if(jQuery(this).width()<jQuery(this).height()){
							jQuery(this).css('margin','0 24px');
							jQuery(this).siblings('p').css('right','24px');
						}
					});
					// Fix heights of the containers
					EqualContainers();
				}
			});
		} else {
			EqualContainers();
		}
			// Fixup fsk searchvalues
		jQuery('select[name="fsk"] option').each(function(){
			if(jQuery(this).attr('value') != "")
				jQuery(this).attr('value',"\""+jQuery(this).attr('value')+"\"");
		});

		jQuery('a.thickbox').each(function(){ jQuery(this).append('<p />');}); // zoom icon
		InitColorboxes();
		Search2SlideEffect();
		// Facebook implementation
		if(jQuery('#post_facebook').length) {
		  	jQuery('#post_facebook').click(function() {
		  		var article_id = jQuery.url.param('article');
		  		var article_ean = jQuery('#cnt-media .block.col.lft.rnd .info.clearfix dd:eq(1)').text();
		  		var format = jQuery('#cnt-media .head.rnd.no-bot h3:first').text();
		  		var startdate = jQuery('#cnt-media .block.col.lft.rnd .info.clearfix dd:eq(2)').text();;
		  		var fullurl = window.document.URL;
		  		
				fb_connect_stream_publish(article_id, article_ean, format, startdate, fullurl);
		  	
			  	return false;
		  	});
		}
		
		// Twitter implementation
		if(jQuery('#post_twitter').length){
			jQuery('#post_twitter').click(function() {
				var url = window.location+"";
				// url = escape(url);
				// url = url.replace(/\//g,'%3F');
				var article_name = jQuery('#cnt-media .block.col.lft.rnd dd:eq(0)').text().replace(/ /g,'+');
				// article_name = article_name.replace(/\r/g,'').replace(/\n/g,'').replace(/ /g,'+');
				//console.log(article_name);
				window.open('http://www.twitter.com/share?url='+url+'&text='+article_name+'&via=dvdliebhaber','twitter-popup','width=590,height=200,scrollbars=yes,toolbar=no,status=no,resizable=yes,menubar=no,location=no,directories=no,top=100,left=100');
			});
		}
		getVersions((location+"").match(/[0-9]+/g)[0]);
		//EqualContainers();
}        
var images_loaded=0;    
$.fn.LoadArticle = function(article_id) {
	var context = jQuery(this);
	var aid = parseInt(article_id);
	var url = (typeof user_loggedin == "undefined") ? "/ceemes/?article/show/"+aid+"/layout=splendid_article_detail_view" : "/ceemes/?article/show/"+aid+"/layout=splendid_article_detail_view_press";
	var target_html = '';
	var target_obj = null;
	
	// Show loader
	jQuery('.MainArea').html('<img id="loading_image" src="/ceemes/webfile/show/2425" alt="loading" style="width:32px;height:32px;display:block;margin:60px auto;"/>');
	
	// Get
	jQuery.get(url, function(html) {
		target_html = jQuery(html).find('#cnt-media').outerHTML();
		
		jQuery('#loading_image').remove();
		
		jQuery('.MainArea').html(target_html);
		
                /*setTimeout("equalHeight(jQuery('.equal'))", 333);*/
		
		var usdate=jQuery('.date').text();
		var x = usdate.split(' ');
		var d = x[0].split('-');
		jQuery('.date').text(d[2]+"."+d[1]+"."+d[0]);
		
		jQuery('a.thickbox').each(function(){ jQuery(this).append('<p />');}); // zoom icon
		if(jQuery('#trailer').attr('title') == "")
			jQuery('#trailer').attr('title','/img/trailer_kf/'+jQuery(jQuery('.block.lft dl.info.clearfix dd')[1]).text()+'_KF_0_00_06.jpg');
		if(jQuery('#trailer_exists').text() == "200")
			InitTrailerplayer();
		else
			jQuery('#trailer').remove();
			
		// ExtendedSearch: Genre Dropdown
		if(jQuery('select[name="category[1]"]').length > 0)
			jQuery('select[name="category[1]"]').loadAllGenres();
		// Fixup search target
		jQuery('input[type=hidden][name=destination]').not('[value*=amasia]').each(function(){
			jQuery(this).attr('value',jQuery(this).attr('value').replace(':MainArea',':MainArea:amasia'));
		});
		jQuery('form input[value=article]').after('<input type="hidden" name="ex_bamasia" value="1"/>');
	
		
		if(jQuery('.gal a.state200 img,.col.lft img.pic').length > 0) {
			jQuery('.gal a.state200 img,.col.lft img.pic').load(function(){
				images_loaded++;
				if(images_loaded == jQuery('.gal a.state200 img,.col.lft img.pic').length){
					jQuery('.gal a.state200 img').each(function(){
						if(jQuery(this).width()<jQuery(this).height()){
							jQuery(this).css('margin','0 24px');
							jQuery(this).siblings('p').css('right','24px');
						}
					});
					
					EqualContainers();
				}
			});
		} else {
			EqualContainers();
		}
		
		jQuery('.state404').remove();
		InitColorboxes();
		Search2SlideEffect();
		// Fixup fsk searchvalues
		jQuery('select[name=fsk] option').each(function(){
			if(jQuery(this).attr('value')!="")
				jQuery(this).attr('value',"\""+jQuery(this).attr('value')+"\"");
		});
			
		// Facebook implementation
		if(jQuery('#post_facebook').length) {
		  	jQuery('#post_facebook').click(function() {
		  		var article_id = jQuery.url.param('article');
		  		var article_ean = jQuery('#cnt-media .block.col.lft.rnd .info.clearfix dd:eq(1)').text();
		  		var format = jQuery('#cnt-media .head.rnd.no-bot h3:first').text();
		  		var startdate = jQuery('#cnt-media .block.col.lft.rnd .info.clearfix dd:eq(2)').text();;
		  		var fullurl = window.document.URL;
		  		
				fb_connect_stream_publish(article_id, article_ean, format, startdate, fullurl);
		  	
			  	return false;
		  	});
		}	
		
		// Twitter implementation
		if(jQuery('#post_twitter').length){
			jQuery('#post_twitter').click(function() {
				var url = window.location+"";
				// url = escape(url);
				// url = url.replace(/\//g,'%3F');
				var article_name = jQuery('#cnt-media .block.col.lft.rnd dd:eq(0)').text().replace(/ /g,'+');
				// article_name = article_name.replace(/\r/g,'').replace(/\n/g,'').replace(/ /g,'+');
				//console.log(article_name);
				window.open('http://www.twitter.com/share?url='+url+'&text='+article_name+'&via=dvdliebhaber','twitter-popup','width=590,height=200,scrollbars=yes,toolbar=no,status=no,resizable=yes,menubar=no,location=no,directories=no,top=100,left=100');
			});
		}
	});
};

/* ##### Gets the names of all subcategories and puts them into the genre dropdown ##### */
$.fn.loadAllGenres = function() {
	// DropDown Variable
	var DropDown = jQuery(this);

	// Fire the ajax
	jQuery.get('/ceemes/articlecategory/xmllist/', function(data) {
		// Shall contain the sub categories of '/DVD/'
		var categories_objs = new Array(); 
		// Shall contain the sub categories of '/DVD/*/'
		var subcategories_objs = new Array(); 
		// Shall contain the final sub categories-names of '/DVD/*/'
		var subcategories = new Array(); 
		
		/* ### Get all categories_objs ### */
		// First off, we have to fetch all parent-elements
		var parents = jQuery(data).find('parent');
		
		// Now iterate the parent-elements and check for children of the category '123' which is '/DVD/'
		parents.each(function() {
			if(jQuery(this).text() == 123)
				categories_objs.unshift(jQuery(this).parent());
		});
		
		/* ### Get all subcategories_objs of the categories_objs fetched above ### */
		// Hold the cat_id of a main-category
		var cat_id = -1;
		
		// Iterate the categories_objs from above
		jQuery.each(categories_objs, function() {
			// Get the idx of the current category
			cat_id = parseInt(jQuery(this).find('idx').text());
			
			// Iterate the parents
			jQuery.each(parents,function() {
				// Compare the current parent-id with the current category-id
				if(parseInt(jQuery(this).text()) == cat_id) {
					// IDX and Parent-ID matches, this is a subcategory like '/DVD/Spielfilm/Erotik'
					var subcategory = jQuery(this).parent();
					
					// Add it to the subcategories_objs collection
					subcategories_objs.unshift(subcategory);
				}
			});
		});
	
		/* ### MAIN ### */
		jQuery.each(subcategories_objs, function() {
			// A name like '/DVD/Spielfilm/Erotik/'
			var subcat_name = jQuery(this).find('name').text();
			
			// Split the name by '/'
			var subcat_name_parts = subcat_name.split('/');
			
			// Determinate the subcategory name
			var final_subcat_name = subcat_name_parts[subcat_name_parts.length-2];
			
			// Add it to the subcategories
			subcategories.unshift(final_subcat_name);
		});
		
		// Sort the subcategories
		subcategories.sort();
		
		// Unique the subcategories
		subcategories.unique();
		
		// Lets prepare the genre dropdown by iterating the subcategories and adding an option for each of them
		jQuery(DropDown).html('');
		jQuery(DropDown).append('<option value="">Alle Genre</option>');
		jQuery.each(subcategories, function() {
			var name = this;
			jQuery(DropDown).append('<option value="'+name+'">'+name+'</option>');
		});
	});
};

/*################################ PLUGIN END ################################*/
function GetRandom( min, max ) {
	if( min > max ) {
		return( -1 );
	}
	if( min == max ) {
		return( min );
	}
 
        return( min + parseInt( Math.random() * ( max-min+1 ) ) );
}
function getURLMonth(m){
	var MonthArray = Array("januar","februar","maerz","april","mai","juni","juli","august","september","oktober","november","dezember");
	return MonthArray[m];
}

function GetNiceDate(date){
	var x = date.split(' ');
	var d = x[0].split('-');
	return d[2]+"."+d[1]+"."+d[0];
};

function InitColorboxes() {
	// Initialise the colorboxes
	jQuery('a.thickbox').colorbox({
 		transition:'elastic',
 		opacity:0.85,
 		slideshow:true,
 		slideshowAuto:false,
 		current: '{current} von {total}',
 		maxWidth:'100%',
 		maxHeight:'100%'
	});
};
function Search2SlideEffect(){
	jQuery('#search-more2-toggleBTN').toggle(function(){
			if(jQuery('#main-bot .block.dbl').length)
				jQuery('#main-bot .block.dbl .inner:last').height(parseInt(jQuery('#main-bot .block.dbl .inner:last').height())+347);
			else{
				jQuery('#main-bot .block.mid .inner:last').height(parseInt(jQuery('#main-bot .block.mid .inner:last').height())+347);
				jQuery('#main-bot .block.lft .inner:last').height(parseInt(jQuery('#main-bot .block.lft .inner:last').height())+347);
			}
			
			jQuery('#search-more2').slideDown();
			return false;
		},
		function(){
			jQuery('#search-more2').slideUp(400,function(){
				if(jQuery('#main-bot .block.dbl').length)
					jQuery('#main-bot .block.dbl .inner:last').height(parseInt(jQuery('#main-bot .block.dbl .inner:last').height())-347);
				else{
					jQuery('#main-bot .block.mid .inner:last').height(parseInt(jQuery('#main-bot .block.mid .inner:last').height())-347);
					jQuery('#main-bot .block.lft .inner:last').height(parseInt(jQuery('#main-bot .block.lft .inner:last').height())-347);
				}	
			});
			return false;
	});
}
function InitTrailerplayer(){
	$.fn.media.defaults.flvPlayer = '/trailer_web/nonverblaster.swf';

	jQuery('a[href$="flv"], a[href$="mov"], a[href$="mp4"], a[href*="youtube.com/v/"]').each(function(){
	var mov = $(this).attr('href');
	var keyframe = $(this).attr('title');
	var add = 'qkt';
	
	var options = {
		preferMeta: false,
		width: 468,
		height: 300,
		autoplay: true,
		bgColor: '#000000',
		caption: false,
		attrs: {allowfullscreen:'true', wmode:'transparent'},
		params: {allowfullscreen:'true'}
	};
	if (mov.search(/youtube/)>0){
		options = $.extend(options,{
			src: mov+'&fs=1&fmt=6', // fmt: 18=mp4, 6=flv
			type: 'swf'
		});
		add = 'you';
	}
	if (mov.search(/\.flv/)>0){
		options = $.extend(options,{
			flashvars: {
				videoURL: dir_publ+mov,
				teaserURL: keyframe,
				controlColor: '0xffffff',
				controlBackColor: '0x000000'
			}
		});
		add = 'flv';
	}
	if (jQuery('.col.mid').length){
		options = $.extend(options,{
			width: 394,
			height: 246
		});
	}
	jQuery(this).addClass('mov '+add).media(options);
});
};

function getMonth(m) {
	switch(m) {
		case '01': return 'Januar';
		case '02': return 'Februar';
		case '03': return 'März';
		case '04': return 'April';
		case '05': return 'Mai';
		case '06': return 'Juni';
		case '07': return 'Juli';
		case '08': return 'August';
		case '09': return 'September';
		case '10': return 'Oktober';
		case '11': return 'November';
		case '12': return 'Dezember';
		default: return '';
	}
}

function EqualContainers(){
		var sidebarHeight=0;
		
		jQuery('#main-bot .rgt:visible').each(function(){
			sidebarHeight+=parseInt(jQuery(this).css('height').replace(' px',''));
		});
		if(jQuery('#main-bot .block.dbl.news').length){
			var mainHeight = parseInt(jQuery('#main-bot .block.dbl').css('height').replace(' px',''));
			jQuery('#main-bot .rgt:visible:last .inner').css('height',parseInt(jQuery('#main-bot .rgt:visible:last .inner').css('height'))-117);
		}else if(jQuery('#main-bot .MainArea .block.mid').length){
			if(jQuery('#main-bot .rgt:visible').length==3)
				sidebarHeight=sidebarHeight+10;

				
			var mainHeight = parseInt(jQuery('#main-bot .MainArea .block.mid').height());
			var leftHeight = parseInt(jQuery('#main-bot .MainArea .block.lft').height());
			if(sidebarHeight>mainHeight && sidebarHeight>leftHeight){
				jQuery('#main-bot .MainArea .block.mid .inner').css('height',parseInt(jQuery('#main-bot .MainArea .block.mid .inner').css('height').replace(' px',''))+(sidebarHeight-mainHeight));
				jQuery('#main-bot .MainArea .block.lft .inner').css('height',(parseInt(jQuery('#main-bot .MainArea .block.lft .inner').css('height').replace(' px','')))+(sidebarHeight-leftHeight));
			}else if(mainHeight>sidebarHeight && mainHeight>leftHeight){
				jQuery('#main-bot .MainArea .block.lft .inner').css('height',(parseInt(jQuery('#main-bot .MainArea .block.lft .inner').css('height').replace(' px','')))+(mainHeight-leftHeight));
				jQuery('#main-bot .MainArea .rgt:visible:eq(1) .inner').css('height',(parseInt(jQuery('#main-bot .MainArea .rgt:visible:eq(1) .inner').css('height').replace(' px',''))-10)+(mainHeight-sidebarHeight));
			}else if(leftHeight>mainHeight && leftHeight>sidebarHeight){
				jQuery('#main-bot .MainArea .block.mid .inner').css('height',parseInt(jQuery('#main-bot .MainArea .block.mid .inner').css('height').replace(' px',''))+(leftHeight-mainHeight));
				jQuery('#main-bot .MainArea .rgt:visible:eq(1) .inner').css('height',(parseInt(jQuery('#main-bot .MainArea .rgt:visible:eq(1) .inner').css('height').replace(' px',''))-10)+(leftHeight-sidebarHeight));
			}
		}else{
			if(jQuery('#main-bot .block.dbl').length){
				var mainHeight = parseInt(jQuery('#main-bot .block.dbl').css('height').replace(' px',''));
		
				if(sidebarHeight>mainHeight){
					jQuery('#main-bot .block.dbl .inner').css('height',parseInt(jQuery('#main-bot .block.dbl .inner').css('height').replace(' px',''))+10+(sidebarHeight-mainHeight));
				}else{
					jQuery('#main-bot .rgt:visible:last .inner').css('height',(parseInt(jQuery('#main-bot .rgt:last .inner').css('height').replace(' px',''))-10)+(mainHeight-sidebarHeight));
				}
			}
		}
}


/*    
    $.fn.Splendid.News = function(o) { };
    
    $.fn.Splendid.MiniNews = function(o) { };
*/

/* ########## FACEBOOK APP INITIALISATION, Domain Related AppIDs -_- ########## */

function InitFacebook(){
	if(typeof(FB)!=='undefined') {
		var facebook_appid_wwwde_amasia = 'e30943fb33f82a2a9dd39fa82b338556';
		var facebook_appid_de_amasia = '6e29cd5dcf8d0f3617297010323e6624';
		
		// On the www-subdomain
		if(document.URL.search(/www./) != -1) {
			FB.init(facebook_appid_wwwde_amasia);
		} 		
		// Not on the www-subdomain
		else {
			FB.init(facebook_appid_de_amasia);
		}
	}
}
/* Facebook Post Function - Splendid related! See AmasiaJS for Amasia related version */
function fb_connect_stream_publish(article_id, article_ean, format, startdate, fullurl) {

	content_short = jQuery('#cnt-media .block.col.mid.rnd .inhalt_kurz').text();
	article_name = jQuery('#cnt-media .block.col.lft.rnd dd:eq(0)').text();
	
	var message = 'Neue ' + format + ' ' + article_name + ' jetzt bei Splendid Film!'; 

	var attachment = { 
	    'name': article_name, 
	    'href': fullurl + '/article/show/' + article_id, 
	    'caption': format + ' ab ' +startdate+' im Handel!', 
	    'description': content_short, 
	    'media': [{ 'type': 'image', 'src': 'http://www.wvg.com/img/dvd_th/' + article_ean + '.jpg', 'href': fullurl + '/article/show/' + article_id}]
	}; 
	var action_links = [{ 'text': 'Jetzt anschauen!', href: fullurl + '/article/show/' + article_id }];
	var user_message_prompt = 'Neue ' + format + ' ' + article_name + ' jetzt bei Splendid Film';
	return FB.Connect.streamPublish(message, attachment, action_links, null, user_message_prompt);
} 
// ############################ MAIN START : DOCUMENT READY BELOW
jQuery(function(){
var loadingArticlePreview = 0;
	// navigation new and soon releases links	
	var nr_date_from = new Date();
	var nr_date_to = new Date();
	var sr_date_from = new Date();
	var sr_date_to = new Date();

	nr_date_from.setDate(nr_date_from.getDate()-70);
	
	jQuery('.new_releases').each(function(){
		if(!jQuery(this).hasClass('ajaxurl')){
		jQuery(this).attr('href',jQuery(this).attr('href').replace("startdate[0]","startdate[0]="+nr_date_from.getDate()+"."+(nr_date_from.getMonth()+1)+"."+nr_date_from.getFullYear()));
		jQuery(this).attr('href',jQuery(this).attr('href').replace("startdate[2]","startdate[2]="+nr_date_to.getDate()+"."+(nr_date_to.getMonth()+1)+"."+nr_date_to.getFullYear()));
		}else{
		jQuery(this).text(jQuery(this).text().replace("startdate[0]","startdate[0]="+nr_date_from.getDate()+"."+(nr_date_from.getMonth()+1)+"."+nr_date_from.getFullYear()));
		jQuery(this).text(jQuery(this).text().replace("startdate[2]","startdate[2]="+nr_date_to.getDate()+"."+(nr_date_to.getMonth()+1)+"."+nr_date_to.getFullYear()));
		}
	});
	
	sr_date_from.setDate(sr_date_from.getDate()+1);

	jQuery('.soon_releases').each(function(){
		jQuery(this).attr('href',jQuery(this).attr('href').replace("startdate[0]","startdate[0]="+sr_date_from.getDate()+"."+(sr_date_from.getMonth()+1)+"."+sr_date_from.getFullYear()));
		jQuery(this).attr('href',jQuery(this).attr('href').replace("startdate[2]","startdate[2]=31.12.2030"));
	});
	
	jQuery('.ajaxurl.ajax_soon').each(function(index){ 
		jQuery(this).text(jQuery(this).text().replace("startdate[0]","startdate[0]="+sr_date_from.getDate()+"."+(sr_date_from.getMonth()+1)+"."+sr_date_from.getFullYear()));
		jQuery(this).text(jQuery(this).text().replace("startdate[2]","startdate[2]=31.12.2030"));
	});
	
	jQuery('.ajaxurl.ajax_available').each(function(index){ 
		jQuery(this).text(jQuery(this).text().replace("startdate[0]","startdate[0]="+nr_date_from.getDate()+"."+(nr_date_from.getMonth()+1)+"."+nr_date_from.getFullYear()));
		jQuery(this).text(jQuery(this).text().replace("startdate[2]","startdate[2]="+nr_date_to.getDate()+"."+(nr_date_to.getMonth()+1)+"."+nr_date_to.getFullYear()));
	});

	// Doin amasia customization
	jQuery(jQuery('#navx ul li')[1]).remove();
	jQuery(jQuery('#navx ul li')[1]).remove();
	jQuery(jQuery('#footer ul li')[1]).remove();
	jQuery(jQuery('#footer ul li')[1]).remove();
	jQuery('div.elm.rnd a[href*=splendid_article]').each(function(){
		jQuery(this).attr('href',jQuery(this).attr('href').replace('splendid_article','splendid_article:amasia'));
	});
	jQuery('.5ColSlider').each(function(){
		jQuery(this).attr('lang',jQuery(this).attr('lang').replace('&destination','&ex_bamasia=1&destination'));
	});
	jQuery('#navx ul li a[href*=page],#footer ul li a[href*=page]').each(function(){
		jQuery(this).attr('href',jQuery(this).attr('href')+":amasia");
	});
	jQuery('#navx ul li a[href*=":MainArea"],#footer ul li a[href*=":MainArea"]').each(function(){
		jQuery(this).attr("href",jQuery(this).attr("href").replace(":MainArea",":MainArea:amasia").replace("&label","&ex_bamasia=1&label"));
	});
	jQuery('.ajaxurl').each(function(){
		jQuery(this).text(jQuery(this).text().replace("&label","&ex_bamasia=1&label"));
	});
	jQuery('input[type=hidden][name=destination]').not('[value*=amasia]').each(function(){
		jQuery(this).attr('value',jQuery(this).attr('value').replace(':MainArea',':MainArea:amasia'));
	});
	jQuery('.archiv a').each(function(){
		jQuery(this).attr('href',jQuery(this).attr('href')+":amasia");
	});
	jQuery('form input[value=article]').after('<input type="hidden" name="ex_bamasia" value="1"/>');
		
	jQuery('.newsbar .elm a').each(function(){
		jQuery(this).attr('href',jQuery(this).attr('href').replace('#',':amasia#'));
	});
	// Choose an ad to display
	if(jQuery('.bullet').length>1){
		var ad_index = GetRandom(0,1);
		jQuery(jQuery('.bullet')[ad_index]).show();
	}
	// convert searchresult dates
	if(jQuery('.with_date').length){
		jQuery('.with_date .date').each(function(){
			jQuery(this).text(GetNiceDate(jQuery(this).text()));
			jQuery(this).show();
		});
	}
	
	// Teaser preparation: Remove the splendid element
	if(jQuery('#teaser .content .splendid').length) {
		jQuery('#teaser .content .splendid,#teaser .content .splendid_nl').remove();
	}
	
	// Apply Splendid functions to elements
	if(jQuery('#teaser').length)
		if(jQuery('#teaser').attr('lang')!='/ceemes/')
			jQuery('#teaser').TopSlider(jQuery('#teaser').attr('lang').replace('349','419'));
			
	if(jQuery('.preview').length){
		jQuery('.preview').each(function(){
			if(jQuery(this).find('span.ajaxurl').text()!='/ceemes/'){
				loadingArticlePreview = 1;
				jQuery(this).ArticlePreview(jQuery(this).find('span.ajaxurl').text(), jQuery(this).find('.ajax_available').length);
			}		
		});	
		jQuery('div.nav-page span.currentPage').html('<a class="set">'+jQuery('div.nav-page span.currentPage').text()+'</a>');
	}	
	if(jQuery('.4ColSlider').length){
		jQuery('.4ColSlider').each(function(){
			if(jQuery(this).find('span.ajaxurl').text()!='/ceemes/')
				jQuery(this).Slider4Col(jQuery(this).find('span.ajaxurl').text());
		});
	}
	if(jQuery('.5ColSlider').length){
		jQuery('.5ColSlider').each(function(){
			if(jQuery(this).attr('lang')!='/ceemes/')
				jQuery(this).Slider5Col(jQuery(this).attr('lang'));
		});
	}
	if(jQuery('.5ColPager').length){
		if(jQuery('.5ColPager').find('span.ajaxurl').text()!='/ceemes/'){
			jQuery('.5ColPager').Pager5Col(jQuery('.5ColPager').find('span.ajaxurl').text());
		}
	}
	
	// Search functions		
	if(jQuery('.nav-alpha').length && jQuery('.5ColPager').length) {
		jQuery('.nav-alpha a').each(function(){
				jQuery(this).click(function(){
					var search_url = jQuery('.nav-alpha .ajaxurl').text();
					if(!jQuery(this).hasClass('all') && !jQuery(this).hasClass('digit'))
						search_url= search_url+"&starts_with="+jQuery(this).text();
					else if(jQuery(this).hasClass('digit'))
						search_url= search_url+"&starts_with=digit";
					jQuery('.nav-alpha a').removeClass('set');
					jQuery(this).addClass('set');
					jQuery('.5ColPager').Pager5Col(search_url);
					return false;
				})
			});
	}
	if(jQuery('#search-more').length && jQuery('.5ColPager').length){
		jQuery('#search-more input[type=submit]').remove();
		jQuery('#search-more a.btn').click(function(){
			if(jQuery('.nav-alpha').length)
				var searchmore_str = jQuery('.nav-alpha .ajaxurl').text();
			else
				var searchmore_str = "";
			jQuery('#search-more select,#search-more input').each(function(){
				searchmore_str= searchmore_str + "&" + jQuery(this).attr('name') + "=" + jQuery(this).val();
			});
			searchmore_str=searchmore_str.replace('&destination','&ex_bamasia=1&destination');
			jQuery('.5ColPager').Pager5Col(searchmore_str);
		});
		jQuery('#search input[type=submit]').remove();
		jQuery('#search a.search-btn').click(function() {
			var search_str = "";
			jQuery('#search input').each(function() {
				search_str= search_str + "&" + jQuery(this).attr('name') + "=" + jQuery(this).val();
			});
			search_str=search_str.replace('&destination','&ex_bamasia=1&destination');
			jQuery('.5ColPager').Pager5Col(search_str);
		});
		// Prevent form from beeing submitted natively by pressing return
		jQuery('form#search').submit(function(){
			jQuery('#search a.search-btn').click();
			return false;
		});
	}
	if(jQuery('.search_result_list').length) {
		if(jQuery('.search_result_list .elm').length) {
			for(var x = 1;x<jQuery('.search_result_list .elm').length/4;x++)
				jQuery(jQuery('.search_result_list .elm')[x*4-1]).after('<br style="clear:both"/>');
		} else if(jQuery.url.param("action")&&!jQuery('.review_article').length) {
			jQuery('.search_result_list').html('<span style="line-height:0px">Leider erzielte Ihre Suche keine Ergebnisse.</span>');
		}
	}
	if(jQuery('div.news').length&&jQuery('div.archiv.equal')){
		jQuery('div.archiv.equal').height(jQuery('div.rnd.news').height()-76);
		jQuery('.archiv a').each(function(){
		    var news_loc = window.location+"";
		    if(news_loc.search(jQuery(this).attr('href')) != -1)
		        jQuery(this).addClass('set');
		});
	}
	// article detail view function
	if(jQuery.url.param("article") !== undefined) {
		jQuery('#main-bot').LoadArticle(jQuery.url.param("article"));
	}
	if(jQuery('.news').length){
		DaySort(jQuery('.news>.col.rnd'));

		jQuery('.news>.col.rnd .head.rnd.no-bot').hide();		
		jQuery('.news>.col.rnd .head.rnd.no-bot:first').show();		
	}
	// navigation highlightning
	jQuery('#navx li a[href$='+jQuery('.pagename').text()+'],#footer .nav-foot ul li a[href$='+jQuery('.pagename').text()+']').addClass('set');
	if(!jQuery('#navx li a.set').length){
		var loc = window.location+"";
		var headline;
		loc= loc.replace(">","%3E");
		loc= loc.replace("<","%3C");
		headline = loc.split('#');
		jQuery('#navx ul li a,#footer .nav-foot ul li a').each(function(){
			if(jQuery(this).attr('href')==loc)
				jQuery(this).addClass('set');
		});
		if(headline.length == 2)
			jQuery('.noslider_2col div h3').text(decodeURI(headline[1]));
		
	}
	if(jQuery('#navx .set').parents('ul.nav-sub').length){
		var parentnode = jQuery('#navx .set').parents('ul.nav-sub').siblings('a');
		jQuery(parentnode).addClass('set');
		jQuery('#footer .nav-foot ul li a').each(function(){
			if(jQuery(this).attr('href')==jQuery(parentnode).attr('href'))
				jQuery(this).addClass('set');
		});
	}

	// load mininews
	jQuery('.ajax_news').LoadMiniNews();

	if(!(typeof user_loggedin == "undefined"))
		jQuery('#navx ul li a[href$=splendid_press]').attr('href','/ceemes//page/show/splendid_press_loggedin');
	// create nice dates again
	jQuery('.review_article .date').each(function(){
    			jQuery(this).text(GetNiceDate(jQuery(this).text()));
    			jQuery(this).show();
    		});
	// remove images that are not set
	if(jQuery('div.stills').length)
		jQuery('div.stills img[src$=blank.gif/]').parents('a').remove();
		
	// setup colorboxes	
	InitColorboxes();
	
	// setup trailer if needed
	if(jQuery('#trailer').length)
		InitTrailerplayer();
	// Fixup fsk searchvalues
	jQuery('select[name=fsk] option').each(function(){
		if(jQuery(this).attr('value')!="")
			jQuery(this).attr('value',"\""+jQuery(this).attr('value')+"\"");
	});	
	// ExtendedSearch: Genre Dropdown
	if(jQuery('select[name="category[1]"]').length > 0)
		jQuery('select[name="category[1]"]').loadAllGenres();
	
	// Fix heights on pages with search2 container
	if(jQuery('.search2').length>0 && loadingArticlePreview != 1){
		EqualContainers();
	}
	
	// Adding toggle event to search2 containers
	if(jQuery('.search2').length>0)
		Search2SlideEffect();

	InitFacebook();

	if(jQuery('.articledetailview').length){
		ModifyArticle();
		EqualContainers();
	}
	FixSteelbooks();
});
