TFT.Ext.BCN = {};

TFT.Ext.BCN.oSelectPanels = [];
TFT.Ext.BCN.SelectPanel  = function(sSelectSelector, sContainerSelector) {
	$("."+sSelectSelector).click(function() {
		TFT.Ext.BCN.SelectPanel.toggle_state(sSelectSelector, sContainerSelector);
	});
}
TFT.Ext.BCN.SelectPanel.toggle_state  = function(sSelectSelector, sContainerSelector) {
	$("."+sSelectSelector).hasClass('collapsed') ? TFT.Ext.BCN.SelectPanel.list_expand(sSelectSelector, sContainerSelector) : TFT.Ext.BCN.SelectPanel.list_collapse(sSelectSelector, sContainerSelector);
};
TFT.Ext.BCN.SelectPanel.list_expand  = function(sSelectSelector, sContainerSelector) {
	$("."+sContainerSelector).show();
	$("."+sSelectSelector).removeClass('collapsed').addClass('expanded');
	$("."+sContainerSelector).bind ( 'mouseleave', function(){TFT.Ext.BCN.SelectPanel.list_collapse(sSelectSelector, sContainerSelector)} );
};
TFT.Ext.BCN.SelectPanel.list_collapse  = function(sSelectSelector, sContainerSelector) {
	$("."+sContainerSelector).hide();
	$("."+sSelectSelector).removeClass('expanded').addClass('collapsed');
};

TFT.Ext.BCN.Util = {};
TFT.Ext.BCN.MTTFTBCNReadershipProfile = {};

TFT.Ext.BCN.Util.LoadAjax = function(sURL, sSpotName, sMethod, sJsCallback) {
  var sSep = '?';
  var patt1=/\?/g;
  if (sURL.match(patt1) == null) sSep = '?';
  else sSep = '&';
  var sTargetURL = sURL + sSep + encodeURIComponent("module_fnc["+sSpotName+"]") + "=ExecuteAjaxCall&_fnc="+encodeURIComponent(sMethod);

  $.ajax({
     url: sTargetURL,
     processData: false,
     dataType:  'json',
     success: sJsCallback,
     type: 'POST'
   });
  return false;
}

TFT.Ext.BCN.MTTFTBCNReadershipProfile.ShowFullProfile = function(data, responseMessage) {
  $('#fullprofile-'+data.sSpotName).html($(data.sResult));
}

TFT.Ext.BCN.SelectChangeHref = function(sSelector){
	$(sSelector).change(function () {
		$(sSelector+" option:selected").each(function () {
			if($(this).attr('value')!=''){
				location.href = $(this).attr('value');
			}
		});
	});
}

TFT.Ext.BCN.oCollapsebox = {};
TFT.Ext.BCN.oCollapsebox.collapsebox = function () {
	$(".collapsebox .collapseheading:first").addClass("active");
	$(".collapsebox .collapseContainer").hide();
	$(".collapsebox .collapseContainer:first").show();
	$(".collapsebox .collapseview:first").hide();
	$(".collapsebox .collapseheading").click(function(){
		bDoOpen = ($(this).hasClass('active')) ? false : true;	
		$(".collapsebox .active").each(function(){
			$(this).next(".collapseContainer").slideToggle().next(".collapseview").show();
			$(this).removeClass('active');
		});
		if (bDoOpen){
			$(this).addClass('active');
			$(this).next(".collapseContainer").slideToggle().next(".collapseview").hide();
		}
	});
}

/*
 *  .textcontainerbox .collapsebox pager callback
 */
TFT.Ext.BCN.LoadArticleCollectionReturn = function(data, responseMessage) {
  var oContainer = $('.textcontainerbox');
  var oTmp = $(data.sResult);
  oContainer.replaceWith(oTmp);
  //  we load collapsebox in .textcontainerbox async, so we call collapsebox() again.
  TFT.Ext.BCN.oCollapsebox.collapsebox();
}


$(document).ready(function(){
	
	TFT.Ext.BCN.oCollapsebox.collapsebox();
	
	if ($('.bildergallery_upper').length != 0) {
		$(function(){
			$('.bildergallery_upper').loopedSlider({
				autoStart: 0,
				restart: 0,
				containerClick: false
			});
		});
	}
	if ($('.bildergallery_lower').length != 0) {
		$(function(){
			$('.bildergallery_lower').loopedSlider({
				autoStart: 0,
				restart: 0,
				containerClick: false
			});
		});
	}
	if ($('.seitengalerie').length != 0) {
		$(function(){
			$('.seitengalerie').loopedSlider({
				autoStart: 0,
				restart: 0,
				containerClick: false
			});
		});
	}
	
	if ($('#slidingpanel').length != 0) {
		$(function(){
			$('#slidingpanel').loopedSlider({
				autoStart: 0,
				restart: 0,
				slidespeed: 750,
				containerClick: false
			});
		});
		
	}
	
	if ($('#presenterslide').length != 0) {
		$('#presenterslide').loopedSlider({
			autoStart: 0,
			restart: 0,
			slidespeed: 750,
			containerClick: false,
			extendFunc: true
		});
		$('.presenterlink').each(function(){
			$(this).click(function() {
				window.location.href=$(this).attr('href');
			});
		});
	}
	
	if ($('.postbox .container h3').length != 0) {
		$('.postbox .container h3').each(function(){
			$(this).hover(
				function () {
					$(this).css('color','#439fd4');
					Cufon.refresh();
				}, 
				function () {
					$(this).css('color','#000000');
					Cufon.refresh();
			});
		});
	}
	
	if ($('img.reflect_presenter').length != 0) {
		$("img.reflect_presenter").reflect({height:0.25});
	}
	if ($('img.reflect_magazine_profile').length != 0) {
		$("img.reflect_magazine_profile").reflect({height:0.34, opacity:0.3});
	}
	if ($('img.reflect_markenlaufband').length != 0) {
		$("img.reflect_markenlaufband").reflect({height:1, opacity:0.1});
	}
	if ($('img.reflect_combinationsbox').length != 0) {
		$("img.reflect_combinationsbox").reflect({height:0.25, opacity:0.15});
	}
	$(".markenlaufband").each(function(){
		
		$(this).hover(
			function () {
				$(this).find('span:first').css('display','none');
				$(this).find('span:last').css('display','block');
			}, 
			function () {
				$(this).find('span:first').css('display','block');
				$(this).find('span:last').css('display','none');
		});
	});
	if (jQuery.browser.msie) {
		$(".reflect_markenlaufband").each(function(){
				$(this).css('width','110px');
				$(this).css('height','146px');
				$(this).find('img:last').css('width','110px');
				$(this).find('img:last').css('height','73px');
		});
	}

	if ($("select#Zeitschriften").length != 0) {
		TFT.Ext.BCN.SelectChangeHref('select#Zeitschriften');
	}
	$("a.iconprint").live("click",function(){
		window.print();
		return false;
	});
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed:'slow',
		overlay_gallery: false,
		theme:'light_square',
		default_width: 610,
		default_height: 350,
		allow_resize : false
	});
});
