/**
 * @author bastianw
 */
$(document).ready(function() {
    function findValueCallback(event, data, formatted) {
        $("<li>").html(!data ? "No match!" : "Selected: " + formatted).appendTo("#result");
    }
    
    function formatItem(row) {
        return row[0] + " (<strong>id: " + row[1] + "</strong>)";
    }
    function formatResult(row) {
        return row[0].replace(/(<.+?>)/gi, '');
    }
    
    bwImageSlider.init();
	if (typeof(keywords) != 'undefined') {
		glossarsearch.init();
	}
    glossarTooltip.parseLinks();
    bwAccNavigation.init();
    bwRoundUpCorners.init();
    bwPrioBoxRow.init();
	briefkasten.init();
	bwHeaderSwitch.init();
	
     // Tabelle Caption runde Ecken	
    $('.CCHEE11 table caption').prepend('<span></span>');
	
	
	 if (window.opera && window.opera.version && parseFloat(window.opera.version()) < 9.6) {
        var elems = document.getElementsByClassName('radiobuttonTable');
        for (var i = 0; i < elems.length; i++) {
            elems[i].style.cssFloat = "none";
        }
    }
	
	$("#search-teaser-text").DefaultValue("Suche...");			
			$("html.de #nachhaltigkeit-glossar-topsearch").DefaultValue("Glossar Suchbegriff eingeben");
			$("html.fr #nachhaltigkeit-glossar-topsearch").DefaultValue("Entrez le terme &agrave; rechercher dans le glossaire ");
			$("html.it #nachhaltigkeit-glossar-topsearch").DefaultValue("Inserire il termine di ricerca nel glossario");
			$("html.en #nachhaltigkeit-glossar-topsearch").DefaultValue("Glossar Suchbegriff eingeben");
			
			$('.open-close').click(function() { 
				if ($(this).hasClass('active')){
					$(this).removeClass('active');
				} else {
					$(this).addClass('active');
				}
								
				$(this).parent().parent().find('.hiddencontent').slideToggle(500,function() {									
					return false;								
				});
				return false;
								
			});
			
			   $('ul.tabNav a').click(function(){
                    var curChildIndex = $(this).parent().prevAll().length + 2;
                    
                    $(this).parent().parent().children('.current').removeClass('current');
                    $(this).parent().addClass('current');
				//$(this).parent().parent().next('.tabContainer').children('.tabContentBG').children('.scrollContent').children('.current').slideUp('fast', function(){
                    $(this).parent().parent().next('.tabContainer').find('.scrollContent').children('.current').slideUp(1, function(){
                        $(this).removeClass('current');
                        $(this).parent().children('div:nth-child(' + curChildIndex + ')').slideDown(1, function(){
                            $(this).addClass('current');
                        });
                    });
                    
                    return false;
                });

		$('.NACHH_Header_standard').next('br').remove();
			
		
	
});


var bwHeaderSwitch = {
	
	init: function () {
		var elements = ["NACHH_Lebenswelt", "greenBackground", "alleThemen_Einleitung"];
		nextElement = $('#content-container .NACHH_Header_standard').next().attr('class');
		$.each(elements, function() {
			if(nextElement === ''+this) {
				if (nextElement === 'NACHH_Lebenswelt') {
				
					if ($('.NACHH_Lebenswelt div:first').attr('id') === 'lebenswelt_energiesparen') {
						$('#content-container .NACHH_Header_standard').find('.border_bottom_white').addClass('border_bottom_grey').removeClass('border_bottom_white');
						console.log('setting grey');
					}
					else {
						$('#content-container .NACHH_Header_standard').find('.border_bottom_white').addClass('border_bottom_green').removeClass('border_bottom_white');
					}
				}
				else {
					$('#content-container .NACHH_Header_standard').find('.border_bottom_white').addClass('border_bottom_green').removeClass('border_bottom_white');
				}
			}
        });
	}
	
}

