var imagelist;
;(function($, undefined) {
	$(function() {
		if (typeof imagelist == 'undefined') {
			imagelist = true;
			// init imagelist hovers
			// may be more than once on page so check if initialized

		    $('.html_ext_imagelist').each(function(i){
		        var imagelist = $(this)
		          , alla = imagelist.find('a')
		          , XOFFSET = 360
		          // height of a single row
		          , ROWH = 112
		          // y offset in illu image for this list
		          , YOFFSET = (parseInt(imagelist.data('startrow'), 10) - 1) * ROWH
		          , track = function(obj) {
		        		var linkid = (obj.attr('id')!='') ? obj.attr('id') : 'Link ID nicht gesetzt'

						wpmsc.tl(this,'o','Imagelist',{
						     linkTrackVars:'prop21,eVar31',
						     prop21:linkid,
						     eVar31:linkid
						});
		        	}

		        alla.each(function(j) {
					var a = $(this)
					  , xy = '-' + ((j % 2 == 0) ? 0 : XOFFSET) + 'px -' +
						Math.abs(YOFFSET + [0, 0, 1, 1, 2, 2, 3, 3, 4, 4][j] * ROWH) + 'px'
						
					// imageillu is clickable
					if (j == 0) {
					    imagelist.bind('click.imagelist', function(e){
					    	track(a)
					        document.location = a.attr('href')
					    })
					}
					
					a.mouseenter(function(){
					    alla.removeClass('html_ext_imagelist-current')
					    a.addClass('html_ext_imagelist-current')
					    imagelist.css({
					        backgroundPosition: xy
					    })
					    
					    // reset imageillu click
					    imagelist
						    .unbind('click.imagelist')
						    .bind('click.imagelist', function(){
						    	track(a)
						        document.location = a.attr('href')
						    })
					})
					a.click(function(e){
						e.stopPropagation()
						// TRACKING
						track($(this))
					})
		        })
		    })
		}
	})	
}(jQuery));
