$(document).ready(function(){
	
	if($('.image-text-gallery-item').length > 0){
		
		$("a.fancy-group").fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'linear',
			'speedIn'		:	500, 
			'speedOut'		:	100, 
			'overlayShow'	:	true
		});
		
		$('#image-text-gallery-wrap').show();
		len = $('.image-text-gallery-item').length;
		list = $('#image-text-gallery ul');
		pos = 0;
		left = 0;
		
		$('#slide-left').click(function(){
			if(pos > 0){
				left += 500;
				list.animate({'left': left});
				pos--;
			}
		});
		
		$('#slide-right').click(function(){
			if(pos < (len-1)){
				left -= 500;
				list.animate({'left': left});
				pos++;
			}
		});
	}
	
	if($('.image-gallery-wrap').is('div')){
		$('.image-gallery-wrap').each(function(){
			$(this).find('.csc-textpic').css('width', $(this).find('.csc-textpic-imagerow:first').width());
			$(this).find('.csc-textpic-imagewrap').css('width', '10000em');
			$(this).find('.csc-textpic').before('<div class="ig-slide-left"></div>');
			$(this).find('.csc-textpic').after('<div class="ig-slide-right"></div>');
			ig_width = $(this).width();
			$(this).css({'width': ig_width, 'display': 'block'});
		});
		
		$('.ig-slide-left').click(function(){
			ig_items = $(this).parent().find('.csc-textpic-imagerow').length;
			
			ig_pos_tmp = parseInt($(this).parent().find('.csc-textpic-imagewrap').attr('title'));
			ig_pos = ig_pos_tmp ? ig_pos_tmp : 1;
			
			ig_left_tmp = parseInt($(this).parent().find('.csc-textpic').attr('title'));
			ig_left = ig_left_tmp ? ig_left_tmp : 0;
			
			if(ig_left >= 0)
				return;
			
			ig_left += $(this).parent().find('.csc-textpic-imagerow:first').width();
			$(this).parent().find('.csc-textpic-imagewrap').animate({'left': ig_left});
			
			ig_pos--;
			
			if(ig_pos == 1)
				$(this).css('background-position', 'right bottom');
				
			$(this).parent().find('.ig-slide-right').css('background-position', 'left top');
			$(this).parent().find('.csc-textpic-imagewrap').attr('title', ig_pos);
			$(this).parent().find('.csc-textpic').attr('title', ig_left);
		});
		
		$('.ig-slide-right').click(function(){
			ig_items = $(this).parent().find('.csc-textpic-imagerow').length;
			
			ig_pos_tmp = parseInt($(this).parent().find('.csc-textpic-imagewrap').attr('title'));
			ig_pos = ig_pos_tmp ? ig_pos_tmp : 1;
			
			ig_left_tmp = parseInt($(this).parent().find('.csc-textpic').attr('title'));
			ig_left = ig_left_tmp ? ig_left_tmp : 0;
			
			if(ig_pos == ig_items)
				return;
			
			ig_left -= $(this).parent().find('.csc-textpic-imagerow:first').width();
			$(this).parent().find('.csc-textpic-imagewrap').animate({'left': ig_left});
			
			ig_pos++;
			
			if(ig_pos == ig_items)
				$(this).css('background-position', 'left bottom');
				
			$(this).parent().find('.ig-slide-left').css('background-position', 'right top');
			$(this).parent().find('.csc-textpic-imagewrap').attr('title', ig_pos);
			$(this).parent().find('.csc-textpic').attr('title', ig_left);
		});
		
	}
		
		
	
	x = 0;
	if($('#top-strip').is('div')){
		$('#top-strip img').each(function(){
			$(this).attr('id', 'rotation-item-'+x++);
		});
		
		$('#rotation-item-0').show();
		
		image_strip_rotation = window.setInterval('imageStripRotation()', 15000);
	}
	
	y = 0;
	if($('#home-slider').is('div')){
		$('#home-slider .csc-default:first').css({'position': 'relative', 'display': 'block'});
		
		if($('#home-slider .csc-default').length > 1){
			$('#home-slider').append('<div id="home-slider-navigator"></div>');
			$('#home-slider .csc-default').each(function(){
				$(this).attr('id', 'home-slider-item-'+y);
				$(this).find('.csc-textpic-text').wrap('<div class="info-item"></div>');
				$('#home-slider-navigator').append('<div class="home-slider-navigator-item" id="'+y+'"></div>');
				y++;
			});
			$('#home-slider').append('<div class="clear"></div>');
			home_rotation = window.setInterval('homeRotation()', 15000);
			
			$('.home-slider-navigator-item').click(function(){
				id = parseInt($(this).attr('id'));
				homeRotation(id);
			});
			
			$('.home-slider-navigator-item:first').css('background-color', '#3F80D3');
		}
		$('.info-item').hover(function(){
				$(this).find('.csc-textpic-text').show();
				$(this).css({'width': 250, 'height': 'auto'});
				window.clearInterval(home_rotation);
			},
			function(){
				$(this).find('.csc-textpic-text').hide();
				$(this).css({'width': 20, 'height': 20});
				home_rotation = window.setInterval('homeRotation()', 3000);
			}
		);
	}
	
	$('.home-teaser:first').css('margin-left' , '2px');
	
	if($('#sec-nav').is('div')){
		if($('#content-wrap').outerHeight(true) > 500)
			$('#sec-nav').css('height', $('#content-wrap').height());
	}
	
	$('.facets ul li, #tx-solr-facets-in-use > ul ul > li').hover(function(){
		$(this).css('color', '#3F80D3');
		$(this).css('background-position', '0 -489px');
	},
	function(){
		$(this).css('color', '#000000');
		$(this).css('background-position', '0 4px');
	});
		
	
});

imageStripRotation_active = 0;

function imageStripRotation(){
	
	imageStripRotation_new = imageStripRotation_active + 1;
	
	if(imageStripRotation_new == x)
		imageStripRotation_new = 0;
	
	$('#rotation-item-'+imageStripRotation_active).fadeOut(2000).css('position', 'absolute');
	$('#rotation-item-'+imageStripRotation_new).fadeIn(2000).css('position', 'relative');
	imageStripRotation_active = imageStripRotation_new;

	window.clearInterval(image_strip_rotation);
	image_strip_rotation = window.setInterval('imageStripRotation()', 15000);
}

homeRotation_active = 0;

function homeRotation(click_value){
	
	if(click_value == undefined)
		homeRotation_new = homeRotation_active + 1;
	else
		homeRotation_new = click_value;
	
	if(homeRotation_new == y)
		homeRotation_new = 0;
	
	$('#home-slider-item-'+homeRotation_active).fadeOut(2000).css('position', 'absolute');
	$('#home-slider-item-'+homeRotation_new).fadeIn(2000).css('position', 'relative');
	$('#'+homeRotation_active).css('background-color', '#FFFFFF');
	$('#'+homeRotation_new).css('background-color', '#3F80D3');

	homeRotation_active = homeRotation_new;

	window.clearInterval(home_rotation);
	home_rotation = window.setInterval('homeRotation()', 15000);
}
