jQuery.noConflict();

/*
 * General DOM ready statemenets
 */
jQuery(function($) {

$('th:first-child, td:first-child').each(function(){
  $(this).css('border-left','0');
});


//don't display empty paragraphes in press releases
	$('p.hugin').each(function() {
		var pvalue = $(this).html();
		if(pvalue== '&nbsp;'){
			$(this).css('display','none');
		}
  });

//don't display empty paragraphes on press releases preview
	$('.news-preview p').each(function() {
		var pvalue = $(this).html();
		if(pvalue== '&nbsp;'){
			$(this).css('display','none');
		}
  });



	/*
	 *  EmptyOnFocus
	 *  Used for the general search form on top
	 */
 	$('#search input').placeholder();
	$('#vacaturesSearch').placeholder();


	 $('#project-list div.jNiceWrapper').css('z-index', '0');


	//Search
	$('#search').find('input:submit').hover(function(){ $('#search').addClass('hover') }, function(){ $('#search').removeClass('hover') })

	//IE6 fixes
	if($.browser.msie){
		$('#subnav li li ul li:first-child').addClass('first-child');
		$('.main-col:first-child').addClass('first-main-col');
		//Fix for Werken Bij Margins
		$('#careersubhomepage').find('#newsevents').siblings('.viewall').css('margin-top','0');
	}

	if (($.browser.msie) && ($.browser.version <= 6)) {
		$('#lang li:first-child, table th:first-child, table td:first-child').addClass('first-child');
		$('.news, .event, .viewall, #homepage #related > li, #related ul li, .download-category table td, #jobs h6, #column .csc-default #similar-jobs li, #press-overview-button a, .media-images span.media-download').hover(function(){ $(this).attr('id','over'); }, function(){ $(this).attr('id',''); })
		$('.button').hover(function(){ $(this).attr('id','bover'); }, function(){ $(this).attr('id',''); })
		$('#newsevents').find('.news-item:first-child').addClass('firstnews');
		var $stayC = $('.stay-connected a');
		$stayC.hover(function(){ $(this).find('i img:first-child').hide(); }, function(){ $(this).find('i img:first-child').show(); })
			$('#careersubhomepage #joblist a, #scroller-inner a, #column .csc-default .vacaciesWidget #joblist li').hover(function(){ $(this).addClass('over'); }, function(){ $(this).removeClass('over'); })
		
		$('#press-overview-button a ').append('<i></i>')
	
		$('#column .csc-default ul li').hover(function(){ $(this).addClass('over')}, function(){ $(this).removeClass('over')})
	
	
		$('.main #related li, #latestPubWidget #related li').hover(function(){ $(this).attr('id','over'); }, function(){ $(this).attr('id',''); })
		//Media Browser
		if($('body').find('#media').length > 0){
			var $interact = $('#interact');
			var $media = $('#media').parent();
			$interact.prependTo($media);
		}
	}

	$('#news .news:first').addClass('first-child')

	//Press List Download & Title trimming
	$('.press-list-item:first').addClass('press-list-item-first')
	$('.press-list-item').find('a').wrapInner('i')
	/*$('.press-list-item').find('i').shorten({ width: 580 }) //Title trimming*/

	//Downloads Press Release Title trimming
	/*$('.download-list').find('.file-title').shorten({ width: 500 }) //Title trimming*/

	//Media Library Title Timming
	/*$('#media-folders').find('.item').each(function(){
		var $titleText = $(this).find('h3').text();
		var $title = $(this).find('h3');
		$title.shorten({ width: 150 }).attr('title',$titleText)
	})*/

	//Tabs
	$('#news-list ul li').bind('click mouseenter',function(){
		var li = $(this)
		if(!li.is('.active')){
			li.siblings().removeClass('active').end().addClass('active');
			return false;
		}
	}).eq(0).click();

	//Latest Press
	$('.news:even').addClass('odd');

	$('.viewall').find('.flickr').click(function(){
		$(this).siblings('a').click();
	});

	//Homepage Video
	if(!$('body').find('#careers-bg').length > 0){
		$('#subhome-button').click(function(){
			$(this).siblings('h1').hide().end().hide().parent().css({ borderRight: '0', paddingRight: '19px'}).end().siblings('div').show()
		});
		$('#full-message .close').click(function(){
			$(this).parents('#full-message').hide().siblings('h1, a').show().parent().css({ borderRight: '1px solid #fff', paddingRight: '18'});
			return false;
		});
	}
	
	//Careers Subhomepage Video
	if(!$('body').find('#careers-bg').length > 0){
		$('#careersubhomepage #subhome-button').click(function(){
			$(this).siblings('h1, strong').hide().end().hide().parent().css({ borderRight: '0', paddingRight: '19px'}).end().siblings('div').show()
		});
		$('#careersubhomepage #full-message .close').click(function(){
			$(this).parents('#full-message').hide().siblings('h1, a, strong').show().parent().css({ borderRight: '1px solid #fff', paddingRight: '18'});
			return false;
		});
	}
	

	//Select Styling
	$('.select').find('.option').click(function(){
		var $options = $(this).siblings('.options')
		$(this).addClass('showoptions')
		$options.show();
		return false;
	});


	//Tip a Friend
	$('#send').fancybox({
          'height'          : 400,
          'width'			: 420,
          'showNavArrows'   : false,
          'padding'			: 30,
          'type'            : 'iframe',
          'scrolling'		: 'no',
          'autoDimensions'  : 'true',
           'autoScale'      : 'false'
	});

	//Equal Heights Columns
	$('.cols .box-content').equalHeights()

	//Selected Filter Color
	$('.jNice-list').find('a').click(function(){
	  $(this).parents('.jNiceWrapper').find('.jNiceSelectText').addClass('jNiceSelected');
	})

	//Jump to country corners
	var $col = $('.column-list ul li a')
	$col.append('<span class="tl"></span><span class="tr"></span><span class="bl"></span><span class="br"></span>');

	//Search Checkboxes
	//$('#bigsearch').find('input:checkbox').jNice();

	//Vessel Title
	$('.vessel').each(function(){
		var $vesselTitle = $(this).find('span.h4');
		$vesselTitle.hide();
		if(!$(this).parent().prev().children().is('.vessel'))
		$vesselTitle.show();
	});

	// Mark selected item (if not default)
	$('.jNiceWrapper').each(function(){
			var selectedValue = $(this).find('.jNiceSelectText').text();
			var defaultValue = $(this).find('.jNice-list ul li a[index="0"]').text();
			if(selectedValue != defaultValue) {
					$(this).find('.jNiceSelectText').addClass('jNiceSelected');
			}
		});
					
	//Pixel Perfect Hacks
	//$('#careers-bg #newsevents').siblings('.viewall').addClass('viewall-nomg')

});

