$.noConflict();
jQuery(document).ready(function($) {

	$("html").removeClass('no-js');
	$("html").addClass('js');
	
	
	// Forms handling

	/*$("form").submit(function(){
		var interessen  = $('#'+this.id+' input[name="Anrede"] option:selected').val();
		var anrede		= $('#'+this.id+' select[name="Anrede"] option:selected').val();
		var titel			= $('#'+this.id+' select[name="Titel"] option:selected').val();
		var vorname		= $('#'+this.id+' input[name="Vorname"]').val();
		var nachname	= $('#'+this.id+' input[name="Nachname"]').val();
		var email			= $('#'+this.id+' input[name="E-Mail-Adresse"]').val();
		
		var register_url = "https://randstad.m-cm.de/u/register.php?CID=129819559&f=826&p=2&a=r&SID=&el=&llid=&counted=&c=&interest[]=["+interessen+"]&inp_46=["+anrede+"]&inp_9=["+titel+"]&inp_1=["+vorname+"]&inp_2=["+nachname+"]&inp_3=["+email+"]";
		
		alert(register_url);
		
		
		
		$.get(register_url, function(data) {
		  alert('Load was performed.');
		});
		
		return false;
		
		
	});*/

	
	
	// fancybox
	if($(".iframe").length){
		$("a.iframe").fancybox();
	}
	
	// Pagination start
	if($('.pagination_start').length){
		
		var l = $('.pagination_start').length;
		
		$('.pagination_start').each(function(index) {
			var i = index;
			var page = i+1;
	  	$(this).addClass('start_page_'+ page);
		});
		
		$('.pagination_stop').each(function(index) {
			var i = index;
			var page = i+1;
	  	$(this).addClass('stop_page_'+ page);
			if(page == 1) {
				$('.start_page_'+page).nextUntil('.stop_page_'+page).wrapAll('<div id="page_'+page+'" class="page article_firstpage">');
			}
			else if(page == l){
				$('.start_page_'+page).nextUntil('.stop_page_'+page).wrapAll('<div id="page_'+page+'" class="page article_page">');
				var j = 0;
				//console.log($('.pagination_start')[2])
				
				for(j=$('.pagination_start').length-1;j>=0;j--) {
					var obj = $('.pagination_start')[j];
					var p = j+1;
					if(j == 0) $('.stop_page_'+l).after('<li class="pagi_navi active"><span class="pagi_seite">Seite '+p+':</span> <span class="pagi_hlink">'+$(obj).text()+'</span></li>');
					else $('.stop_page_'+l).after('<li class="pagi_navi"><span class="pagi_seite">Seite '+p+':</span>  <span class="pagi_hlink">'+$(obj).text()+'</span></li>');
				}
						
				$('.stop_page_'+l).after('<h2 id="pagi_head">Übersicht zu diesem Artikel</h2>');
				$('.stop_page_'+l).after('<hr id="pagi_hr">');
				$('.pagi_navi').wrapAll('<ul id="pagilist">')
				
			}
			else {
				$('.start_page_'+page).nextUntil('.stop_page_'+page).wrapAll('<div id="page_'+page+'" class="page article_page">');
			}
			
		});
		
		$('#pagilist').after('<div id="pagercontainer"><a href="#" class="prev">&laquo;</a> <span id="pager">Seite 1/'+l+'</span> <a href="#" class="next active">&raquo;</a></div><div id="clearpagination">Diesen Artikel auf einer Seite lesen</div>');
		
		var number_navi = '';
	 	number_navi ='<div id="number_navi">';
		for (i=1; i<=l; i++){
			if(i==1) { 	number_navi = number_navi+'<span class="navi_number active">'+i+'</span> '; }
			else     {	number_navi = number_navi+'<span class="navi_number">'+i+'</span> '; }
		}
		number_navi = number_navi+'</div>';
		
		$('#pagilist').after(number_navi);
	} // Pagination stop
	
	$('.navi_number').live('click', function() {
		var clicked_pagenumber = parseInt($(this).text())-1;
		var link = $('.pagi_navi')[clicked_pagenumber];
		$('.navi_number').removeClass('active');
		$(this).addClass('active');
		$(link).trigger('click');
	});
	
	
	if($("#xingbutton").length) {
		var href = window.location.href;
		$("#xingbutton").attr('href','https://www.xing.com/app/user?op=share&url='+href+';title='+$('title').text().replace(/&/, "und")+';provider=Randstad Korrespondent');
		$("#xingbutton").attr('target','_blank');
	}
	
	$('.pagi_navi').live('click', function(){
		
		page = $(this).index() +1;
		
		if (page != 1) { $('#main .teaser').fadeOut('fast'); }
		else if (page == 1) { $('#main .teaser').fadeIn('fast'); }
		
		$('#pagilist li').removeClass('active');
		$(this).addClass('active');
		
		$('.page:visible').slideUp(function(){
			$('#page_'+page).slideDown();
		});
		$('html, body').animate({scrollTop:260}, 'slow');
		
		// Update pager
		$('#pager').text('Seite '+page+'/'+$('.pagi_navi').length);
		if(page == 1) { 
			$('#pagercontainer .prev').removeClass('active'); 
			$('#pagercontainer .next').addClass('active'); 
		}
		else if (page != 1 && page != $('.pagi_navi').length) { 
			$('#pagercontainer .prev').addClass('active');
			$('#pagercontainer .next').addClass('active');
		} 
		else if (page == $('.pagi_navi').length) {
			$('#pagercontainer .prev').addClass('active');
			$('#pagercontainer .next').removeClass('active');
		}
		
		// Update number navi
		$('#number_navi span').removeClass('active'); 
		$($('#number_navi span')[page-1]).addClass('active');
		
		return false;
	});
	
	$('a.next').live("click", function(){
		
		var length = $('#pagilist li').length;
		//page = $('#pagilist .active').index() +1;
		
		var current_page = $('#pagilist li').index($('li.active'))+1;
		if(current_page == length) return false;
		else {
			var new_page = current_page+1;
			
			$('#main .teaser').fadeOut('fast');
		
			$('#pagilist li').removeClass('active');
			var nextli = $('#pagilist li').get(current_page);

			$(nextli).addClass('active');
		
			$('.page:visible').slideUp(function(){
				$('#page_'+new_page).slideDown();
			});
			$('html, body').animate({scrollTop:260}, 'slow');
			$('#pager').text('Seite '+new_page+'/'+length);
			
			// Update number navi
			$('#number_navi span').removeClass('active'); 
			$($('#number_navi span')[current_page]).addClass('active');
		}
		return false;
	});
	
	$('a.prev').live("click", function(){
		
		var length = $('#pagilist li').length;
		
		var index = $('#pagilist li').index($('li.active'));
		var current_page = index+1;
		
		if(current_page == 1) {
			
			return false;
		}
		else {
			var new_page = current_page-1;
			
			if (new_page != 1) { $('#main .teaser').fadeOut('fast'); }
			else if (new_page == 1) { $('#main .teaser').fadeIn('fast'); }
		
			$('#pagilist li').removeClass('active');
			var nextli = $('#pagilist li').get(index-1);

			$(nextli).addClass('active');
		
			$('.page:visible').slideUp(function(){
				$('#page_'+new_page).slideDown();
			});
			$('html, body').animate({scrollTop:260}, 'slow');
			
			$('#pager').text('Seite '+new_page+'/'+length);
			
			// Update number navi
			$('#number_navi span').removeClass('active'); 
			$($('#number_navi span')[new_page-1]).addClass('active');
		}
		return false;
	});
	
	$('#clearpagination').live('click', function(){
		$('.page:hidden').slideDown();
		if($('#main .teaser:hidden')){ $('#main .teaser:hidden').fadeIn('fast'); }
		$('#pagercontainer').fadeOut('fast');
		$('#pagilist').fadeOut('fast');
		$('#pagi_head').fadeOut('fast');
		$('#pagi_hr').fadeOut('fast');
		$('#pagi_navi').fadeOut('fast');
		$('#number_navi').fadeOut('fast');
		$(this).text('');
		
		return false;
	});
	// Pagination end
	
	
	
	// Collapse archive navigation
	$("p.collapseit").click(function(){
		$("#ul"+this.id).slideToggle();
		if($("#"+this.id+" .pfeil_img").attr('src') == 'tl_files/images/pfeil_close.jpg'){
			$("#"+this.id+" .pfeil_img").attr('src', 'tl_files/images/pfeil_open.jpg');
		}
		else {
			$("#"+this.id+" .pfeil_img").attr('src', 'tl_files/images/pfeil_close.jpg');
		}
	});
	
	// Toggle Newsmonths
	$(".togglemonths").click(function(){
		$("#"+this.id+'+ul').slideToggle();
		if($("#"+this.id+" .pfeil_img").attr('src') == 'tl_files/images/pfeil_close.jpg'){
			$("#"+this.id+" .pfeil_img").attr('src', 'tl_files/images/pfeil_open.jpg');
		}
		else {
			$("#"+this.id+" .pfeil_img").attr('src', 'tl_files/images/pfeil_close.jpg');
		}
	});
		
	// lightbox
	$("a[rel*=lightbox]").lightbox();
	
	// img captions
	if ($('img') != null){
			$("img").jcaption({
				//Element to wrap the image and caption in
				wrapperElement: 'div',
				//Class for wrapper element
				wrapperClass: 'caption',
				//Caption Element
				captionElement: 'p',
				//Attribute of image to use as caption source
				imageAttr: 'title',
				//If true, it checks to make sure there is caption copy before running on each image
				requireText: true,
				//Should inline style be copied from img element to wrapper
				copyStyle: false,
				//Strip inline style from image
				removeStyle: true,
				//Strip align attribute from image
				removeAlign: true,
				//Assign the value of the image's align attribute as a class to the wrapper
				copyAlignmentToClass: false,
				//Assign the value of the image's float value as a class to the wrapper
				copyFloatToClass: true,
				//Assign a width to the wrapper that matches the image
				autoWidth: true,
				//Animate on hover over the image
				animate: false,
				//Show Animation
				show: {opacity: 'show'},
				showDuration: 200,
				//Hide Animation
				hide: {opacity: 'hide'},
				hideDuration: 200  
			});
	} // img captions end	
});

