

function stripos ( f_haystack, f_needle, f_offset ){
    // Finds position of first occurrence of a string within another, case insensitive  
    // 
    // version: 810.1317
    // discuss at: http://phpjs.org/functions/stripos
    // +     original by: Martijn Wieringa
    // +      revised by: Onno Marsman
    // *         example 1: stripos('ABC', 'a');
    // *         returns 1: 0
    var haystack = (f_haystack+'').toLowerCase();
    var needle = (f_needle+'').toLowerCase();
    var index = 0;
 
    if ((index = haystack.indexOf(needle, f_offset)) !== -1) {
        return index;
    }
    return false;
}

// public accessor variable
var wvg = {

	exSearch: {
		enable: false,
		categories: '',
		cookie: null
	},
	syslang: 'de',
	translate: function(key) {
		if (wvg.isEn()) {
			var translations = {'Dokumentation':'Documentaries','Erotik':'Erotic','Musik':'Music','Film':'Movies','Ratgeber':'Advisor'};
			if (typeof translations[key] !== 'undefined') {
				return translations[key];
			}
		}
		return key;
	},
	isEn: function() {
		return (wvg.syslang.toLowerCase() == 'en' || wvg.syslang == 2);
	}
};

(function() {
	var swapper = function(element, params) {
		this.element = element;
		this.params = params;
		this.init();
	}
	swapper.prototype = {
		init: function() {
			if ( !this.params.id || !this.element ) {
				var imgs = this.element.getElementsByTagName('img');
				for (var i = 0; i < imgs.length; i++) {
					if ($(imgs[i]).hasClass('active')) {
						this.over.call(imgs[i], {data: {params: this.params}});
						continue;
					}
					$(imgs[i]).bind("mouseover", this, this.over);
					$(imgs[i]).bind("mouseout", this, this.out);
				}
			}
			else if ( this.params.id ) {
				$('#'+this.params.id).bind("mouseover", this, this.over);
				$('#'+this.params.id).bind("mouseout", this, this.out);
			}
		},
		over: function(obj) {
			this.oldsrc = this.src;
			this.src = this.src.substr(0, (this.src.length - 4)).concat(obj.data.params.suffix).concat(this.src.substr((this.src.length - 4), this.src.length));
		},
		out: function(obj) {
			this.src = this.oldsrc;
		}
	};
	var menues = {
		matched: [],
		path: '',
		entry: [
			{'id':'lvl-1','suffix':'_g','imgOn':[],'imgOff':[]},
			{'id':'lvl-2','suffix':'_g','imgOn':[],'imgOff':[]},
			{'id':'lvl-3','suffix':'_g','imgOn':[],'imgOff':[]},
			{'id':'article-menu','suffix':'_g','imgOn':[],'imgOff':[]}
		],
		getKey: function(id, type) {
			for (var i = 0 ; i < this.entry.length; i++ ) {
				if (id == this.entry[i].id )
					return this.entry[i][type];
			}
		},
		handleMouseEvent: function(o) {
                    if(this.number)
			this.src = menues.getKey(this.menuName, o.data.key)[this.number].src;
		},
		init: function() {
			// read from article details view and store path information
			var _path = $('#article-view').attr('rel') || $('.navigation-path').attr('rel');;
			if (typeof _path != 'undefined' && _path != '')
				this.path = _path.toLowerCase();
			// iterate menu images and apply magic
			for (var i=0; i < menues.entry.length; i++) {
				var current = menues.entry[i];
				var nav = document.getElementById(current.id);
				if (!nav) continue;
				var imgs = nav.getElementsByTagName('img');
				for (var j=0;j<imgs.length;j++) {
					var currImage = imgs[j];
					var path = $(currImage).attr('alt') ? path = $(currImage).attr('alt').toLowerCase() : path = '';
					var suffix = currImage.src.substring(currImage.src.lastIndexOf('.'));
					var hoverPath = currImage.src.substring(0,currImage.src.lastIndexOf('.'));
					if (
						($(currImage).parent().hasClass('current_nav') ||
						((this.path.indexOf(path) !== -1)) && (current.id != 'article-menu')) &&
						!currImage.current_nav
					   )
					{
						var obj = {'img': currImage, 'src': hoverPath, 'suffix': suffix, 'hover': current.suffix};
						this.matched.push(obj);
						currImage.current_nav = true;
						$(currImage).parents('ul').addClass('visible')
						$(currImage).parent().siblings('ul').addClass('visible');
						continue;



    					} else if (currImage.current_nav)
						continue;
					current.imgOff[j] = new Image();
					current.imgOff[j].src = currImage.src;
					current.imgOn[j] = new Image();
					current.imgOn[j].src = hoverPath + current.suffix + suffix;
					currImage.number = j;
					currImage.menuName = current.id;
					$(currImage).bind('mouseover', {key:'imgOn'}, this.handleMouseEvent);
					$(currImage).bind('mouseout', {key:'imgOff'}, this.handleMouseEvent);
				}
			}
			this.applyMatched();
		},
		applyMatched: function() {
			var m = this.matched;
			if (m.length == 1) {
				m = m[0];
				m.img.src = m.src + m.hover + m.suffix;
			} else if (m.length == 2) {
				m2 = m[1];
				m2.img.src = m2.src + m2.hover + m2.suffix;
			}
			$('#menu ul li').each(function() {
				var li = $(this);
				if (li.children('ul').length > 0) {
					// hide all submenues if it has not been marked visible
					if (!li.children('ul').hasClass('visible'))
						li.children('ul').hide();
					// attach event on parent list item to toggle submenues
					if (li.children('a').eq(0).hasClass('parent')) {
						li.children('a').eq(0).bind('click', function() {
							$(this).parent().children('ul').toggle('slow');
							return false;
						});
					}
				}
			});
		}
	};
	var article = {
		activeTab: null,
		amazon: {
			searchindex: 'DVD'
		},
		prepareView: function() {
			// setup tabs for view
			$('.details li a img').each(function() {
				this.backupSrc = this.src;
				$(this).bind('click', article.handleEvent);
				// hide all content panels except 'start'
				if (!$(this).hasClass('start'))
					$('#tab-'+$(this).attr('class')).hide();
				else {
					article.activeTab = this;
					article.detachEvents(this);
					$(this).attr({'src': this.src.substring(0,this.src.lastIndexOf('.')) + '_g.jpg'});
				}
			});
			this.mediaCheck();
			this.getCoverExtensions();
			this.setupPrinter();
		},
		setupPrinter: function() {
			$('.print').click(function() {
				var _title = $('.details').find('h1').eq(0).clone(true);
				var _content = $('#tab-start').find('p').eq(0).clone(true);
				var _cover = $('#article-view .cover').eq(0).find('img').eq(0).clone(true);
				wvg.popup = {title: _title, content: _content, cover: _cover, printmode: true};
				return  !window.open(wvg.relurl+'/page/show/popup_print', '', 'width=800,height=600,scrollbars=yes');
			});
		},
		coverMagnifier: function() {
			// Show all HighDL-Buttons			
			$('.DLHigh').show();

			var openPopup = function(_fullurl, _fn, _key) {
				wvg.popup = {high: _fullurl, fn: _fn, key: _key, imagemode: true};
				return  !window.open(wvg.relurl+'/page/show/popup_high', '', 'width=800,height=600,scrollbars=yes');
			};
			/*$('body').append('<div id="magnifier" style="display: none;"></div>');
			$('.float-cover').each(function() {
				$(this).mouseover(function() {
					var el = $(this).offset();
					el.top = (el.top +$(this).height())-32;
					el.left = (el.left + $(this).width())-32;
					$('#magnifier').css({'top': el.top+'px', 'left': el.left+'px'});
					$('#magnifier').show();
				});
				$(this).mouseout(function() { $('#magnifier').hide(); });
				$(this).click(function() {
					var s = $(this).find('img').get(0).src.split('/');
					if (!s[5])
						return false;
					var fn = s[5];
					var pr = s[5].substr(0, s[5].lastIndexOf('.'));
					fn = pr + '_high' + s[5].substr(s[5].lastIndexOf('.'), s[5].length)
					return openPopup('/img/dvd_high/'+fn, s[5], $(this).find('a').attr('class'));
				});
			});*/
		},
		mediaCheck: function() {
			var checkMedia = function() {
				$('.float-cover img').each(function() {
					if (this.width < 30)
						$(this).parents('.float-cover').hide();
				});
				$('.cover-add .label img').each(function() {
					if (this.width < 30)
						$(this).parents('.label').hide();
				});

			}
			$(window).load(checkMedia);
		},
		attachEvents: function( obj ) {
			obj.src = obj.backupSrc;
			$(obj).bind('mouseover', {key:'imgOn'}, menues.handleMouseEvent);
			$(obj).bind('mouseout', {key:'imgOff'}, menues.handleMouseEvent);
		},
		detachEvents: function( obj ) {
			$(obj).unbind('mouseover', menues.handleMouseEvent);
			$(obj).unbind('mouseout', menues.handleMouseEvent);
		},
		handleEvent: function(e) {
			article.detachEvents(this);
			$('.tab-item').hide();
			if (this != article.activeTab)
				article.attachEvents(article.activeTab);
			$('#tab-'+this.className).show();
			article.activeTab = this;
			return false;
		},
		getCoverExtensions: function() {
			if ($('#article-menu').get(0)) {

				// amazon
				$.ajax({
					type: 'get',
					url:'/amazon/onca/xml/?Condition=All&MerchantId=All&Service=AWSECommerceService&AWSAccessKeyId=17R1H71CVCP17B0TVH02&Operation=ItemLookup&SearchIndex='+wvg.article.amazon.searchindex+'&ItemId='+wvg.article.amazon.requestEAN+'&IdType=EAN&ResponseGroup=Large',
					dataType: 'xml',
					success: function(xml){
						$(xml).find('Items Item').each(function() {
							var asin = $(this).find('ASIN').eq(0).text();
							var url = $(this).find('DetailPageURL').eq(0).text();
							// response valid, setup link
							if (asin != '' && url != '') {
								$('#goamazon').attr('href', url);
							} else {
								$('#goamazon').attr('href', 'http://www.amazon.de');
							}
						});
					}
				});
			 }
		},
		getPI: function(aid) {

			if (parseInt(aid) === 'NaN' || parseInt(aid) === 0)
				return;

			$.ajax({
				type: 'get',
				url:wvg.relurl+'/article/xmlview/'+aid+'/',
				dataType: 'xml',
				success: function(xml) {
					$(xml).find('projex article exf').each(function() {

						var mfacts = $(this).find('mfacts').eq(0).text();
						var mlogo1 = $(this).find('mlogo1').eq(0).text();
						var mlogo2 = $(this).find('mlogo2').eq(0).text();
						if (mfacts != '') {
							$('#mfacts').html(mfacts);
						}
						if (mlogo1 != '') {
							$('li#mlogo1').find('label').append(
								$('<a href="'+wvg.relurl+'/webfile/show/'+mlogo1+'">Ansehen</a>')
									.click(function() {
										return !window.open(this.href, 'Webfile', 'width=640,height=480');
									})
							);
						}
						if (mlogo2 != '') {
							$('li#mlogo2').find('label').append(
								$('<a href="'+wvg.relurl+'/webfile/show/'+mlogo2+'">Ansehen</a>')
									.click(function() {
										return !window.open(this.href, 'Webfile', 'width=640,height=480');
									})
							);
						}
					});
				}
			});
		}
	};
	var util = {
		pickerInput: null,
		weekdays : ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
		monthnames: {
			de: function(date) { date.setMonthNames("Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");},
			en: function(date) {date.setMonthNames("January", "February", "March", "April", "May", "June", "July", "August", "September", "Oktober", "November", "December");}
		},
		calendar: function(inputname, formname, format) {
			var date = new CalendarPopup('calendar-div');
			if (wvg.syslang == 'de') {
				util.monthnames.de(date);
				date.setDayHeaders('So','Mo','Di','Mi','Do','Fr','Sa');
				date.setTodayText("Heute");
			} else {
				util.monthnames.en(date);
				date.setDayHeaders('Su','Mo','Tu','We','Th','Fr','Sa');
				date.setTodayText("Today");
			}
			date.setWeekStartDay(1);
			date.setReturnFunction('wvg.util.activateHiddenDate');
			var formel = $('#'+formname).get(0);
			util.pickerInput = formel.elements[inputname];
			util.pickerFormat = format;
			date.select(formel.elements[inputname], inputname, util.pickerFormat);
		},
		activateHiddenDate: function(y,m,d) {
			util.pickerInput.value = formatDate(new Date(y,m-1,d,0,0,0), util.pickerFormat);
			$('#'+util.pickerInput.id+'_op').removeAttr('disabled');
		},
		nice_date: function(usdate) {
			if (usdate === '')
				return '-';
			var x = usdate.split(' ');
			var d = x[0].split('-');
			var jd = new Date(d[0], d[1] - 1, d[2]);
			return util.weekdays[jd.getDay()] + ', ' + d[2] + '.' + d[1] + '.' + d[0];
		},
		setReleaseMonth: function(startdate, enddate) {
			var getMonth = function(date) {
				var x = date.split('.');
				var now = new Date(x[2],parseInt(x[1]-1),x[0],0,0,0);
				return wvg.util.monthnames[wvg.syslang][now.getMonth()];
			};
			var sd = getMonth(startdate);
			var ed = getMonth(enddate);
			if (sd !== ed) {
				return;
			}
			wvg.releaseMonth = sd;

			$('.rollable img.hover').each(function() {
				if (sd != null && this.src.indexOf(sd.toLowerCase()) !== -1) {
					$(this).addClass('active');
				}
			});
		},
		setCookie: function (name, value, expires, path, domain, secure) {
			var curCookie = name + "=" + escape(value) +
				((expires) ? "; expires=" + expires.toGMTString() : "") +
				((path) ? "; path=" + path : "") +
				((domain) ? "; domain=" + domain : "") +
				((secure) ? "; secure" : "");
			document.cookie = curCookie;
		},
		getCookie: function (name) {
			var dc = document.cookie;
			var prefix = name + "=";
			var begin = dc.indexOf("; " + prefix);
			if (begin == -1) {
				begin = dc.indexOf(prefix);
				if (begin != 0) return null;
			} else
				begin += 2;
			var end = document.cookie.indexOf(";", begin);
			if (end == -1)
				end = dc.length;
			return unescape(dc.substring(begin + prefix.length, end));
		},
		random: function(min, max) {
			if ( min > max ) {
				return( -1 );
			}
			if ( min == max ) {
				return( min );
   			}
			var r = parseInt( Math.random() * ( max+1 ) );
			return( r + min <= max ? r + min : r );
		}
	};
	// get category option list, if requested/required
	var exSearch = {
		o_categories: null,
		o_genres: null,
		init: function() {
			if (!$('#searchform').size()) {
				return;
			}
			this.o_categories = $('#categories').get(0);
			this.o_genres = $('#genre').get(0);
			this.sform = $('#searchform').get(0);
			if (wvg.util.getCookie('lastSearch') == '') {
 				wvg.util.setCookie('lastSearch','');
			}
			this.restoreSearchForm();
			$('#categories').change(function() {
				exSearch.getGenres(this.value);
			});

			var setSearch = function() {
				// save to cookie
				var catval = $(exSearch.o_categories).val();
				var genval = $(exSearch.o_genres).val();
				var title = $('#name').val();
				var ean = $('#ean').val();
				var fsk = $('#fsk').val();
				var darsteller = $('#darsteller').val();
				var regie = $('#regisseur').val();
				var format = $('#format').val();
				var date_from = $('#release_date_from').val();
				var date_to = $('#release_date_to').val();
				wvg.util.setCookie('lastSearch','/submit=true/cat='+catval+'/gen='+genval+'/name='+title+'/ean='+ean+'/fsk='+fsk+'/darsteller='+darsteller+'/regie='+regie+'/format='+format+'/date_from='+date_from+'/date_to='+date_to);
				wvg.util.setCookie('restore','yes');
				if (exSearch.o_genres.selectedIndex !== 0) {
					exSearch.o_categories.name = "";
				}
			}
			$(this.sform).submit(setSearch);
			$('#nav-search').submit(setSearch);
		},
		getGenres: function(parent, updateCaller) {
			for (var i = this.o_genres.options.length-1 ; i >= 0; i--) {
				this.o_genres.remove(i);
			}
			exSearch.o_genres.disabled = true;
			exSearch.o_genres.options[exSearch.o_genres.options.length] = new Option('', '');

			if (parent == '' || parent == 0)
				return;

			$.ajax({
				type: 'get',
				url:wvg.relurl+'/articlecategory/xmllist/noid/parent='+parent,
				dataType: 'xml',
				success: function(xml){
					if ($(xml).find('articlecategory').length > 0) {
						$(xml).find('articlecategory').each(function(){
							var idx = $(this).find('idx').text();
							var basename = $(this).find('basename').text();
							var option = new Option(wvg.translate(basename), basename);
							if (updateCaller && idx == updateCaller)
								option.selected = true;
							exSearch.o_genres.options[exSearch.o_genres.options.length] = option;
						});
						exSearch.o_genres.disabled = false;
						if (updateCaller) {
							exSearch.selectDefault(exSearch.o_genres, updateCaller);
						}
					}
				}
			});
		},
		selectDefault: function (dd, value) {
			if (!dd) return;
			for(var i = 1; i < dd.options.length; i++) {
				if (dd.options[i].value == value) {
					dd.options.selected = true;
					dd.value = dd.options[i].value;
					dd.selectedIndex = i;
					break;
				}
			}
		},
		restoreSearchForm: function() {
			for (var i = 0, len = this.sform.elements.length; i < len; i++) {
				var o = this.sform.elements[i];
				var v = $(o).attr('rel');

				if (o.type == 'select-one' && $(o).attr('rel')) {
					this.selectDefault(o, v);
					if ($(o).attr('id') === 'categories') {
						// take care about "special interest"
						var req = false;
						var topc = ['189','181','192','190'];
						for (var cc = 0; cc < topc.length; cc++) {
							if (topc[cc] == v) {
								this.selectDefault(o, 180);
								exSearch.getGenres(180, v);
								req = true;
								break;
							}
						}
						if (!req)
							exSearch.getGenres(v);
					}
				}
			}
			var hash = {};
			var c = wvg.util.getCookie('lastSearch');
			if (c) {c = c.split('/');}
			else {c = [];}
			for (var i = 1; i < c.length; i++) {
				var o = c[i].split('=');
				hash[o[0]] = {k:o[0], v:(o[1]||'')};
			}
			if ((window.location.href.indexOf('__lastsearch') !== -1) || (wvg.util.getCookie('restore')=='yes')) {
				if (hash.cat && hash.gen) {
					exSearch.selectDefault(exSearch.o_categories, (hash.cat.v||''));
					exSearch.getGenres(hash.cat.v, hash.gen.v);
				}
				$('#name').val((hash.name?(hash.name.v||''):''));
				$('#ean').val((hash.ean?(hash.ean.v||''):''));
				exSearch.selectDefault($('#fsk').get(0), hash.fsk?(hash.fsk.v||''):'');
				$('#darsteller').val((hash.darsteller?(hash.darsteller.v||''):''));
				$('#regisseur').val((hash.regie?(hash.regie.v||''):''));
				exSearch.selectDefault($('#format').get(0), hash.format?(hash.format.v||''):'');
				$('#release_date_from').val((hash.date_from?(hash.date_from.v||''):''));
				$('#release_date_to').val((hash.date_to?(hash.date_to.v||''):''));
				wvg.util.setCookie('restore','');
			} else {
				wvg.util.setCookie('lastSearch','');
			}
		}
	};
	var slides = {
		image: null,
		coverActive: false,
		ltarget: null,
		index: -1,
		timeout: null,
		init: function() {
			this.navigate('start');
			var cover = $('#coverPreview');
			var alt = '';
			$('.back,.next').click(this.navigate);
			$('area').mouseover(function(e) {
				alt = $(this).attr('alt');
				if (alt == 'undefined') {return false;}
				var page = (wvg.isEn()?'/page=articleview/layout=default_en/':'');
				var url = wvg.relurl + '/article/showbynr/noid/nr=' + alt + page;
				$(this).click(function() {
					window.location.href = url;
					return false;
				});
				var doMouseOver = function() {
					cover.css({'left':(e.pageX-600)+'px', 'cursor':'pointer'}).hide().click(function() {
						window.location.href = url;
						return true;
					});
					slides.ltarget = alt;
					slides.image = document.createElement('img');
					slides.image.src = '/img/dvd_new/' + alt + '_new.jpg';
					$(slides.image).css('display', 'none');
					$(slides.image).mouseover(function() { slides.coverActive = true; });
					$(slides.image).mouseout(function() { slides.coverActive = false; cover.hide();});
					var _load = setInterval(function() {
						cover.fadeIn().html('<span>Lade...</span>');
						if (slides.image.complete && slides.image.width > 1) {
							clearInterval(_load);
							cover.html(slides.image);
							$(slides.image).fadeIn();
						}
						else if (slides.image.complete && slides.image.width < 1) {
							clearInterval(_load);
							cover.hide();
						}
					}, 50);
				}
				slides.timeout = setTimeout(doMouseOver, 250);
				return false;
			});
			// hide the cover when area has changed
			$('area').mouseout(function(e) {
				clearTimeout(slides.timeout);
				var alt = $(e.target).attr('alt');
				setTimeout(function() {
					if (alt ==  'undefined') {return;}
					if ((alt == slides.ltarget) && slides.coverActive) {
						cover.show();
					}
					else if ((alt != slides.ltarget) && !slides.coverActive) {
						cover.hide();
					}
				}, 50);
			});
		},
		navigate: function(_init) {
			if (typeof wvg.newlist == 'undefined') {
				return;
			}
			var dir = 'next';
			var set = null;
			if (_init != 'start') {
				dir = $(this).attr('class');
			}
			if (dir == 'next') {
				if (typeof wvg.newlist[slides.index + 1] == 'undefined') {
					$('.next').hide();
					return false;
				} else {
					if (_init != 'start') {
						$('.back').show();
					}
					slides.index+=1;
					set = wvg.newlist[slides.index];
				}
			}
			else if (dir == 'back') {
				if (typeof wvg.newlist[slides.index - 1] == 'undefined') {
					$('.back').hide();
					return false;
				} else {
					$('.next').show();
					slides.index-=1;
					set = wvg.newlist[slides.index];
				}
			}
			if (_init !== 'start') {
				$('#mapHolder').fadeOut('slow', function() {
					$('#mapHolder').attr('src', '/img/'+set.map).fadeIn('slow');
				});
			}
			$('area').each(function(i) {
				if (i < set.codes.length) {
					$(this).attr('alt', set.codes[i]);
				}
				else {
					$(this).attr('alt', '');
				}
			});
		}
	};
	var news = {
		init: function() {
			$('.newsticker').show();
			$('.newsticker').liScroll();


			//$('#news-slider').show();
			$('body').append($('<div id="scroller-cover" style="display: none; position: absolute;"></div>'));
			var $cover = $('#scroller-cover');
			$('.newsticker li a').each(function() {
				$(this).mouseover(function(e) {
					var preview = '/img/dvd_new/' + $(this).attr('rel') + '_new.jpg';
					$cover.html('<img src="'+preview+'" alt=""/>');
					$cover.css({'left':(e.pageX+20)+'px', 'top':(e.pageY-50)+'px', 'cursor':'pointer'}).show();
				});
				$(this).mouseout(function(e) {
					$cover.hide();
				});
			});
		}
	};
	var misc = {
		init: function() {
			this.setSelectedCountry();
		},
		setSelectedCountry: function() {
			var select = $('#country').get(0);
			if (!select) {
				return;
			}
			exSearch.selectDefault(select, $(select).attr('rel'));
		}
	};
	var player = {
		load: function() {
			var $trailer = $('#trailer');
			$trailer.css({
				top: (($(window).height()/2)-200),
				left: (($(window).width()/2)-200)
			}).show();
			$('#trailer a').eq(0).media({ autoplay: true });
		}
	};

/*
this.tooltip = function(){
	xOffset = 10;
	yOffset = 20;
	t = "notset";
	jQuery("a.tooltip").hover(function(e){
		this.t = this.title;
		this.title = "";
		jQuery("body").append("<p id='tooltip'>"+ this.t +"</p>");
		jQuery("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		jQuery("#tooltip").remove();
    });
	jQuery("a.tooltip").mousemove(function(e){
		jQuery("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};*/



	// map to public space
	wvg.util = util;
	wvg.article = article;
	wvg.player = player;
	$(document).ready(function() {
/*		// Hiding all submenus(2 to 8) except lvl-1
for(i = 2; i < 9; i++)  {
    $("#lvl-"+i).hide();
    if(i>=2 && i<=6) {
        $("#lvl-b-"+i).hide();
    }
}*/

// Article View: Tab-Menu
/*$("#article-view li a img").click(function() {
		var img = $(this).attr("src");
		if(stripos(img,"_g.jpg",0) !== false)
			$(this).attr('src',$(this).attr('src').replace("_g.jpg",".jpg"));
		else
			$(this).attr('src',$(this).attr('src').replace(".jpg","_g.jpg"));
	});*/

// Display hidden state messages in search result
$(".RESTRICTED, .CANCELED, .SOLDOUT, .DEACTIVATED").each(function() {
	if($(this).attr('title') == 't') {
		$(this).show();
	}
});

// Binding the toggle-magic on those submenues which don't perform a search on click
$(".parent").bind("click", function(e){
	oldState = $(this).siblings("ul").css("display");

	$(".parent").siblings("ul").hide("normal");
	if(oldState=="none")
		$(this).siblings("ul").show("normal");

	return false;
});

		// If there was a pageName given, add the class current_nav to mark the current nav-entry
		if(typeof wvg_search_pageName != "undefined" && wvg_search_pageName != ".") {
				menuEntryA = $(wvg_search_pageName);
				$(menuEntryA).addClass("current_nav"); // Add class current_nav
		}

		$(".current_nav").each(function() {
			imgTag = $(this).children("img").eq(0);
               		imgTag.attr("src",imgTag.attr("src").replace(/.gif/,"_g.gif"));

			$(this).parents("ul").show(); // Show the parents(open the menu)
                        $(this).siblings("ul").show();
		});

function onMouseEnterFn() {
      imgTag = $(this).children("img").eq(0);
      imgTag.attr("src",imgTag.attr("src").replace(/.gif/,"_g.gif"));
}

function onMouseLeaveFn() {
      imgTag = $(this).children("img").eq(0);
      imgTag.attr("src",imgTag.attr("src").replace(/_g.gif/,".gif"));
}

// Binding the hover-magic on all submenu buttons
$("#lvl-1 a, #nav_logoutbutton a").each(function() {
    if(!$(this).hasClass("current_nav")) {
        $(this).bind("mouseenter", onMouseEnterFn);
        $(this).bind("mouseleave", onMouseLeaveFn);
    }
});


// Add Tooltips
//tooltip();

		//menues.init();
		slides.init();
		exSearch.init();
		article.prepareView();
		misc.init();
		news.init();
		$('.tooltip').tooltip({ track: true, delay: 250, showURL: false, showBody: " - " });
		$('.rollable').each(function() {
			new swapper(this, { suffix: '_g', type: 'img' } );
		});
	});
})();