/*
 * Testimonials Scroller
 */

jQuery(function($) {
	
	$('#scroller-inner').jcarousel({
		scroll: 1,
        initCallback: mycarousel_initCallback,
				buttonNextHTML: null,
        buttonPrevHTML: null,
		easing: 'linear',
		wrap: 'circular',
		animation: '400',
		start: parseInt($('#scroller-inner .active').index())-1
		
	});
	
	function mycarousel_initCallback(carousel){
	
		$('#scroller #next').bind('click', function(){
			carousel.next();
			return false;
		});
		
		$('#scroller #prev').bind('click', function(){
			carousel.prev();
			return false;
		});
		
		$('#scroller').css('visibility','visible');
		
	}
	
});

/*
 * Video
 */
jQuery(function($) {$(this)

	var $rkVideo = $('#video .rk_video').hide(),
		$videoPager = $('#video-pager');
	if ($rkVideo.length > 0) $videoPager.css('position','static');

	$rkVideo.each(function(i){
        var videoTitle = $(this).attr('title');
		var src = $('embed', this).attr('src');
        $(this).html(''); // #0020100: Stop auto-play in background in IE7

		//Creating link
		$('<a href="#" title="'+videoTitle+'">'+(i+1)+'</a>')
			.appendTo($videoPager)
			.click(function() {
				$.fancybox({
						padding			: 0,
						autoScale		: true,
						transitionIn	: 'none',
						transitionOut	: 'none',
						//centerOnScroll: true,
						overlayOpacity	:'0.84',
						overlayColor	:'#000',
						//width			: 640,
						//height		: 360,
						href			: src,
						type			: 'swf',
						swf				: {
						   	wmode		: 'transparent',
						   	allowscriptaccess: 'always',
							allowfullscreen	: 'true'
						}
					});
				if($(this).parent().is('#video-pager'))	$(this).parents('body').find('#fancybox-wrap').addClass('videobox');
				$(this).siblings('a').removeClass('active').addClass('active');
				$('#fancybox-close').click(function(){
					$(this).parents('#fancybox-wrap').removeClass('videobox');
				})
				return false;
			});
	});

});

/*
 * Homepage Jobs link
 */
jQuery(function($){
	$('#jobs h6').append('<i />');
});

/*
 * Cycle & Flickr
 */
