// delay
$.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};

$(document).ready(function(){
	var cur_url = location.href;
	if(cur_url.indexOf('produkte-detail')>=0 || cur_url.indexOf('kaufen-detail')>=0){
		var pre='../';
	} else {
		var pre='';
	}
	// select language, and then will goto another website
	$('#lang').addClass('langjs').html('<span>Sprache</span><ul id="se-lang" style="display:none"><li lang="en"><img src="'+ pre +'images/english.png" /></li><li lang="zh-CN"><img src="'+ pre +'images/chinese.png" /></li><li lang="jp"><img src="'+ pre +'images/japanese.png" /></li></ul>');
	$('.lang span').click(function(){$('#se-lang').slideToggle('fast')});
	$('#se-lang li').mouseover(function(){$(this).addClass('on')}).mouseout(function(){$(this).removeClass('on')}).click(function(){
		$(this).parent().slideUp('fast');
		var gourl = '';
		var lang = $(this).attr('lang');
		switch(lang) {
			case 'zh-CN':
				gourl = 'http://www.wondershare.cn/';break;
			case 'en':
				gourl = 'http://www.wondershare.com/';break;
			case 'jp':
				gourl = 'http://www.wondershare.jp/';break;
			default:
				gourl = '';
		}
		if(gourl) location.href = gourl;
	});
	$(document).click(function(){$('#se-lang:visible').hide();})

	// navigator
	$('#navul > li:last').css('background','none');
	// current nav
	var cur = $('body').attr('id');
	$('#navul > li a').each(function(){
		var acur = $(this);
		if(cur == acur.attr('class')) {
			acur.addClass('on');
			acur.parent().siblings().children('a').removeClass('on');
			return;
		};
	});
	
	var timer = null;

	$('#navul li li:has(ul)').addClass('has');

	$('#navul > li:has(ul) > a').bind('mouseenter',function(e){
									els = this;
									function sw() {
										$(els).addClass('cur').siblings('ul').slideDown(100)
										.children('li').bind('mouseenter',function(){if($(this).children('ul').length) $(this).children('a').addClass('sub').siblings('ul').show();});
									}

									clearTimeout(timer);
									timer = window.setTimeout (sw, 150);
									}).bind('mouseleave', function(){
										clearTimeout(timer);
									});
	$('#navul > li > ul > li > ul').bind('mouseleave',function(){$(this).hide();});
	$('#navul > li > ul > li').bind('mouseleave',function(){
										$(this).children('a').removeClass('sub');
										$(this).children('ul').hide();
									});
	$('#navul > li').bind('mouseenter',function(){$(this).children('a').addClass('cur');})
					   .bind('mouseleave',function(){$(this).children('a').removeClass('cur').siblings('ul').slideUp('fast');});
});