var briefkasten = {
    init: function() {
        $('#gallery-briefkasten-layer').find('div.close a').click(function() {
            $.unblockUI();
			$('.blockUI').hide();
			
			$('#briefkastenForm').children(':not(.bottom, .close)').each(function(index) {
    			$(this).css( "visibility", "visible" );
  			});
    		$('#briefkastenResponse').remove();
			
			return false;
        });
        
        $('a.briefkasten').click(function() {
        	var backgroundImageUrl = "../image/nachhaltigkeit/bg_briefkasten_layer.png" 
        	if (document.location.protocol=="http:") {
        		//backgroundImageUrl = "/pb/site/nachhaltigkeit/resourceCached/1/common/image/nachhaltigkeit/bg_briefkasten_layer.png";
        		backgroundImageUrl = $('#briefkastenBackground').val();
        	} 
            $.blockUI({
                message: $('#gallery-briefkasten-layer'),
                css: {
                    position: 'fixed',
                    top: '50px',
                    left: '50px',
                    border: 'none',
                    width: '516px',
                    height: 'auto',
                    cursor: 'default',
                    backgroundImage: 'url(' + backgroundImageUrl + ')', 
                    backgroundColor: 'transparent',
                    backgroundRepeat: 'no-repeat',
                    padding: '60px 19px 0 15px'
                },
                overlayCSS: {
                    backgroundColor: '#000000',
                    opacity: '0.7'
                },
                fadeIn: 250,
                fadeOut: 250
            });
			return false;
        });
    }
}





var glossarsearch = {
    init: function() {

        $("#nachhaltigkeit-glossar-topsearch").autocomplete(keywords, {
            width: '177px',
            minChars: 0,
            matchContains: false,
            max: 5,
            autoFill: true,
            mustMatch: false,
            formatItem: function(row, i, max) {
                $('#nachhaltigkeit-direktlinks').find('.popout').slideUp();
                return '<span rel="' + row.url + '">' + row.name + '</span>';
            },
            formatMatch: function(row, i, max) {
                return row.name;
            },
            formatResult: function(row, max) {
                return row.name;
            }
        })
		.after('<input type="hidden" name="url" id="asc_result" value="" />').result(function(e, row) {
            // call tooltip function
            var offset = $(this).offset();
            glossarTooltip.open(row.url, true, offset.top, offset.left);
            $('#ac_result').val(row.url);
        });
		
		
	    $("#nachhaltigkeit-glossar-topsearch").parent().submit(function() {
            return false;
        });
        
        $('#nachhaltigkeit-direktlinks').click(function() {
            $(this).find('.popout').slideToggle();
        });
        $('#nachhaltigkeit-direktlinks li').click(function() {
            location.href = $(this).find('span').attr('rel');
        });
		
		
		// set no-match messagebox
		var messDom;
		if ($('html.fr').size() > 0) {
			messDom = $('<div class="ac_noResults">Aucun r&eacute;sultat n\'a &eacute;t&eacute; trouv&eacute;.</div>');
		} else if($('html.it').size() >0) {
			messDom = $('<div class="ac_noResults">Non &egrave; stato trovato alcun termine corrispondente.</div>');
		} else {
			messDom = $('<div class="ac_noResults">Es wurde kein passender Begriff gefunden.</div>');
		}
		messDom.css('background','#fff');
		messDom.css('display', 'none');
		messDom.css('position', 'absolute');
		messDom.css('width', '167px');
		messDom.css('top', '179px');
		messDom.css('left', '455px');
		messDom.css('z-index', '100');
		messDom.css('padding', '5px');
		$('body').append(messDom);
		
		$("#nachhaltigkeit-glossar-topsearch").keyup(function () {
			if ( ($('body').find('div.ac_results').html() == null) || ($('body').find('.ac_even').html()) == null) {
				$('.glossarTT').fadeOut(150, function() {
                    ttDom.find('.content').html(' ');
                });
				messDom.css('display', 'block');
			}
			else messDom.css('display', 'none');
		});
		
		$("#nachhaltigkeit-glossar-topsearch").blur(function () {
			messDom.css('display', 'none');
		});
		
		
    }
}