jQuery(function($) {

 	//Cycle
	var $cycle = $('#cycle-inner'),
		$items = $('.item', $cycle),
		$flickrButton = $('#banner-bar .viewall');

	$cycle.cycle({
		fx:     'scrollHorz',
		timeout: 7500,
		speed: 300,
	    pager:  '#cycle-pager .pager-pages',
	    next:   '.next',
	    prev:   '.prev',
	    pause:  1,
	    before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
	    	$('#cycle .flickr-back').click();

	    	//Showing or Hiding the flickr button
	    	if($(nextSlideElement).is('.has-flickr')){
	    		$flickrButton.show('fast');
	    	} else {
	    		$flickrButton.hide('fast');
	    	}
	    }
	});

	//Hiding the flickr button when there's only 1 project active
   	//console.log($items.length);
   	if (($items.length <= 1) && (!$items.eq(0).is('.has-flickr'))) {
   		$flickrButton.hide();
   	}

	//Hide Pagination when there's only one item
	if($('.pager-pages').is(':empty')){
		$('.pager-pages').parent().hide();
		$('.pager-pages').parent().parent().siblings('a').hide();
	}
	//Hide Filters if empty
	if($('#filter').is(':empty')){
		$('#press-filters').hide();
	}

	//Fix for left
	$('.desc').each(function(){
		var $desc = $(this);
		if ($desc.is('.right')) {
			$desc.removeClass('right').parents('.item').addClass('right');
		}
	});

	/*
	 * Flickr Slideshow
	 */

	// Show Flickr Panel
	// LIST
	$('#banner-bar .viewall, #flickr').find('a').click(function(){

		$cycle.cycle('pause'); //Pausing automatic cycle
        $('#banner .next, #banner .prev').css('visibility','hidden');
		$('#cycle-inner .item:visible').find('.flickr-slideshow').animate({
			right: '0'
		}, 400);
		return false;
	});

	// Hide Flickr Panel
	// LIST
	$('.flickr-back').click(function(){
        $('#banner .next, #banner .prev').css('visibility','visible');
		$(this).parents('.flickr-slideshow').animate({
			right: '-960'
		}, 400, function() {
            $('#cycle #cycle-inner').show();
        });

		$cycle.cycle('resume'); //Resuming automatic cycle

		return false;
	});

	// Show Flickr Panel
	// SINGLE
	$('#flickr').find('a').click(function(){

		$cycle.cycle('pause'); //Pausing automatic cycle
		$('#cycle .flickr-slideshow').animate({
			right: '0'
		}, 400);
		return false;
	});

	// Hide Flickr Panel
	// SINGLE
	$('.flickr-back').click(function(){
		$(this).parents('.flickr-slideshow').animate({
			right: '-960'
		}, 400);
		return false;
	});

	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
	    $(pager).parent().find('a').removeClass('active')
	        .filter('a:eq('+currSlideIndex+')').addClass('active');
	};

	var $flickrSlideshow = $('.flickr-slideshow');
    var photoCount = $('.flickr-item').length;
    $('.flickr-inner-prev').hide();
	$flickrSlideshow.each(function(){
		var $flicker = $(this);
		$flicker.find('.flickr-img').cycle({
			fx: 'scrollHorz',
            next: '.flickr-inner-next',
            prev: '.flickr-inner-prev',
		    timeout: 0,
		    pager: $('.flickr-pager',$flicker),
			pagerAnchorBuilder: function(idx, slide) {
				var newPager ='';
				if ((idx %12 == 0) && (idx != 0)) newPager = '</div><div class="flickr-pager">'
				return newPager+'<a href="#"><img src="'+$('img',slide).attr('src')+'"/></a>';
	    	},
            onPrevNextEvent: function(isNext, zeroBasedSlideIndex, slideElement) {
                if(zeroBasedSlideIndex == 0) {
                    $('.flickr-inner-prev').hide();
                }
                else {
                    $('.flickr-inner-prev').show();
                }
                if(zeroBasedSlideIndex == photoCount) {
                    $('.flickr-inner-next').hide();
                }
                else {
                    $('.flickr-inner-next').show();
                }
            }
		});
	});


	$('.flickr-pager').each(function(){
		var $flc = $(this);
		var parent = $flc.parent();
		$flc.find('.flickr-pager').each(function(){
			var $flcNew = $(this);
			$flcNew.nextAll().appendTo($flcNew);
			$(this).appendTo(parent)
		});
	});

	//Creating a cycle for the thumbs (pager-items)
	$flickrSlideshow.each(function(){
		var $flicker = $(this);
		var $flickrPager = $('.flickr-pager-inner', $flicker);

		$flickrPager.cycle({
			fx: 'scrollHorz',
		    timeout: 0,
		    next: $('.flickr-next',$flicker),
		    prev: $('.flickr-prev',$flicker)
		});

		//Hiding the arrows if there are few items
		if ($flickrPager.children().length <= 1) {
			$('.flickr-next, .flickr-prev',$flicker).hide();
		};
	});

	//Close Button for Video
	$('#message-inner').find('.close').appendTo('.rk_video');

	//Details Button
	$('.details').wrapInner('i').append('<span></span>');

    // Show/hide next and prev buttons
    $('.flickr-next').click(function(){
        setTimeout(function() {
            $('.flickr-prev').show();
            $('.flickr-next').hide();
        },1000);
    });
    $('.flickr-prev').click(function(){
        $('.flickr-next').show();
        $('.flickr-prev').hide();
    }).hide();
});

/*
 * Media Library
 */
jQuery(function($) {

	$('#mediaperpageform').change(function(){
		$(this).trigger('submit')
	});

});

/*
 * Careers
 */
jQuery(function($) {
	var $cyclecareers = $('#vacancies-inner');

	$cyclecareers.cycle({
		fx:     'scrollHorz',
		timeout: 5000,
		speed: 500,
	    pager:  '#cycle-pager #pager-pages',
	    pause:  1

	});

    $('#careersubhomepage #filter select, #vacancypage #filter select').change(function() {
      $('#search-submit').click();
    });

 	//Clear filters
	/*$('#vacancypage a.edit').click(function(){
		$('#vacancypage #filter select option').attr('selected', false);
		$('#vacancypage #filter [name*="tx_ttnews[swords]"]').val('');
		$('#vacancypage #filter #search-submit').click();
		return false;
	});*/
});

