/**
 * 新课标--评测客户端
 * ============================================================================
 * 版权所有 (C) 2007-2009 上海学舟信息科技有限公司，并保留所有权利。
 * 网站地址: http://www.xinkb.org
 * ============================================================================
 * $Author: yongzh $
 * $Date: 2009-04-27 11:11:40 +0800 (星期一, 27 四月 2009) $
 * $Id: functionCommend.js 1698 2009-04-27 03:11:40Z yongzh $
*/

var functionCommend = {
	index:0,
	data:[],
	//to:'next',
	init:function(data){
		$("#demo").show();
	    $("#demo_summary").show();
		this.center = parseInt($("#demo").offset().left) + parseInt($("#demo").width()) / 2;
	    this.top    = parseInt($("#demo").offset().top);
		if(data.length){
			$.each(data,function(k,v){
				var img=$('<img index="'+k+'" id="'+this.id+'" style="display:none" src="/main/show,hm?pic='+this.pic+'"></img>');
				img.appendTo("#demo");
				$.extend(img,v);
				img.imgwidth=img.width();
				img.imgheight=img.height();
				img.css({"z-index":1,"left": functionCommend.center - img.imgwidth/2, "top": functionCommend.top});
				functionCommend.data.push(img);
			});
			this.prePosition(this.data[this.nindex()]);
			this.newPosition(this.data[this.index]);
			this.nextPosition(this.data[this.pindex()]);
			this.click=$('<a target="_blank" class="FC_click" href="javascript:;" style=" background:url(/main/Public/shgao/images/block.png) no-repeat;" id="FC_click_a"></a>');
			this.click.css({"z-index":4,"width": this.data[this.index].imgwidth, "height": this.data[this.index].imgheight,"left": this.center - this.data[this.index].imgwidth/2, "top": this.top,display:"block",position:'absolute'});
			this.click.appendTo("#demo");
			if($.browser.msie&& $.browser.version=='6.0'){
				DD_belatedPNG.fix('.FC_click');
			}
			this.unmask();
			this.lefticon();
			this.righticon();
			//setTimeout(this.timeOut,5000);
		}
	},
	pindex:function(){
        var index_p = this.index - 1;
        index_p = index_p <0 ? this.data.length - 1:index_p;
        return index_p;
	},
	nindex:function(){
		var index_n = this.index + 1;
        index_n = index_n >= this.data.length ? 0 : index_n;
        return index_n;
	},
	ppindex:function(){
        var index_p = this.pindex() - 1;
        index_p = index_p < 0 ?  this.data.length - 1:index_p;
        return index_p;
	},
	nnindex:function(){
		var index_n = this.nindex() + 1;
        index_n = index_n >= this.data.length ? 0 : index_n;
        return index_n;
	},
	next:function(){
		if(this.timeoutindex){
			clearTimeout(this.timeoutindex);
			this.timeoutindex=setTimeout(this.timeOut,5000);
		}
		//this.to='next';
		this.cleaPosition(this.data[this.pindex()]);
		this.nextPosition(this.data[this.index]);
		this.newPosition(this.data[this.nindex()]);
		this.prePosition(this.data[this.nnindex()]);
	    this.index++;
		this.index>=this.data.length?this.index=0:'';
		$('#FC_left_icon').animate({"opacity": 0.1},300,'',function(){
			$('#FC_left_icon').animate({"opacity": 0.8},500);
		});
		$('#FC_right_icon').animate({"opacity": 0.1},300,'',function(){
			$('#FC_right_icon').animate({"opacity": 0.8},500);
		});
	},
	previous:function(){
		if(this.timeoutindex){
			clearTimeout(this.timeoutindex);
			this.timeoutindex=setTimeout(this.timeOut,5000);
		}
		//this.to='previous';
		this.cleaPosition(this.data[this.nindex()]);
		this.prePosition(this.data[this.index]);
		this.newPosition(this.data[this.pindex()]);
		this.nextPosition(this.data[this.ppindex()]);
		this.index--;
		this.index < 0?this.index=this.data.length-1:'';
		$('#FC_left_icon').animate({"opacity": 0.1},300,'',function(){
			$('#FC_left_icon').animate({"opacity": 0.8},400);
		});
		$('#FC_right_icon').animate({"opacity": 0.1},300,'',function(){
			$('#FC_right_icon').animate({"opacity": 0.8},400);
		});
	},
	prePosition:function(img){
		img.css({"z-index":2}).show().animate({"width": img.imgwidth*0.8, "height": img.imgheight*0.8,"left": this.center - img.imgwidth/2 - 33,                 "top": this.top + 10, "opacity": 0.3 },300);
	    img.click(function(){
			functionCommend.previous();
		});
	},
	nextPosition:function(img){
		img.css({"z-index":2}).hide().animate({"width": img.imgwidth*0.8, "height": img.imgheight*0.8,"left": this.center - 3*img.imgwidth/2 +$("#demo").width(), "top": this.top + 10, "opacity": 0.3 },300);
	    img.click(function(){
			functionCommend.next();
		});
	},
	newPosition:function(img){
		$('#FC_summary').html(img.summary);
		img.unbind('click').css({"z-index":3}).show().animate({"width": img.imgwidth,     "height": img.imgheight,    "left": this.center - img.imgwidth/2,                      "top": this.top, "opacity": 1   },300,'',function(){
					$('#FC_click_a').attr('href',img.link);
		});
	},
	cleaPosition:function(img){
		img.unbind('click').css({"z-index":1}).css({"width": img.imgwidth*0.8, "height": img.imgheight*0.8,"left": this.center - img.imgwidth/2, "top": this.top + 10, "opacity": 0}).hide();
	},
	lefticon:function(){
		var el=$('#FC_left_icon');
		el.css({"z-index":3,position:'absolute',"left": $("#demo").offset().left+20, "top": this.top + 48, "opacity": .8}).fadeIn(400);
	    el.click(function(){
			functionCommend.previous();
		});
	},
	righticon:function(){
		var el=$('#FC_right_icon');
		el.css({"z-index":3,position:'absolute',"left": $("#demo").offset().left+$("#demo").width()-el.width()-19.5, "top": this.top + 48, "opacity": .8}).fadeIn(400);
	    el.click(function(){
			functionCommend.next();
		});
	},
	load:function(){
		$.post('/'+mUrlDir+'/index/functionCommend.html',{}, function(data){
            if (data.status) {
              functionCommend.init(data.info);
            }
        }, "json");
		
	},
	timeOut:function(){
		if(functionCommend.to=='next'){
			functionCommend.next();
		}else{
			functionCommend.previous();
		}
		functionCommend.timeoutindex=setTimeout(functionCommend.timeOut,5000);
	},
    //遮罩
	mask:function(msg){
		if(msg=='loading'){
			msg='<img src="/home/image/large-loading.gif" style="z-index:4"  width="32" height="32" />';
		}
		$("#Function").mask(msg);
	},
	//移除遮罩
	unmask:function(time){
            $("#Function").unmask(function(){
            }, time);
	},
	extend : $.extend
};
 
