
$_DUCEDIS.extend({
	initFoot: function(){
		//this.showItemChild();
		try{
			var topmenu = $ES('.top .ducenavs a');
			var first = topmenu[0];
			if($E('.top .fav a')){
				$E('.top .fav a').setProperty('href','javascript:;').addEvent('click',function(){
					if ( document.all )
						window.external.addFavorite($_CONFIG['favlink']['host'], $_CONFIG['favlink']['title']);
					else if ( window.sidebar )
						window.sidebar.addPanel($_CONFIG['favlink']['title'], $_CONFIG['favlink']['host'], "");
				})
			}else if ( $_CONFIG['favlink'] ) {
				var menus = topmenu ? topmenu.length : 0;
				var target = $E('.top .ducenavs');
				var i = $_CONFIG['favlink']['index'];
				i = i < 0 ? menus + i + 1 : i;

				var el = new Element('li', {
					'class': 'fav'
				}).adopt( new Element('a', {
					'styles': { cursor: 'pointer'},
					'class': i ? '' : 'nobg',
					'href': 'javascript:;',
					'events': {
						'click' : function(){
							if ( document.all )
								window.external.addFavorite($_CONFIG['favlink']['host'], $_CONFIG['favlink']['title']);
							else if ( window.sidebar )
								window.sidebar.addPanel($_CONFIG['favlink']['title'], $_CONFIG['favlink']['host'], "");
						}
					}
				}).set('text', $_CONFIG['favlink']['text']) );

				first = i ? topmenu[0] : null;

				if ( i >= menus || i < 0 ){
					target.appendChild(el);
				} else {
					var before = topmenu[i].getParent();
					target.insertBefore(el, before);
					/*var comma = new Element('li', {
						'class': 'comma'
					}).adopt( new Element('span').set('text', "|"));
					target.insertBefore(comma, before);*/
				}
			}

			if(first) 
				first.style.background = 'none';
		}
		catch(e){}

		var gotop=new Element('a', {
			'class': 'gotop',
			'styles': {
				cursor: 'pointer', 
				position:'fixed',
				zIndex:10,
				'bottom':'10%',
				display: 'none'
			},
			'title':'回到顶部',
			'events': {	
				'click' : function(){ 
					$(document.body).scrollTo(0); 
					this.setStyle('display', 'none');
					return false;
				} 
			}
		});

		var backTopLeft=function(){
			var s_w=950;
			var s_x=window.getWidth();
			var btLeft = s_x/2+(s_w/2)+5;
			if(window.ie6) gotop.setStyle('position', 'absolute');
			if(btLeft+20>s_x){
				gotop.setStyle('left', s_x-25);
			}else if(btLeft <= s_w+5){
				gotop.setStyle('left', s_w+5);
			}else{
				gotop.setStyle('left', btLeft);
			}
		};

		window.addEvents({
			'domready': function(){
				gotop.inject(document.body);
				backTopLeft();
			},
			'scroll': function(){
				if(window.getScrollTop()===0){
					gotop.setStyle('display', 'none');
				}else{
					gotop.setStyle('display', 'block');
					if(window.ie6)
						gotop.setStyle('top', window.getScrollTop()+window.getHeight()-150);
				}
			},
			'resize':function(){
				backTopLeft();
			}
		});

		window.addEvent('domready',function(){
			/*if($_SCREEN_W){
				$ES('.widget_preview').each(function(widget){
					var autowidth = widget.get('autowidth').toInt();
					if(autowidth>0){
						widget.setStyle('width',autowidth);
					}
				});
			}*/
			var intro;
			if(intro=$('goods-intro')){
				intro.getElements('img').each(function(img){
					var imgurl=img.get("init_src")||img.get("src");
					if(!imgurl){return}
					new Asset.image(imgurl, {
						onload:function(){
							if(!this||!this.width){
								return;
							}
							var f=$_DUCEDIS.getTrueSize(intro);
							var e = {'width':this.width,'height':this.height};
							if(this.width>f.x){
								e['width']=f.x;
								e['height']=f.x*this.height/this.width;
							}
							img.setStyles(e);
						}
					});
				})
			}
		});
	}
});

$_DUCEDIS.initFoot();