/*
 * Ajax Filter
 *
jQuery(function($) {

	setUpProjectsAjax();

});

function setUpProjectsAjax(){

(function($) {

	var $filter = $('#filter'),
		$pager = $('#perpageform'),
		$submit = $('[type=submit]', $filter).hide(),

		$continent = $('#continent'),
		$country = $('#country'),

		$projectList = $('#project-list').addClass('js'),
		_url = window.location.href,

		$loader = $('#loading'),
		parameters = '';

	//Filtering countries based on continent selection
	$continent.change(function(){

		var $el = $(this),
			$countryLinks = $country.siblings('.jNiceSelectWrapper').find('a').slice(1);

		//All continents
		if ($el.val() == '') {
			$countryLinks.show();
		} else {
			$countryLinks.hide().filter('.p'+$el.val()).show();
		}

	});

	//Preparing to make the AJAX call when changing the filter option
	$('select', $filter).add('select', $pager).change(function(){

		//AJAX params
		parameters = $filter.serialize()+'&'+$('#perpageform').serialize()+'&ajax=1';

		//AJAX submit
		ajaxSubmit(parameters);
	});

	//Pager
	$('#project-list').click(function(event){
		if ($(event.target).is('a') && $(event.target).parents('#browse-bar')[0]) {

			//Getting the pointer
			var href = event.target.href;
			var pointer = href.substring(href.indexOf('pointer='));

			//AJAX params
			parameters = $filter.serialize()+'&'+$('#perpageform').serialize()+'&ajax=1&'+pointer;

			//AJAX submit
			ajaxSubmit(parameters);
			return false;
		}
	});

	//Actual ajax function.
	//This handles all ajax requests for the Project List
	function ajaxSubmit(parameters){
        // Crop string if it exceeds the limit of the jNice box
        $('.jNiceWrapper').each(function(){
            var selectedContent = $(this).find('.jNiceSelectText').text();
            if(selectedContent.length > 26) {
                selectedContent = selectedContent.substring(0,26)+'...';
                $(this).find('.jNiceSelectText').text(selectedContent);
            }
        });

		//Loading animation ON
		$loader.fadeIn(300);

		//Emptying the workarea
		$projectList.empty();

		//Making the AJAX call
		$.ajax({
			type: 'post',
	  		url: _url,
	  		data: parameters,
	  		success: function(data) {
				$loader.fadeOut(300);  	//Loading animation OFF

 				//$('#project-list div.jNiceWrapper').css('z-index', '0');
				//data = data.substr(data.indexOf('<bdy'));

	   			$projectList.empty().html(data);	//Adding the data
	   			Cufon.replace('.project .txt h3', {hover: 'true'}); //Cufon the titles
	   			$('.project', $projectList).hide().showdelay(); //Showing the data
	   			//Readd jNice
	   			$('#perpageform').jNice();

	   			$('#perpageform .jNiceWrapper').css('z-index','0');

	   			//Reattaching some events
	   			$('#perpageform select').change(function(){

					//AJAX params
					parameters = $filter.serialize()+'&'+$('#perpageform').serialize()+'&ajax=1';
					//AJAX submit
					ajaxSubmit(parameters);

				});

				// Mark selected item (if not default)
				$('.jNiceWrapper').each(function(){
        				var selectedValue = $(this).find('.jNiceSelectText').text();
        				var defaultValue = $(this).find('.jNice-list ul li a[index="0"]').text();
        				if(selectedValue != defaultValue) {
            					$(this).find('.jNiceSelectText').addClass('jNiceSelected');
        				}
    				});
	  		},
	  		error: function(data) {
	  			//Loading animation OFF
				$loader.fadeOut(300);
				$projectList.html(data);

					$('#perpageform .jNiceWrapper').css('border','1px solid red');

	  		}
		});



	}

	//Initial Load
	$('.project', $projectList).showdelay();

	})(jQuery);
}

/*jQuery(function($){

	var $clearFilters = $('#filters').find('h2 .edit');
	$clearFilters.click(function(){
		var $select = $('.jNiceWrapper');
		$select.each(function(){
			var $el = $(this).find('.jNiceSelectText');
			var $reset = $(this).find('.jNice-list li:first-child a').text();
			$el.text($reset);
		});
	});



});*/
/*
jQuery(function($){

	var $clearFilters = $('#filters').find('h2 .edit');
	$clearFilters.click(function(){
		location.reload();
	});

});*/