var glossarTooltip = {

    open: function(url, topsearch, offsetTop, offsetLeft) {
        if (topsearch === true) {
            offsetTop += 30;
        }
        $.ajax({
            url: url,
            cache: true,
            success: function(html) {
                if ($('.glossarTT').size() > 0) {
                    glossarTooltip.openTooltip(html, offsetTop, offsetLeft);
                }
                else {
                    glossarTooltip.createDOM(html, offsetTop, offsetLeft);
                }
            },
            timeout: 5000,
            error: function(request, error) {

            }
        });
    },
    
    createDOM: function(content, offsetTop, offsetLeft) {
        //console.log('create dom with'+content);
        ttDom = $('<div class="glossarTT"><div class="close"><span>close</span></div><div class="content"></div></div>');
        ttDom.find('.content').html(content);
        ttDom.find('.close').click(function() {
            $(this).parent().fadeOut(150, function() {
                ttDom.find('.content').html(' ');
            });
        })
        ttDom.css('display', 'none');
        ttDom.css('left', offsetLeft + 'px');
        ttDom.css('top', offsetTop + 'px').fadeIn(500);
        $('body').append(ttDom);
    },
    
    openTooltip: function(content, offsetTop, offsetLeft) {
        //console.log('open tooltip with'+content)
        
        tt = $('.glossarTT');
        tt.find('.content').html(content);
        tt.css('left', offsetLeft + 'px');
        tt.css('top', offsetTop + 'px').fadeIn(500);
    },
    
    parseLinks: function() {
        $('.glossarlink').each(function() {

            $(this).click(function() {
                var offset = $(this).offset();
                var offsetLeft = offset.left + 10;
                var offsetTop = offset.top + 20;
                glossarTooltip.open($(this).attr('rel'), false, offsetTop, offsetLeft);
            });
			
			/*
            $(this).mouseover(function() {
                var offset = $(this).offset();
                var offsetLeft = offset.left + 10;
                var offsetTop = offset.top + 20;
                glossarTooltip.open($(this).attr('rel'), false, offsetTop, offsetLeft);
            }, function() {
                $('.glossarTT').fadeOut(150, function() {
                    ttDom.find('.content').html(' ');
                });
                
            });
            */
            
        });
    }
}


var bwAccNavigation = {

    init: function() {
        $('.NACHH-accordNav_267').each(function(i, jObj) {
			if ($(jObj).find('li').size() === 1) {
				$('li:first', jObj).addClass('active');
				$('li:first .media', jObj).slideDown(500);
				$('li:first .link', jObj).slideDown(500);
			}
			else {
				$('li:first', jObj).addClass('active');
				$('li:first .media', jObj).slideDown(500);
				$('li:first .link', jObj).slideDown(500);
				bwAccNavigation.setTimer(jObj, i)
				bwAccNavigation.setHandler(jObj, i);
			}
        });
    },
    
	
    setHandler: function(jObj, i) {

		var allNews = $(jObj).find('li');
		allNews.each(function() {
			
			$(this).find('.header').mouseover(function(){
				bwAccNavigation.stopTimer();				

				var tc = $(this).parent().find('.media').attr('class');
				
				allNews.each(function() {
					$(this).find('.media').slideUp(500);
					$(this).find('.media').removeClass('active');
				});			
				
				if (tc != 'media active') {
					$(this).parent().find('.media').slideDown(500);
					$(this).parent().find('.media').addClass('active');		
				}
				else bwAccNavigation.startTimer();			
			});
		});
/*		
        $(jObj).find('li').each(function(ii, jObjInner) {
            $(this, jObjInner).attr('id', 'navAccElement-' + i + '-' + ii);
            $(this, jObjInner).mouseover(function() {

                activeid = $(this).parent().find('li.active').attr('id');
                if (activeid != $(this).attr('id')) {
                    $('#' + activeid + ' .media').slideUp(500, function() {
						$('#' + activeid + ' .link').hide();
					});
					$('#' + activeid + ' .link').slideUp(500, function() {
						$('#' + activeid + ' .link').hide();
					});
                    $(this).find('.media').slideDown(500);
					$(this).find('.link').slideDown(500);
                    $('#' + activeid).removeClass('active');
                    $(this).addClass('active');
                }
                else {
                    // nüscht
                }
            });
        });
*/
        
    },

	setTimer: function (jObj) {
		this.setElNum(1);
		this.el = jObj;
		this.startTimer();
	},
	startTimer: function() {
		
		this.interval = setInterval("bwAccNavigation.aniBW()",2500);
	},
	stopTimer: function() {
		clearInterval(this.interval);
	},
	setElNum: function (v) {
		this.elNum = v;
	},
	getElNum: function (v) {
		return this.elNum;
	},
	aniBW: function (jObj) {

		if ($(this.el).find('li').size() === this.elNum) {
			var curEl = $(this.el).find('li')[0]; // aktives element holen
			var preEl = $(this.el).find('li')[$(this.el).find('li').size()-1];
		}
		else {
			var curEl = $(this.el).find('li')[this.elNum]; // aktives element holen
			var preEl = $(this.el).find('li')[this.elNum - 1];
		}
		$(curEl).slideDown(500, function() {
					$(this).find('.media').slideDown(500);
					$(this).addClass('active');
					}
		);

		$(preEl).slideDown(500, function() {
					$(this).find('.media').slideUp(500);
					$(this).removeClass('active');
					}
		);

		if ($(this.el).find('li').length == this.elNum) this.elNum = 0
		else this.elNum++;
	}
}




