jQuery.noConflict();
jQuery(document).ready(function($){
  
  
  
  
  $('body').addClass('js');
  
  var fb = $('<div>', {'class': 'sharebuttons clearfix'}).html('<div class="tw"><a href="http://twitter.com/share" class="twitter-share-button" data-count="vertical">Tweet</a></div><div class="fb"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FB%C3%BCrgerstiftung-Duisburg%2F101269816598131&amp;layout=box_count&amp;show_faces=false&amp;width=200&amp;action=like&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:65px;" allowTransparency="true"></iframe></div>').prependTo('#social');
  
  
	$('#focus_sozial').hover(function() {
	  $('#fce_saeulen_startseite').removeClass();
	  $('#fce_saeulen_startseite').addClass("fce_saeulen_status_1");
	});
	$('#focus_bildung').hover(function() {
	  $('#fce_saeulen_startseite').removeClass();
	  $('#fce_saeulen_startseite').addClass("fce_saeulen_status_2");
	});
	$('#focus_verantwortung').hover(function() {
	  $('#fce_saeulen_startseite').removeClass();
	  $('#fce_saeulen_startseite').addClass("fce_saeulen_status_3");
	});
	
	$('.fce_keyvisual_container').tabbed_background();
	$('.content_h_slide').h_slider();
	
	$.sharebox.init($('#share-button'));
	$('#share-button').sharebox();
	
});

(function($) {
	$.fn.h_slider = function(o){
		is_home = ($('#wrapper')[0]) ? true : false;
		return this.each(function(){
			var $this = $(this).addClass('content_h_slide_enabled');
			$this.find('.csc-textpic-imagewrap, .csc-textpic-imagecolumn').removeAttr('style');
			var $items = $this.find('.csc-textpic-imagecolumn:first')
				.removeAttr('class')
				.addClass('items')
				.find('dl')
				.removeAttr('class')
				.removeAttr('style')
				.addClass('item');
				
			var api_scrollable =  $this.find('.csc-textpic-imagewrap:first')
				.removeAttr('class')
				.addClass('scrollable')
				.unwrap()
				.unwrap();
				
			if( (!is_home && $items.length > 4) || ( is_home && $items.length > 5)){
				api_scrollable = api_scrollable
				.before('<a class="nav prev"/>')
				.after('<a class="nav next"/>')
				.scrollable_fallback({clickable: false}).circular().data('scrollable_fallback');
			}else{
				$this.addClass('content_h_slide_nav_removed');
			}
			
			
		});
	};
	
	$.fn.tabbed_background = function(o){
		return this.each(function(){
			var el = $(this).wrap('<div class="fce_tabbed_background_enabled"/>');
			
			//prepend tabs
			var str_tabs = '<ul class="tabs clearfix">';
			el.find('> div .csc-header').each(function(){
				var classes = $(this).parent().attr('class').split(' ').slice(1);
			  var title = $(this).text();
			  str_tabs += '<li><a href="#' + title.toLowerCase().replace(/[^a-zäöüß0-9]+/g,'-') +'" class="'+classes+'">' + title + '</a></li>';
			});
			str_tabs += '</ul>';
			el.prepend(str_tabs);
			
			var tabs = el.find('.tabs a');
			el.parent().attr('class', 'fce_tabbed_background_enabled '+tabs.eq(0).attr('class'));
			
			//prepend backgrunds
			var bg = el.before('<div class="fce_keyvisual_backgrounds"><div class="items"></div></div>').parent().find('.fce_keyvisual_backgrounds .items');
			
			var imgs = '';
			el.find('.csc-textpic-imagewrap').each(function(){
			  var imgsrc = $(this).find('img').attr('src');
				$(this).remove();
			  imgs += '<div class="item"><img src="'+imgsrc+'" alt=""></img></div>';
			});
			bg.html(imgs);
			
			var api_bg = bg.parent().scrollable({ vertical: true, api: true });

			var api_tabs = el.find('.tabs').tabs(el.find('> div'), {rotate: true}).slideshow({autoplay: true, interval: 6000}).data('tabs');
			api_tabs.onBeforeClick(function(info, index) {
				api_bg.seekTo(index);
				var current_class = tabs.eq(index).attr('class');
				el.parent().attr('class', 'fce_tabbed_background_enabled '+current_class);
			});
			
		});
	};
})(jQuery);