/*
 * Filter Ajax
 *
jQuery(function($){
	var $filters = $('#filters'),
		$loader = $('<div class="loader" />').appendTo($filters);

	$('#filter').change(function(){
		if (document.getElementById('pressRelease-page')) return false;
		ajaxSubmit();
	});

	function ajaxSubmit(){
		$('.loader', $filters).fadeIn(300);

		$.ajax({
			type: 'post',
	  		url: window.location.href,
	  		data: $('#filter').serialize()+'&ajax=2',
	  		success: function(data) {
				$('.loader', $filters).fadeOut(300);  	//Loading animation OFF

	   			$filters.empty().html(data+'<div class="loader"></div>');	//Adding the data

				$('#filter').jNice();

				$('#filter').change(function(){
					ajaxSubmit();
				});

				setUpProjectsAjax();

				// Mark selected item (if not default)
				$('.jNiceWrapper').each(function(){
                    var selectedValue = $(this).find('.jNiceSelectText').text();
                    var defaultValue = $(this).find('.jNice-list ul li a[index="0"]').text();
                    if(selectedValue != defaultValue) {
                            // Crop string if it exceeds the limit of the jNice box
                            var selectedContent = $(this).find('.jNiceSelectText').text();
                            if(selectedContent.length > 26) {
                                selectedContent = selectedContent.substring(0,26)+'...';
                                $(this).find('.jNiceSelectText').text(selectedContent);
                            }
                            $(this).find('.jNiceSelectText').addClass('jNiceSelected');
                    }
                });

	  		},
	  		error: function(data) {
	  			//Loading animation OFF
				$('.loader', $filters).fadeOut(300);
				$projectList.html(data);
				setUpProjectsAjax();
	  		}
		});
	}

});/*


/*
 * Downloads
 */
jQuery(function($) {

	var $downloads = $('#downloads'),
		$category = $('.download-category', $downloads),
		$title = $('h2', $downloads),
		$content = $('.content', $downloads).hide(),
		$tabs = $('div.tabs', $downloads),
		$tabsMore = $('.tabs-more', $tabs).hide(),
		$child = $('.list > li > a', $downloads),
		$subcontent = $('.list > li > ul', $downloads).hide();

	//Accordion
	/*
	$title.toggle(
		function(){
			$(this).addClass('open');
			$(this).next('.content').slideDown(function(){
				$(this).blur();
			});
			return false;
		},
		function(){
			$(this).removeClass('open');
			$(this).next('.content').slideUp(function(){
				$(this).blur();
			});
			return false;
		}
	);
	*/

	$title.click(function(){
		var $el = $(this), $content = $el.next('.content'),
			$siblings = $el.parent().siblings().find('>h2.open');

		if ($el.is('.open')) {
			$el.removeClass('open');
			$content.slideUp(function(){
				$(this).blur();
			});
		} else {
			$el.addClass('open');

			$content.slideDown(function(){
				$(this).blur();
			});

            var firstChild = $('ul.tabs li:first-child',$content);
            var secondChild = firstChild.next();
            secondChild.children('a').trigger('click');
            setTimeout(function() {
                var triggeredClick = false;
                firstChild.children('a:first-child').each(function(){
                    if(!triggeredClick) {
                        $(this).trigger('click');
                        triggeredClick = true;
                    }
                });
            },50);

			$siblings.trigger('click');
		}

		return false;

	});

	$child.toggle(
		function(){
			$(this).addClass('open');
			$(this).next('ul').slideDown();
			return false;
		},
		function(){
			$(this).removeClass('open');
			$(this).next('ul').slideUp();
			return false;
		}
	);

	//Tabs
	$tabs.tabs();

	$tabs.each(function(){

		var $tab = $(this),
			$tabsMore = $('.tabs-more', $tab);

		//Creating the extra tabs
		var $archive = $('>ul>li', $tab).slice(10);
		if ($archive.length > 0) {
			$archive.wrapAll('<li class="tabs-archive"><ul></ul></li>');
			$tabsMore.show();
		}

		var $tabsArchive = $('.tabs-archive', $tab);

		$tabsMore.mouseenter(function(){
			$tabsArchive.show();
			$tabsMore.hide();
		})

		$tabsArchive.mouseleave(function(){
			$tabsArchive.hide();
			$tabsMore.show();
		});
	});
	
	$('#tabs ul li a').click(function(){
		setTimeout(function() {
        		Cufon.refresh();
		}, 10); 
	});
	
	// Refresh cufon with a delay so the active tab is displayed properly
	setTimeout(function() {
		Cufon.refresh();
	}, 100);


    var locationParts = $(location).attr('href');
    locationParts = locationParts.split('#');
    if(locationParts.length > 1) {
        var startChar = locationParts[1].substring(0,1);
        if(startChar == 'f') {
            $('#'+locationParts[1]).closest('div.download-category').children('h2').children('a').click();
            var t = setTimeout ("jQuery(function($) { var locationParts = $(location).attr('href'); locationParts = locationParts.split('#'); var downloadTagName = $('#'+locationParts[1]).get(0).tagName; switch(downloadTagName) { case 'TR': var downloadCategoryId = $('#'+locationParts[1]).parent().parent().parent().attr('id'); $('a[href$=\"'+downloadCategoryId+'\"]').click(); break; case 'A': $('#'+locationParts[1]).parent().parent().parent().children('a').click(); break; }});",300);
            $('a#'+locationParts[1]).addClass('hover').hover();
            $('tr#'+locationParts[1]+' td').addClass('over');

        }
        else if(startChar == 'c') {
            $('a#'+locationParts[1]).closest('div.download-category').children('h2').children('a').click();
            if($('a#'+locationParts[1]).parent().get(0).tagName != 'H2') {
                var t = setTimeout ("jQuery(function($) { $('a#"+locationParts[1]+"').click(); });",0);
            }
        }
    }

});