var bwImageSlider = {

    init: function() {
			
		bwImageSlider.countImages();
		
        $('.NACHH-galleryslide_267').each(function(i, jObj) {
            gC = $(jObj);
            gCStage = $(jObj).find('.imageslider-stage');

            
            bild2 = gC.find('.imageslider ul li:first div.previewdata img');
            gCStage.html($(gC).find('.imageslider ul li:first div.previewdata').html());
            gC.find('.imageslider ul li:first').addClass('active');
            bwImageSlider.setCounter(jObj);
			
			// close mit "ESC"
			gC.bind('keydown',  function(e) {
			if (parseInt(e.which) == 27 ) {
				$.unblockUI();
	            return false;
			}
			});
        });
    },
    
    countImages: function() {
				$('.NACHH-galleryslide_267').each(function(i, jObj) {
					$(jObj).find('.imageslider ul li').each(function(ii, jObjInner) {
						$(this, jObjInner).attr('id', 'image-' + (i + 1)+'-' + (ii + 1));
					});
				});
		
    },
    
    setCounter: function(jObj) {
       		
            gcCounter = $(jObj).find('.imageCounter');
            gcStage = $(jObj).find('.imageslider-stage');
            imageList = $(jObj).find('ul');
            totalImages = $(jObj).find('ul li').size();

			
            if (totalImages > 0) {
                gcCounter.html('1/' + totalImages);
                if (totalImages > 1) {
                    $(jObj).find('.imageSlideControl').html('<a href="#" class="backwards"><b>back</b></a><a href="#" class="forward"><b>next</b></a><a href="#" class="zoom"><b>zoom</b></a><br clear="all" />');
                    
                    detailViewLayer = $('<div id="gallery-detail-layer">' +
                    '	<div class="close"><a href="#">schliessen</a></div>' +
                    '	<div class="header"></div>' +
                    '	<div class="counter"></div>' +
                    '	<div class="image-container">' +
                    '		<div class="backward"><a href="#"><b>backward</b></a></div>' +
                    '		<div class="image"></div>' +
                    '		<div class="forward"><a href="#"><b>forward</b></a></div>' +
                    '	</div>' +
                    '	<div class="text"><p>Lorem Ipsum dolor sit amet, Lorem Ipsum dolor sit amet, Lorem Ipsum dolor sit amet, Lorem Ipsum dolor sit amet, Lorem Ipsum dolor sit amet, Lorem Ipsum dolor sit amet</p>' +
                    '	<div class="download">Download <a href="#">Druck (1024kB)</a></div></div>' +
                    '</div>' +
                    '').css('display', 'none');
                    
                    $('body').prepend(detailViewLayer);
                    
                    $(detailViewLayer).find('div.close a').click(function() {
                        $.unblockUI();
						/* fix - unbind of clicks needed */
						$('.forward a').unbind('click');
						$('.backward a').unbind('click');
                        return false;
                    });
					
					// close mit "ESC"
					$(detailViewLayer).bind('keydown',  function(e) {
						if (parseInt(e.which) == 27 ) {
							$.unblockUI();
							/* fix - unbind of clicks needed */
							$('.forward a').unbind('click');
							$('.backward a').unbind('click');
	                        return false;
						}
					});
					
                    $('.imageSlideControl .zoom', jObj).click(function() {
						gcCounter = $(jObj).find('.imageCounter');
			            gcStage = $(jObj).find('.imageslider-stage');
			            imageList = $(jObj).find('ul');
			            totalImages = $(jObj).find('ul li').size();
			
						
                        fulldata = imageList.find('li.active .fulldata');
                        image = $(fulldata).find('.image').html();
						
                        subtitle = $(fulldata).find('.subtitle').html();
                        download = $(fulldata).find('.download').html();
                        headline = $(fulldata).find('.header').html();
						
                        currentImageNumber = $(fulldata).parent().attr('id');
						var re = new RegExp("image-([1-9]+)-");
                        currentImageNumber = currentImageNumber.replace(re, '');
                        $('.counter', detailViewLayer).html(currentImageNumber + '/' + totalImages);
                        
                        
                        $('.image',detailViewLayer).html(image);
                        $('.text p',detailViewLayer).html(subtitle);
                        $('.header',detailViewLayer).html(headline);
                        $('.download',detailViewLayer).html(download);
                        
						
						$('.forward a', detailViewLayer).click(function() {
							gcCounter = $(jObj).find('.imageCounter');
				            gcStage = $(jObj).find('.imageslider-stage');
				            imageList = $(jObj).find('ul');
							fulldata = imageList.find('li.active .fulldata');
				            totalImages = $(jObj).find('ul li').size();
							
                            activeImage = $(fulldata).parent().parent().find('.active');
							nextImage = activeImage.next();
                            if (nextImage.size() == 0) {
                                nextImage = activeImage.parent().find('li:first');
                            }
                            activeImage.removeClass('active');
                            nextImage.addClass('active');
                            fulldata = imageList.find('li.active .fulldata');
                            image = $(fulldata).find('.image').html();
                            subtitle = $(fulldata).find('.subtitle').html();
							headline = $(fulldata).find('.header').html();
                            download = $(fulldata).find('.download').html();
                            nextImageNumber = nextImage.attr('id');
							var re = new RegExp("image-([1-9]+)-");
                            nextImageNumber = nextImageNumber.replace(re, '');
                            $('.counter',detailViewLayer).html(nextImageNumber + '/' + totalImages);
                            
                            $('.image',detailViewLayer).html(image);
                            $('.text p',detailViewLayer).html(subtitle);
                            $('.header',detailViewLayer).html(headline);
                            $('.download',detailViewLayer).html(download);
  
							
                            return false;
                        });
                        

                        $('.backward a', detailViewLayer).click(function() {
							gcCounter = $(jObj).find('.imageCounter');
				            gcStage = $(jObj).find('.imageslider-stage');
				            imageList = $(jObj).find('ul');
							fulldata = imageList.find('li.active .fulldata');
				            totalImages = $(jObj).find('ul li').size();
							
                            activeImage = $(fulldata).parent().parent().find('.active');
                            prevImage = activeImage.prev();
							
                            if (prevImage.size() == 0) {
                                prevImage = activeImage.parent().find('li:last');
                            }
                            activeImage.removeClass('active');
							prevImage.addClass('active');
                            fulldata = imageList.find('li.active .fulldata');
                            image = $(fulldata).find('.image').html();
                            subtitle = $(fulldata).find('.subtitle').html();
							headline = $(fulldata).find('.header').html();
                            download = $(fulldata).find('.download').html();
                            prevImageNumber = prevImage.attr('id');
							var re = new RegExp("image-([1-9]+)-");
                            prevImageNumber = prevImageNumber.replace(re, '');
                            $('.counter',detailViewLayer).html(prevImageNumber + '/' + totalImages);
                            
                            $('.image',detailViewLayer).html(image);
                            $('.text p',detailViewLayer).html(subtitle);
                            $('.header',detailViewLayer).html(headline);
                            $('.download',detailViewLayer).html(download);							
                            							
                            return false;
                            
                        });
						
						
						
						
                        $.blockUI({
                            message: $(detailViewLayer),
                            css: {
                                position: 'fixed',
                                top: '50px',
                                left: '50px',
                                border: 'none',
                                width: '685px',
                                height: '534px',
                                cursor: 'default',
                                backgroundImage: 'url(../image/nachhaltigkeit/bg_gallery_layer.png)',
                                backgroundRepeat: 'no-repeat',
                                padding: '20px'
                            },
                            overlayCSS: {
                                backgroundColor: '#000',
                                opacity: '0.7'
                            },
                            fadeIn: 250,
                            fadeOut: 250

                        });
					

                        return false;
                    });
                    


                    
                    $('.imageSlideControl .backwards', jObj).click(function() {
                        gcCounter = $(jObj).find('.imageCounter');
			            gcStage = $(jObj).find('.imageslider-stage');
			            imageList = $(jObj).find('ul');
			            totalImages = $(jObj).find('ul li').size();
						activeImage = imageList.find('li.active');
                        prevImage = activeImage.prev();
                        if (prevImage.size() == 0) {
                            prevImage = activeImage.parent().find('li:last');
                        }
                        activeImage.removeClass('active');
                        prevImage.addClass('active');
                        gcStage.html(imageList.find('li.active div.previewdata').html());
                        prevImageNumber = prevImage.attr('id');
						var re = new RegExp("image-([1-9]+)-");
                        prevImageNumber = prevImageNumber.replace(re, '');
                        gcCounter.html(prevImageNumber + '/' + totalImages);
                        return false;
                    });
                     $('.imageSlideControl .forward', jObj).click(function() {
						gcCounter = $(jObj).find('.imageCounter');
			            gcStage = $(jObj).find('.imageslider-stage');
			            imageList = $(jObj).find('ul');
			            totalImages = $(jObj).find('ul li').size();
                        activeImage = imageList.find('li.active');
                        nextImage = activeImage.next();
                        if (nextImage.size() == 0) {
                            nextImage = activeImage.parent().find('li:first');
                            
                        }
                        activeImage.removeClass('active');
                        nextImage.addClass('active');
                        gcStage.html(imageList.find('li.active div.previewdata').html());
                        nextImageNumber = nextImage.attr('id');
						var re = new RegExp("image-([1-9]+)-");
                        nextImageNumber = nextImageNumber.replace(re, '');
                        gcCounter.html(nextImageNumber + '/' + totalImages);
                        
                        return false;
                    });
                    
                }
            }
            		
		
    },
	
			
    
    nextImage: function(jObj) {

            activeImage = $(jObj).find('li.active');
        
    }
    
    
   
}


