/*
 * 
 * e7Rev      : $Rev$
 */
var ivi;
var stageReady=false;
if (!ivi) {
	ivi = {}
}

if (typeof jQuery != 'undefined') {
    $.extend(ivi, {
    	
    	
    	// Init after page load
    	init: function(){
			ivi.initPlugins();	
    		ivi.addEvents();
			ivi.initAjaxSelectors();
			ivi.rotateImages();
			// Round corners for Content chapter
			$('.contentChapter:last').addClass('lastChapter');
			$('.contentChapter:first').addClass('firstChapter');
			
    		if(($('#marginColumn .teaserBox').height()-185) > ($('#contentBox .centerCol').height()+40)){
				$('#contentBox .innerBox').height(($('#marginColumn .teaserBox').height()-185));
			}

			//Determine the os
			var osName="";
			if (navigator.appVersion.indexOf("Mac")!=-1) osName="MacOS";
			
			//Apply fixes for os and browser
			if(osName=="MacOS" && $.browser.mozilla){
			    ivi.applyMacFirefoxFixes();
			}
			
			//Apply fixes for IE
			if($.browser.msie){
			    ivi.applyWindowsIeFixes();
			}
			
			// Teaser Fast Access skinned ComboBoxes 
            $('#teaser-fast-access select').styledSelectBox({
            	useJScrollPane: true 
            });
            
            if($('#helpPage').length > 0){
            	$('a[href]').attr('target', '_blank');
            }
            
    	},
    	
    	//Fixes
    	applyMacFirefoxFixes:function(){
    	        $(".paging").css("line-height", "14px");
			    $(".paging span span, .paging a span").css("padding", "6px 8px 2px 0");
			    $(".siteSearch #searchForm1 .txtField, #footerBox #searchForm2 .txtField").css({top: "1px",fontSize: "11px"});
    	},
    	
    	applyWindowsIeFixes:function(){
    		
    		// Fix cutted options in select boxes
    		var expand = function(){
	    		var width = $(this).css("width");
	    		// Don't overwrite the stored original width,
	    		// if the event occurs for a second time before contract()
	    		if (width == "auto")
	    		return;
	
	    		$(this)
	    		.data("origWidth", width)
	    		.css("width", "auto");

	    		if($(this).width() < parseInt(width)){
	    			$(this).css('width', width);
	    		}

    		};

    		var contract = function(){
	    		var width = $(this).css("width");
					
	    		// Don't perform this twice
	    		if (width != "auto")
	    		return;
	
	    		var origWidth = $(this).data("origWidth");
	    		// If the original width was not stored, abort
	    		if (origWidth === undefined)
	    		return;
	
	    		$(this)
	    		.css("width", origWidth)
	    		.data("origWidth", width);
    		};

    		$("select#cat1, select#cat2, select#cat3").each(function(index) {
	
	    		// The select needs to be enclosed in a container with the same CSS width,
	    		// which uses overflow:hidden, in order to hide the expanded part
	    		var width = $(this).css("width");
	    		var span = '<span style="padding-right: 8px; width:'+width+'; overflow:hidden; float:left;"></span>';
	    		$(this).wrap(span);
	

	    		$(this)
	    		.data("origWidth", width)
	    		.css("width", "auto");
	    		
	    		if($(this).width() > parseInt(width)){
	    			
	    			// Add event listeners
		    		$(this)
		    		.mousedown(expand)
		    		.blur(contract)
		    		.change(contract);
	    		}
	    		
	    		$(this)
	    		.css("width", width)
    		});

    	},
    	
    	addEvents: function(){
    		// Hover for Top links box
			$('dl.topLinks dt a').live('hover', function(event){
				$(event.target).parent().toggleClass('hover').next('dd').toggleClass('hover');
			});
			// Hover for Top links box
			$('dl.topLinks dd').live('hover', function(event){
				$(event.target).toggleClass('hover').prev('dt').toggleClass('hover');
			});


			/*** table products ***/
			$('.table-products tbody tr').live('hover', function(event){
				$(this).toggleClass('green');
			});		
			
			/*** teaser fast access ***/
			$('#teaser-fast-access select').live('change', function(event){
				self.location.href = $(this).attr("value");
			});					
			
			/*** tertiary teaser standard ***/
            $('.tertiary-teaser.standard').hover(
                    function(){
                    	$(this).find('.tertiary-teaser-bg-image').animate({top: '0px'}, {queue: false, duration: 200}, 'swing');
                    	$(this).children('.tertiary-teaser-content').animate({height: '67px', paddingTop: '14px'}, {queue: false, duration: 200}, 'swing');
                    	$(this).children('.tertiary-teaser-content').children('p').animate({opacity: '0'}, {queue: false, duration: 200}, 'swing');
                    	
                    },
                    function(){
                    	$(this).find('.tertiary-teaser-bg-image').animate({top: '-89px'}, {queue: false, duration: 200}, 'swing');
                    	$(this).children('.tertiary-teaser-content').animate({height: '127px', paddingTop: '43px'}, {queue: false, duration: 200}, 'swing');
                    	$(this).children('.tertiary-teaser-content').children('p').animate({opacity: '1'}, {queue: false, duration: 200}, 'swing');
                    }
            );
			
			
			/*** Topic teaser hover ***/
			$('.topicTeaser .teaserItem').live('hover', function(event){
				$(this).toggleClass('hoverItem');
			});
			
			/*** Zoom content images (small + big) ***/
			if($(".zoom a, .teaserBox .zoom").length > 0){
				$(".zoom a, .teaserBox .zoom").fancybox({
					'hideOnContentClick': true,
					'titlePosition' 	: 'inside',
					'padding'		: 10,
					'titleShow'			: false,
					'overlayColor'	: '#000000',
					'overlayOpacity' : 0.6
				});
			}
			
			/*** Zoom ***/
			$(".teaserBox .openVideo, .videoTeaser .openVideo").click(function() {
				$.fancybox({
					'padding'		: 10,
					'overlayColor'	: '#000000',
					'overlayOpacity' : 0.6,
					'autoScale'		: false,
					'transitionIn'	: 'none',
					'transitionOut'	: 'none',
					'titleShow'		: false,
					'width'			: 500,
					'height'		: 281,
					'href'			: ivi.DOC_ROOT+'../static/flashvideoplayer/flashVideoPlayer.swf',
					'type'			: 'swf',
					'swf'			: {
					   	'wmode'		: 'transparent',
						'allowfullscreen'	: 'true',
						'flashvars'	: 'file='+this.href+'&controlbar=over&skin='+ivi.DOC_ROOT+'../static/flashvideoplayer/itze.zip'
					}
				});

			return false;
		});

		/*** Media Gallery ***/
		$('.mediaGallery .mediaThumb a').live('click', function(event){
			
			var selectedMediaThumb = $(this).parents('.mediaGallery .mediaThumb');
			var selectedMediaElement = $('.mediaGallery .mediaElement');
			
			if (!selectedMediaThumb.hasClass('active')) {				
			
				$('.mediaGallery .mediaThumb').removeClass('active');
				
				var mediaUrl = $(this).attr("href");
				var mediaTitle = $(this).parents('.mediaGallery .mediaThumb').find('.caption a').html();
				var mediaInfoCopy = $(this).parents('.mediaGallery .mediaThumb').find('.infocopy').html();
				var mediaPreviewImage = $(this).attr("rel");
				
				if (selectedMediaThumb.hasClass('picture')) {
					selectedMediaElement.html('<img src="'+ mediaUrl +'" alt="' + mediaTitle + '" />');
				}

				if (selectedMediaThumb.hasClass('video')) {
					selectedMediaElement.html('<div class="flashVideo"></div>');
					selectedMediaElement.find('.flashVideo').flash({
		                id:"flashVideo",
		                allowScriptAccess:"sameDomain",
		                src: "/media/static/flashvideoplayer/flashVideoPlayer.swf",
		                width: 500,
		                height: 281,
		                base: ".",
		                quality: "high",
		                menu: "false",
		                allowfullscreen: "true",
		                flashvars: {
							file: mediaUrl,
							image: mediaPreviewImage,
							controlbar: "over",
							skin: '/media/static/flashvideoplayer/itze.zip'
		                }
		            },
		            {
		                version: "9.0.115.0"
		            },
		            // Insert Flash Function
		            function(htmlOptions) {
		                $(this).addClass('flash-replaced');
		                $(this)[0].innerHTML=$.fn.flash.transform(htmlOptions);
		            },			            
		            // Noflash Alternative
		            function(htmlOptions) {
		                var noFlash= ivi.LABEL_NO_FLASH;
		                $(this).html(noFlash);
		            }
		            );					
				}

				if (selectedMediaThumb.hasClass('animation')) {
					selectedMediaElement.html('<div class="flashAnimation"></div>');
					
					selectedMediaElement.find('.flashAnimation').flash({
		                id:"flashAnimation",
		                allowScriptAccess:"sameDomain",
		                src: mediaUrl,
		                width: 500,
		                height: 281,
		                base: ".",
		                quality: "high",
		                menu: "false",
		                allowfullscreen: "true"
		            },
		            {
		                version: "9.0.115.0"
		            },
		            // Insert Flash Function
		            function(htmlOptions) {
		                $(this).addClass('flash-replaced');
		                $(this)[0].innerHTML=$.fn.flash.transform(htmlOptions);
		            },			            
		            // Noflash Alternative
		            function(htmlOptions) {
		                var noFlash= ivi.LABEL_NO_FLASH;
		                $(this).html(noFlash);
		            }			            
					);						
					
				}				
				
		        $('.mediaGallery .mediaText h6').html(mediaTitle);		        
		        $('.mediaGallery .mediaText div').html(mediaInfoCopy);

						// If Tool tip in info copy
				if($(".mediaGallery .mediaText div .tipAnchor").length > 0){
					$(".mediaGallery .mediaText div .tipAnchor").tipTip({defaultPosition: 'top'});
				}
		        $('.mediaGallery').find(".mediaThumb[lang='" + selectedMediaThumb.attr('lang') + "']").addClass('active');
 
				}
		        
		        return false;

		});	
			
		// selektiere das erste Element der Media-Galerie
		$($('.mediaGallery .mediaThumb').get(3)).find('a').trigger('click');

			
		/*** Gallery Teaser ***/
		$(".galleryTeaser .mediaThumb a").live('click', function(event){
		
			var pictures = [];
			var selectedIndex = 0;
			var i = 0;
			var selectedItemId = $(this).parents('.galleryTeaser .mediaThumb').attr('lang');
			
			$(this).parents('.galleryTeaser').find('.mediaThumb .image a').not('.cloned .image a').each(function(){

				var id = $(this).parents('.galleryTeaser .mediaThumb').attr('lang');
				var title = $(this).parents('.galleryTeaser .mediaThumb').find('.caption a').html();
				var infocopy = $(this).parents('.galleryTeaser .mediaThumb').find('.infocopy').html();
				
				pictures.push({
					'href' : $(this).attr('href'),
					'title' : '<h6>' + title + '</h6><div>' + infocopy + '</div>'
				});
				
				if (selectedItemId === id) {
					selectedIndex = i;
				}
				
				i++;
			});
			
			$.fancybox(pictures, {
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'titlePosition' 	: 'inside',
				'index'				: selectedIndex
			});
			
			return false;

		});	
			
			
			/*** videoTeaser with openMediaGallery ***/
			if($(".videoTeaser .openMediaGallery").length > 0){
				$(".videoTeaser .openMediaGallery").fancybox({
					'scrolling'			: 'no',
					'width'				: 500,
					'height'			: 555,
					'autoScale'			: false,
			        'transitionIn'		: 'fade',
					'transitionOut'		: 'fade',
					'type'				: 'iframe',
					'titleShow'			: false
				});
			}
		},
		
		initPlugins: function(){
			
			// Toggle label in search fields
			if($('input.txtField').length > 0){
				$('input.txtField').toggleLabel();
			}
			
			$("#search1").autocomplete(ivi.DOC_ROOT+'../../de/footernavigation/suche/suchvorschlaege.jsp', {
				width: 177,
				scroll: false,
				matchContains: true
			});
			
			$("#search2").autocomplete(ivi.DOC_ROOT+'../../de/footernavigation/suche/suchvorschlaege.jsp', {
				width: 162,
				scroll: false,
				matchContains: true
			});
	        
	        
	        // Tabbed navigation
			if($('.tabNav').length > 0){
				$('.tabNav').tabbedNav();
			}
			
	        // Folding boxes
			if($('.multiFolding, .singleFolding').length > 0){
		        $('.multiFolding, .singleFolding').advancedFlaps({
		        	toggling: false,
		        	openClass: 'openItem'
		        });
			}
			
			if($(".topicTeaser div.scrollable, .galleryTeaser div.scrollable, .mediaGallery div.scrollable").length > 0){
				$(".topicTeaser div.scrollable, .galleryTeaser div.scrollable, .mediaGallery div.scrollable").scrollable({
		        	size: 1,
		        	clickable: false,
		        	next: '.nonext',
		        	prev: '.noprev',
		        	nextPage: '.next',
		        	prevPage: '.prev'
	        	}).circular({size:3});
			}

	        // Tool tip
			if($(".tipAnchor").length > 0){
				$(".tipAnchor:not(.infocopy span.tipAnchor)").tipTip({defaultPosition: 'top'});
			}
			
			if($('.openHelpBox').length > 0){
				$('.openHelpBox').fancybox({
					'scrolling'			: 'auto',
					'width'				: 580,
					'height'			: 560,
					'autoScale'			: false,
			        'transitionIn'		: 'fade',
					'transitionOut'		: 'fade',
					'type'				: 'iframe',
					'titleShow'			: false
				});
			}
			
	        // Calender for forms
	        $.datepicker.regional[ivi.LANGUAGE] = {
	        		closeText: ivi.LABEL_CLOSE,
	        		prevText: ivi.LABEL_PREV,
	        		nextText: ivi.LABEL_NEXT,
	        		currentText: ivi.LABEL_CURRENT,
	        		monthNames: ivi.LABEL_MONTH_NAMES,
	        		monthNamesShort: ivi.LABEL_MONTH_NAMES_SHORT,
	        		dayNames: ivi.LABEL_DAY_NAMES,
	        		dayNamesShort: ivi.LABEL_DAY_NAMES_SHORT,
	        		dayNamesMin: ivi.LABEL_DAY_NAMES_MIN,
	        		weekHeader: ivi.LABEL_WEEK_HEADER,
	        		dateFormat: ivi.CAL_DATE_FORMAT,
	        		firstDay: 1,
	        		isRTL: false,
	        		showMonthAfterYear: false,
	        		yearSuffix: ''
	        		};
	        $.datepicker.setDefaults($.datepicker.regional[ivi.LANGUAGE]);
	        
	        // Calendar with 3 selects
	        if($(".dateHidden").length > 0){
		        $(".dateHidden").datepicker({
					showOn: 'button',
					buttonImage: ivi.DOC_ROOT + ivi.CALENDAR_ICON_SRC,
					buttonImageOnly: true,
					showButtonPanel: true,
					onSelect: function(date, inst){
		        		var isoDate = $.datepicker.parseDate(ivi.CAL_DATE_FORMAT,date);
		        		$(this).prevAll('select.year').find('option').each(function(index, item){
		        			if($(item).val() == $.datepicker.formatDate('yy',isoDate)){
		        				$(item).attr('selected', 'selected');
		        			}
		        		});
		        		$(this).prevAll('select.month').find('option').each(function(index, item){
		        			if($(item).val() == $.datepicker.formatDate('mm',isoDate)){
		        				$(item).attr('selected', 'selected');
		        			}
		        		});
		        		$(this).prevAll('select.day').find('option').each(function(index, item){
		        			if($(item).val() == $.datepicker.formatDate('dd',isoDate)){
		        				$(item).attr('selected', 'selected');
		        			}
		        		});
		        		
		        	}
				});
	         
	        }
	        // Calendar with 1 input field
	        if($(".dateInput").length > 0){
		        $(".dateInput").datepicker({
					showOn: 'both',
					buttonImage: ivi.DOC_ROOT + ivi.CALENDAR_ICON_SRC,
					buttonImageOnly: true,
					showButtonPanel: true
				});	
	        }

	        if(typeof maxDates != 'undefined'){
	        	$.each(maxDates, function(elemId, date){
	        		$('#'+elemId).datepicker("option", "maxDate", date)
	        	});
	        }
	        
	        if(typeof minDates != 'undefined'){
	        	$.each(minDates, function(elemId, date){
	        		$('#'+elemId).datepicker("option", "minDate", date)
	        	});
	        }	        
	        
		},
		
		initAjaxSelectors: function() {
			// On change
			$('.selectCat').change(function(){
					ivi.getJsonData($(this).attr('lang'));
				});
			// On document ready
			if($('select#cat1').length > 0){
				ivi.getJsonData($('select#cat1').attr('lang'))
			};
			
		},
		
		
		//Infinite loop for the seals display
		infiniteLoop:function(anchors, timeOut){
		    for(var i = 0; i < anchors.length ;i++){	       
		        if(!$(anchors[i]).hasClass("invisible") ){
		            $(anchors[i]).addClass("invisible"); 
		            if( i < (anchors.length -1)){
		                $(anchors[i+1]).removeClass("invisible");
		            } else {
		                $(anchors[0]).removeClass("invisible");
		            }
		            break;
		        }
		     }
		     window.setTimeout(function(){ ivi.infiniteLoop(anchors,timeOut); }, timeOut);
		},
		
		//Operate the seals display
		rotateImages: function(){ 
		     $(".articleHead .rotaryImage").each(function(){
		         var anchors = $(this).children().filter("a");
		         var timeOut=ivi.SEAL_INTERVAL;
		         window.setTimeout(function(){ ivi.infiniteLoop(anchors,timeOut); }, timeOut);     
		     });
		     
		     $("#popUp .rotaryImage").each(function(){
		         var anchors = $(this).children().filter("a");
		         var timeOut=ivi.SEAL_INTERVAL;
		         window.setTimeout(function(){ ivi.infiniteLoop(anchors,timeOut); }, timeOut);     
		     });
		},
		
		// Ajax selectors
		ajaxEventHandler: function(url,params,callbackFuncSuccess,callbackFuncError,historyParam){
			$.ajax({
				   type: "GET",
				   url: encodeURI(url+params),
				   dataType: "json",
				   timeout: 20000,
				   error: function (XMLHttpRequest, textStatus, errorThrown) {
					   callbackFuncError(textStatus);
					   ivi.hideOverlay();
				   },
				   success: function(data,textStatus){
					   callbackFuncSuccess(data);
					   ivi.hideOverlay();
				   },
				   complete: function (XMLHttpRequest, textStatus) {
					   
				   }
			});
		},
		
		showOverlay: function(){

			$(".wrapper").append('<div id="wait"><img src="'+ivi.LOADING_GIF+'" alt=""/></div>');
			$("#wait").children().css({ 
				display:"block",
				marginTop: $(window).height()/2+'px',
				marginLeft: $(window).width()/2+'px'
				});

		},
		
		hideOverlay: function() {
			$("#wait").remove();
		},
		
		// Get params for selcetor ajax-request
		getParams: function(qType){
		    var params ='?type='+qType;

		    $('.selectCat').each(function(index){
		    		var thisSelect = this;
		    		params = params+'&'+$(thisSelect).attr("name")+'='+$(thisSelect).val();
		    });

		    return params;
		},
		
		// Get params for selcetor ajax event-handler
		getJsonData: function(qType){
			// TODO: Enter real Urls
			var requestUrl;
			if(qType == "jobs"){
				requestUrl = "http://www.itzehoer.de/de/metanavigation/karriere/jobsjson.jsp";
			} else if(qType == "press"){
				requestUrl = "http://www.itzehoer.de/de/metanavigation/presse/pressemeldungen/pressjson.jsp";
			} else {
				requestUrl = "http://www.itzehoer.de/de/metanavigation/presse/termine/terminjson.jsp";
			}
			ivi.showOverlay();

			ivi.ajaxEventHandler(requestUrl, ivi.getParams(qType), ivi.updateResults, ivi.showError, false);
			
		},
		
		// Update search results in press, career & events tables
		updateResults: function(jsonObj) {

			var options = {
					num_display_entries:4,
		    		current_page:0,
		    		num_edge_entries:1,
		    		link_to:"javascript:void(0);",
		    		prev_text:"&nbsp;",
		    		next_text:"&nbsp;",
		    		ellipse_text:"...",
		    		prev_show_always: true,
		    		next_show_always: true,
		    		callback: function(currentPage, containers){
						ivi.generateItems(currentPage, jsonObj);
					}
			};

			if(null != jsonObj) {
			
				if(jsonObj.size == '0'){
					$('.paging').hide();

					if(jsonObj.type == 'jobs'){
						$('.jobsCollection').html('<p style="color:#fa0000;padding: 30px 0 0 0;">'+ivi.JOB_SELECTOR_NO_DATA_ERROR+'</p>');
					}
					if(jsonObj.type == 'events'){
						$('.eventsCollect .itemCollection tbody').html('<tr><td colspan="4"><p style="color:#fa0000;padding: 30px 0 0 0;">'+ivi.EVENTS_SELECTOR_NO_DATA_ERROR+'</p></td></tr>');
					}
					if(jsonObj.type == 'press'){
						$('.pressReleases .itemCollection').html('<p style="color:#fa0000;padding: 30px 0 0 0;">'+ivi.PRESS_SELECTOR_NO_DATA_ERROR+'</p>');
					}
				}else{
					$('.paging').show();
				
					if(jsonObj.type == 'jobs'){
						options.items_per_page = ivi.ITEMS_PER_PAGE_CAREER;
						$(".jobOffers .paging").pagination(jsonObj.size, options);
					}
					
					if(jsonObj.type == 'press'){
						options.items_per_page = ivi.ITEMS_PER_PAGE_PRESS;
						$(".pressReleases .paging").pagination(jsonObj.size, options)
					}
					
					if(jsonObj.type == 'events'){
						options.items_per_page = ivi.ITEMS_PER_PAGE_EVENTS;
						$(".eventsCollect .paging").pagination(jsonObj.size, options)
					}
				}
			}
			
		},

		// Handle Errors
		showError: function(textStatus) {

				$('.paging').hide();
			
				var errorString = ivi.SELECTOR_ERROR;
			
				if (textStatus == 'notmodified') {
					errorString = ivi.SELECTOR_NOTMODIFIED_ERROR;
				} else if(textStatus == 'timeout') {
					errorString = ivi.SELECTOR_TIMEOUT_ERROR;
				} else if(textStatus == 'parsererror') {
					errorString = ivi.SELECTOR_PARSE_ERROR;
				}
				
				var errorHtml = '<p style="color:#fa0000;padding: 30px 0 0 0;">'+errorString+'</p>';
				
				if($('.jobsCollection').length > 0){
					$('.jobsCollection').html(errorHtml);
				}
				if($('.eventsCollect').length > 0){
					$('.eventsCollect .itemCollection tbody').html('<tr><td colspan="4">'+errorHtml+'</td></tr>');
				}
				if($('.pressReleases').length > 0){
					$('.pressReleases .itemCollection').html(errorHtml);
				}
		
		},	
		
		// Generate single items in press, career & events tables
		generateItems: function(pageIndex, jsonData){

			  var itemsPerPage = 0;
			  
			  if(jsonData.type == 'jobs'){
				  itemsPerPage = ivi.ITEMS_PER_PAGE_CAREER;
			  }
			  if(jsonData.type == 'press'){
				  itemsPerPage = ivi.ITEMS_PER_PAGE_PRESS;
			  }
			  if(jsonData.type == 'events'){
				  itemsPerPage = ivi.ITEMS_PER_PAGE_EVENTS;
			  }
			  
			  var max_elem = Math.min((pageIndex+1) * itemsPerPage, jsonData.size);
			  var newcontent = '';
			  
			  if(jsonData.type == 'jobs'){
				// Iterate through a selection of the content and build an HTML string
				  for(var i = pageIndex * itemsPerPage; i < max_elem; i++) {
						if (jsonData.items[i][3].indexOf("Ausbildung") == -1)
						{
							newcontent += '<div class="job">'
										+'<h5>'
											+'<span class="jobDate">'+jsonData.items[i][0]+'</span>'
											+'<span class="jobLocation">'+jsonData.items[i][1]+'</span>'
											+'<span class="jobPosition">'+jsonData.items[i][2]+'</span>'
											+'<span class="jobTitle">'+jsonData.items[i][3]+'</span>'
										+'</h5>';
							if (jsonData.items[i][5] != "")
							{
								newcontent += '<h4><a href="'+jsonData.items[i][5]+'">'+jsonData.items[i][4]+'</a></h4>';
							}
							else
							{
								newcontent += '<h4>'+jsonData.items[i][4]+'</h4>';
							}
							newcontent += '</div>';
						}
						else
						{
							newcontent += '<div class="job">'
										+'<h5>'
											+'<span class="jobDate">'+jsonData.items[i][0]+'</span>'
											+'<span class="jobTitle">'+jsonData.items[i][1]+'</span>'
										+'</h5>';
							if (jsonData.items[i][5] != "")
							{
								newcontent += '<h4><a href="'+jsonData.items[i][5]+'">'+jsonData.items[i][4]+'</a></h4>';
							}
							else
							{
								newcontent += '<h4>'+jsonData.items[i][4]+'</h4>';
							}
							newcontent += '</div>';
						}
				  }
				  
				  // Replace old content with new content
				  $('.jobsCollection').html(newcontent);
			  }
			  
			  if(jsonData.type == 'press'){
				  // Iterate through a selection of the content and build an HTML string
				  for(var i = pageIndex * itemsPerPage; i < max_elem; i++) {
						if (jsonData.items[i][5] != "") {
							newcontent += '<div class="item">'
										+'<div class="runaroundLeft">'
											+'<img width="100" alt="'+jsonData.items[i][2]+'" src="'+jsonData.items[i][4]+'"/>'
										+'</div>'
										+'<div>'
											+'<h5>'+jsonData.items[i][0]+', '+jsonData.items[i][1]+'</h5>'
											+'<h4><a href="'+jsonData.items[i][5]+'">'+jsonData.items[i][2]+'</a></h4>'
											+'<p><a href="'+jsonData.items[i][5]+'">'+jsonData.items[i][3]+'</a></p>'
											+'<a class="arrowLink" href="'+jsonData.items[i][5]+'">'+ivi.TEXT_MORE_LINK+'</a>'
										+'</div>'
									+'</div>';
						}
						else
						{
							newcontent += '<div class="item">'
										+'<div class="runaroundLeft">';
							if (jsonData.items[i][4] != "") {
								newcontent += '<img width="100" alt="'+jsonData.items[i][2]+'" src="'+jsonData.items[i][4]+'"/>';
							}
							else {
								newcontent += '<img width="100" alt="'+jsonData.items[i][2]+'" src="http://www.itzehoer.de/media/presse_1/presse-default.jpg"/>';
							}
							newcontent	+= '</div>'
										+'<div>'
											+'<h5>'+jsonData.items[i][0]+', '+jsonData.items[i][1]+'</h5>'
											+'<h4>'+jsonData.items[i][2]+'</h4>'
											+'<p>'+jsonData.items[i][3]+'</p>'
										+'</div>'
									+'</div>';
						}
				  }
				  
				  // Replace old content with new content
				  $('.pressReleases .itemCollection').html(newcontent);
			  }
			  
			  if(jsonData.type == 'events'){
				  var moreLink = '';
				  // Iterate through a selection of the content and build an HTML string
				  for(var i = pageIndex * itemsPerPage; i < max_elem; i++) {
					  // generate more-link if needed
					  if(jsonData.items[i][3] != ''){
						  moreLink = '<a class="arrowLink" href="'+jsonData.items[i][3]+'">'+ivi.TEXT_MORE_LINK+'</a>'
					  }
					  newcontent += '<tr>'
										+'<td>'+jsonData.items[i][1]+'</td>' /*Datum, Uhrzeit*/
										+'<td>'+jsonData.items[i][2]+'</td>' /* Headline */
										+'<td>'+jsonData.items[i][0]+'</td>' /* Ort */
										+'<td>'+moreLink+'</td>' /* Link */
									+'</tr>';
					  moreLink = '';
				  }
				  
				  // Replace old content with new content
				  $('.eventsCollect .itemCollection .eventsOverview tbody').html(newcontent);
			  }
			  
			  // Resize content height after content replacement
			  if(($('#marginColumn .teaserBox').height()-185) < ($('#contentBox .centerCol').height()+40)){
				 $('#contentBox .innerBox').height($('#contentBox .centerCol').height());
			  }
			  
			  // Prevent click eventpropagation
			  return false;
		},
		
		openWindow: function(url){
    	
    		popUp = window.open(url, "_blank", "width=855,height=680,status=yes,scrollbars=yes,resizable=yes,menubar=yes,location=yes");
    		popUp.focus();
    		return false;
    		
		}
		
    })
    /* page load */
    $().ready(function() {
    	ivi.init();
    });
}