/*
 * Press release
 */
jQuery(function($) {

 	var $context = $('#press-filters'),
 		$clear = $('.edit', $context);
	
	/*	
	//Remove Chrome Placeholder
	if ($.browser.webkit) {
		chromePlaceholder = $('#press-release-search-input').attr('placeholder')
		$('#press-release-search-input').removeAttr('placeholder').val(chromePlaceholder);
		$('#press-release-search-input').clearInput();
	}
	*/

	//Press release
	$('#pressRelease-page input[type=submit]').show();
	$('#press-search input, #press-subscribe input').placeholder();
	$('#shareyouropinionform textarea').placeholder();

	if ($('body').is('#pressRelease-page')) {

		$('#market, #pressPagerItems').change(function(){
			$(this).parents('form').submit();
		});

	}

	//Clear filters - marian commented (clear filters works without jQuery but with gp vars in link)
	/*$clear.click(function(){

		var $el = $(this),
			$form = $el.parents('.press-filters').find('form'),
			$yearInput = $('[name*=newyear]', $form),
			$keywordInput = $('[name*=swords]', $form);

		if ($yearInput.is(':visible')) $yearInput.val('');
		if ($keywordInput.is(':visible')) $keywordInput.val('');

		$form.submit();

		return false;
	});*/

});


/*
 * Financial alignment financial calendar
 */

jQuery(function($) {

    $.each($('.financialCalendar h4'), function(index, value) {
  		if($(this).height() == '15') {
  			$(this).addClass('financialCalendarMargin');
  		}
	});

});

/*
 * CSC Sitemap
 */
jQuery(function($) {

	var $sitemap = $('.csc-sitemap'),
		$a = $('>ul>li>a, >ul>li>ul>li>a', $sitemap),
		$toggle = $('#sitemap-toggle');

	//Adding odd classes to the list items
	$('>ul>li>ul>li>ul', $sitemap).each(function(){
		$('a:even', this).addClass('odd');
	});

	//Adding a class to childless elements
	$('>ul>li>ul>li', $sitemap).each(function(){
		var $li = $(this);
		if (!$('>ul', $li)[0]) {
			$li.addClass('childless');
		}
	});

	//Accordion
	$a.click(function(){
		var $link = $(this);

		//If parent is childless we follow the link
		if ($link.parent().is('.childless')) {
			return true;
		}

		if (!$link.is('.open')) {
			$link.addClass('open').next('ul').slideDown();
		} else {
			$link.removeClass('open').next('ul').slideUp();
		}
		return false;
	});

	//All items toggle
	$toggle.click(function(event){
		if (event.target.href) {
			if (event.target.href.indexOf('#fold') > 0) {
				$a.removeClass('open').next('ul').slideUp();
			} else {
				$a.addClass('open').next('ul').slideDown();
			}
		}
		return false;
	});

});

/*
 * History Tabs
 */
jQuery(function($) {
	var $tabs = $('#tabs'),
		$links = $('.tabs a', $tabs),
		$tabsMore = $('.tabs-more', $tabs).hide();

	$tabs.tabs();

	if (!$tabs.is('.media')) {
		goto = jQuery('div.goto').text();
		$links.each(function(i){
			var $a = $(this),
				href = $a.attr('href'),
				$prev = $(href).prev('.tab-content');
				text = $a.text(),

				$button = $('<div class="viewall"><a href="'+href+'">'+goto+' '+text+'</a><i></i></div>').appendTo($prev);

			$('a',$button).click(function(){
				$links.filter('[href='+href+']').click();
				return false;
			});

		});
	}

	//Creating the extra tabs
	var $archive = $('>ul>li', $tabs).slice(7);
	if ($archive.length > 0) {
		$archive.wrapAll('<li class="tabs-archive"><ul></ul></li>');
		$tabsMore.show();
	}

	var $tabsArchive = $('.tabs-archive', $tabs);

		$tabsMore.mouseenter(function(){
			$tabsArchive.show();
			$tabsMore.hide();
		})

		$tabsArchive.mouseleave(function(){
			$tabsArchive.hide();
			$tabsMore.show();
		});

});

/*
 * Quick Job Search
 */
jQuery(function($) {
	$('#quick-job').jNice();
});

/*
 * Information Request Form
 */
jQuery(function($) {
	$('#informationrequestform .powermail_check_inner').jNice();
});

/*
 * Press Release Single
 */
jQuery(function($) {
	var $wrap = $('#press-release-single');

	//Innerwrappign the h3's and adding the Back to top links
	$('h2, h3, h4, h5, h6', $wrap).each(function(){
		$(this).innerWrap('<span></span>').slice(1).append('<a class="back-to-top" href="#press-release-single">back to top</a>');
	});

	//Using JS to scroll up
	$('.back-to-top').click(function(){
		scroll(0,0);
		return false;
	});
});