var bwRoundUpCorners = {

    init: function() {
        var elements = [".NACHH-accordNav_267", ".boxprio1v1_820", ".boxprio1v2_820", ".boxprio1v3_405", ".boxprio1v4_405", ".boxprio2v1_405", ".boxprio2v2_405", ".boxprio3v2_267", ".boxprio3v1_267", ".boxprio3v3_267", ".boxprio3v6", ".box_nachhaltig_download_405", ".NACHH-galleryslide_267 .imageslider-stage", "#nachhaltigkeit-standardcontent #content-col2 .contentContainer"];
        
        $.each(elements, function() {
            el = $(''+this).find('.media');
			if(el.size() === 0) {
				el = $(''+this).find('.image');
			}
            el.append('<div class="mask"> </div>')
        });
		
    }
}

var bwPrioBoxRow = {

    init: function() {

        $('.row').each(function(i, jRow) {
			var boxprio1v3_405 = $('div.boxprio1v3_405', jRow).size();
            var boxprio2v2_405 = $('div.boxprio2v2_405', jRow).size();
            var boxprio3v2_267 = $('div.boxprio3v2_267', jRow).size();
			var boxprio3v1_267 = $('div.boxprio3v1_267', jRow).size();
			var boxprio3v3_267 = $('div.boxprio3v3_267', jRow).size();
			var boxprio3v4_267 = $('div.boxprio3v4_267', jRow).size();
            
            if (boxprio1v3_405 > 0 || boxprio2v2_405 > 0) {
                $('div.boxprio1v3_405', jRow).each(function(j, objinner) {
                    if (j % 2) {
                        $(this).addClass('lastElementInRow');
                        $(this).after('<br clear="all" /><br />');
                    }
                });
				 $('div.boxprio2v2_405', jRow).each(function(j, objinner) {
                    if (j % 2) {
                        $(this).addClass('lastElementInRow');
                        $(this).after('<br clear="all" /><br />');
                    }
                });
                
            }
            if (boxprio3v2_267 > 0) {
                $('div.boxprio3v2_267', jRow).each(function(j, objinner) {
                    if (((j + 1) % 3) == 0) {
                        $(this).addClass('lastElementInRow');
                        $(this).after('<br clear="all" /><br />');
                    }
                });
            }
            if (boxprio3v1_267 > 0) {
                $('div.boxprio3v1_267', jRow).each(function(j, objinner) {
                    if (((j + 1) % 3) == 0) {
                        $(this).addClass('lastElementInRow');
                        $(this).after('<br clear="all" /><br />');
                    }
                });
            }
            if (boxprio3v3_267 > 0) {
                $('div.boxprio3v3_267', jRow).each(function(j, objinner) {
                    if (((j + 1) % 3) == 0) {
                        $(this).addClass('lastElementInRow');
                        $(this).after('<br clear="all" /><br />');
                    }
                });
            }
            if (boxprio3v4_267 > 0) {
                $('div.boxprio3v4_267', jRow).each(function(j, objinner) {
                    if (((j + 1) % 3) == 0) {
                        $(this).addClass('lastElementInRow');
                        $(this).after('<br clear="all" /><br />');
                    }
                });
            }									

        });
		
		
        

    }
    
}