/*
 * General Search Back to Top
 */
jQuery(function($) {
	var $wrap = $('.tx-indexedsearch');

	//Innerwrappign the h3's and adding the Back to top links
	$wrap.each(function(){
		if(!$(this).find('#pagesResNr').length > 0)
		//$(this).find('h3').append('<a class="back-to-top" href="#press-release-single">back to top</a>');
		//alert($(this).find('h3').position().left);
		$(this).prepend('<a class="back-to-top" href="#press-release-single" style="position:absolute;z-index:1000;left:'+($(this).find('h3').position().left-93)+'px;top:'+($(this).find('h3').position().top+14)+'px;">back to top</a>');
	});

	//Using JS to scroll up
	$('.back-to-top').click(function(){
		scroll(0,0);
		return false;
	});
});

/*
 * News & Events single
 */
jQuery(function($) {
	var $wrap = $('#news-single');

	//Innerwrappign the h3's and adding the Back to top links
	$('h2, h3, h4, h5, h6', $wrap).each(function(){
		$(this).innerWrap('<span></span>');
	});

});

/*
 * Normal content
 */
jQuery(function($) {

	//Innerwrappign the h3's and adding the Back to top links
	$('h3').each(function(){
		if(!$(this).find('span').length > 0 )
		$(this).innerWrap('<span></span>');
	});

});

/*
 * Highlight Elements
 */
jQuery(function($) {

	var $highlighter = $('#tx-indexedsearch-searchbox-sword').val();
	$('.docResults').highlight($highlighter);

});

jQuery(function($) {

	//Margin for content images
	var $img = $('.csc-textpic-imagewrap').find('img');
	var $width = $img.attr('width');
	if($width == 166) $img.css('margin','0');

	var $imgwrap = $('.csc-textpic-imagewrap')
	$imgwrap.each(function(){
		var $img = $(this).find('img')
		var $height = $img.attr('height');
		if($height == 115) $img.css('margin','0');
	});

});

/*
 * Media Browser
 */
jQuery(function($) {

	var $mediaImages = $('#media-images'),
		$mediaVideos = $('#media-videos');

	//Setting the fancybox for images
	$('.image a', $mediaImages).attr('rel','media-gallery').fancybox({
		padding: 0,
		cyclic: true,
		overlayColor: '#000',
		overlayOpacity: .84,
		titleFormat:
			function formatTitle(title, currentArray, currentIndex, currentOpts) {
				var $item = $(currentArray[currentIndex]).parents('.item'),
					$title = $('h3 a', $item).clone(),
					$downlaod = $('.media-download', $item).clone(),
					$content = $title.add($downlaod).wrapAll('<div class="media-title" />').parent(),

					_innerWidth = $content.appendTo('body').width();
					$content.remove();

				//Centering the 'title'
				$content.css({
					'margin-left'	: -_innerWidth/2,
					'position'		: 'absolute',
					'top'			: '9px',
					'left'			: '50%'
				});

		    	return $content;
			}
	});

	//Setting the fancybox for video
	$('.image a', $mediaVideos).each(function(){
		var $a = $(this),
			$flash = $('.video-container', $a.parents('.item')),
			src = $('embed', $a.parents('.item')).attr('src');
			
			$a.click(function(){
				$('#fancybox-outer').removeClass('fancybox-outer-white').addClass('fancybox-outer-black');
			});


		$a.fancybox({
			padding: 0,
			overlayColor: '#000',
			overlayOpacity: .84,
			transitionIn: 'none',
			transitionOut: 'none',
			href: $a.attr('href'),
			type: 'swf',
			swf: {
				wmode: 'transparent',
				allowfullscreen: 'true',
				allowscriptaccess: 'always'
			}
		});

	});


});

/*
 * Boxkalis TV
 */

jQuery(function($) { 

	var $tvVideos = $('#boskalistv');

	//Setting the fancybox for video
	$('a', $tvVideos).each(function(){
		var $a = $(this),
			$flash = $('.video-container', $a.parents('.box-content')),
			src = $('embed', $a.parents('.box-content')).attr('src');


		$a.fancybox({
			padding: 0,
			overlayColor: '#000',
			overlayOpacity: .84,
			transitionIn: 'none',
			transitionOut: 'none',
			href: $a.attr('href'),
			type: 'swf',
			swf: {
				wmode: 'transparent',
				allowfullscreen: 'true',
				allowscriptaccess: 'always'
			}
		});

	});
	
});

/*
 * Organisation Map
 */
jQuery(function($) {
	var $showLocation = $('#show-locations'),
		$locationOffices = $('#location-offices').hide(),
		$checkbox = $(':checkbox', $showLocation);

	$showLocation.jNice();

	$showLocation.bind('click', toggleNames);
	$('.jNiceCheckbox', $showLocation).bind('click', toggleNames);
	$checkbox.bind('click change', toggleNames);

	function toggleNames() {
		if ($checkbox.is(':checked')) {
			$locationOffices.show();
		} else {
			$locationOffices.hide();
		}
	}

});

/*
* Search page
*/
/*jQuery('.jNiceCheckbox').bind('click', function() {
	jQuery(this).prev('input').trigger('click');
});*/

jQuery('#checkPages').click (function (){
	alert('test');
	var thisCheck = jQuery(this);
	if (thischeck.is (':checked')){
		alert('testif');
		jQuery('input[name=tx_indexedsearch[media]]').value('1');
	}
});

jQuery('#checkDocs').click (function (){
	var thisCheck2 = jQuery(this);
	if (thischeck2.is (':checked')){
		jQuery('input[name=tx_indexedsearch[media]]').value('2');
	}
});

/*
 * Table Sorter
 */
jQuery(function($) {
	$("#job-list")
		.tablesorter({
			widthFixed: true,
			widgets: ['zebra','columnHighlight']
		})
		.tablesorterPager({
			container: $("#browse-bar"),
			cssNext: '.pager-next',
			cssPrev: '.pager-prev',
			seperator: ' '+$('#pager-separator').text()+' ',
			cssPageDisplay: '.page-number'
		});
	$('#pager-separator').hide();
});



//clear form input
(function( $ ){
  // define the initialValue() function
  $.fn.initialValue = function(value) {
    if (value) {
      return this.attr('initial-value', value);
    } else {
      return this.attr('initial-value');
    }
  };

  $.fn.clearInput = function() {
    return this
      .focus(function(){
        if (this.value == $(this).initialValue()) {
          this.value = '';
        }
      })
      .blur(function(){
        if (this.value == '') {
          this.value = $(this).initialValue();
        }
      })
      .each(function(index, elt) {
        $(this).initialValue(this.value);
      });
  };

  // apply plugin to all inputs with class ".clear-input"
  $(function() {
    $('input.clear-input').clearInput();
  });

})( jQuery );


/*
 * Share a pages
 */
jQuery(function($){
	$('#shareYourOpinion, .footer-sitemap a.internal-link-new-window').click(function(){
   		$('#fancybox-outer').addClass('fancybox-outer-white').removeClass('fancybox-outer-black');
	});
	
	$('#shareYourOpinion, .footer-sitemap a.internal-link-new-window').fancybox({
	    'height'		: 310,
	    'width'			: 480,
	    'showNavArrows'   : false,
	    'padding'			: 30,
	    'type'            : 'iframe',
	    'scrolling'		: 'no',
	    'autoDimensions'  : 'true',
	    'autoScale'      : 'false'
	 });
	
	
});

// Home cycle
jQuery(function($) {
    $('.image-post-loader').each(function(){
        var realImage = '<img alt="" src="'+$(this).text()+'" height="417" width="960" />';
        $(this).replaceWith(realImage);
    });
});

// Quick search selection marker
jQuery(function($) {
   $('form.quick-search select').change(function(){
       $('.jNiceWrapper').each(function(){
            var selectedValue = $(this).find('.jNiceSelectText').text();
            var defaultValue = $(this).find('.jNice-list ul li a[index="0"]').text();
            if(selectedValue != defaultValue) {
                // Crop string if it exceeds the limit of the jNice box
                var selectedContent = $(this).find('.jNiceSelectText').text();
                if(selectedContent.length > 26) {
                    selectedContent = selectedContent.substring(0,26)+'...';
                    $(this).find('.jNiceSelectText').text(selectedContent);
                }
                $(this).find('.jNiceSelectText').addClass('jNiceSelected');
            } else {
                $(this).find('.jNiceSelectText').removeClass('jNiceSelected');
            }
        });
   });
   
   $('.tx-indexedsearch-browsebox').each(function(){
       if($(this).html() == '') {
           $(this).css('display','none');
       }
   });
   
   $('.docResults a').each(function(){
       $(this).attr('target','_blank');
   });
   
   $('#footer').supersleight({shim: 'fileadmin/custom/images/transparent.gif'});
   
   var vsPlaceholder = $('#vacaturesSearch').attr('placeholder');
   var vsValue = $('#vacaturesSearch').attr('placeholder');
   if(vsValue != vsPlaceholder) $('#vacaturesSearch').removeClass('placeholder');
});

/**
 * #0020065
 */
jQuery(function($) {
    $('.press-list-item, .box-content-financial-position .financialCalendar, #events .event, #newsFinancialCalendar .news').each(function(){
        if(!$(this).has('a').length) {
            $('div.date',$(this)).addClass('date-no-hover');
        }
        else {
            if($('div.date',$(this)).next().get(0).tagName != 'A') {
                $('div.date',$(this)).addClass('date-no-hover');
            }
            else {
                $('div.date',$(this)).click(function(){
                    window.location = '/'+$(this).next().attr('href');
                }).mouseenter(function(){
                    $(this).next().addClass('active');
                }).mouseleave(function(){
                    $(this).next().removeClass('active');
                });
            }
        }
    });
});

/**
 * #0020095
 */
jQuery(function($) {
    $('.tx-indexedsearch-res p').each(function(){
        var content = $(this).html();
        content = content.replace(/typo3temp\/pics\/([A-Z0-9]*)\.jpg/gi,"");
        $(this).html(content);
    });
});
