jQuery(document).ready(function() {
    // 初始化可视化html编辑器
    InitWYSIWYG ();

    // 禁用a标签焦点 和空连接
    jQuery("a").bind("focus",function(){
        if(this.blur){
            this.blur();
        }
    });

    jQuery("a").click(function(){
        if(jQuery(this).attr("href") == "#"){
            return false;
        }
    });

    // 计算上传图片位置
   /* jQuery(".imgcon img").onload = function(){
        conheight = jQuery(".imgcon").height();
    picheight = jQuery(".imgcon img").height();
    alert(picheight)
    jQuery(".imgcon img").css("marginTop",(conheight-picheight)/2);
    }*/

    function lazyLoadImage (_idx, img) {
		img = $(img);
		var url = img.attr('src');
		var newImage = new Image();
		newImage.onload = function (e) {
                    conheight = jQuery(".imgcon").height();
                    picheight = img.height();
                    img.css("marginTop",(conheight-picheight)/2);
		};
		newImage.src = url;
	}
        function fastLoadImage (_idx, img) {
		img = $(img);
		var url = img.attr('src');
		var newImage = new Image();
		newImage.onload = function (e) {
                    conheight = 93;
                    picheight = newImage.height*93/200;
                    img.css("marginTop",(conheight-picheight)/2);
		};
		newImage.src = url;
	}
     $('.imgcon img').each(lazyLoadImage);
     $(".thumblist img").each(fastLoadImage);
	
    // 首页评委效果
    jQuery("ul.gallery li").hover(function() { //On hover...
        jQuery(this).find(".active").stop(true,true).fadeIn();
    } , function() { //on hover out...
        //Fade the image to 1
        jQuery(this).find(".active").stop(true,true).fadeOut();
    });
    jQuery("ul.gallery li").click(function(){
        alinks = jQuery(this).find("a").attr("href");
        if(alinks != "#"){
            window.location.href=alinks;
        }
    })

    // 评委列表效果
    jQuery("ul.lgallery li").hover(function() { //On hover...
        jQuery(this).find("p").css({
            'background-color':'#e8e8e8'
        });
    } , function() { //on hover out...
        //Fade the image to 1
        jQuery(this).find("p").css({
            'background-color':'#f7f7f7'
        });
    });
    jQuery("ul.sgallery li").hover(function() { //On hover...
        jQuery(this).find("p").css({
            'background-color':'#e8e8e8'
        });
    } , function() { //on hover out...
        //Fade the image to 1
        jQuery(this).find("p").css({
            'background-color':'#ffffff'
        });
    });


    jQuery("ul.jgallery li").click(function(){
        links = jQuery(this).find("a").attr("href");
        if(links != "#"){
            window.location.href=links;
        }
    })
	
    jQuery("ul.jgallery li").hover(function() { //On hover...
        //Get image url and assign it to 'thumbOver'
        if(!jQuery(this).find(".active").hasClass("ing")){
            jQuery(this).find(".active").stop(true,true).fadeIn();
        }
    } , function() { //on hover out...
        //Fade the image to 1
        if(!jQuery(this).find(".active").hasClass("ing")){
            jQuery(this).find(".active").stop(true,true).fadeOut();
        }
    });
    var bro = jQuery.browser;
    if(bro.msie){
        jQuery('ul.jgallery li img').tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: " - ",
            fade: 250,
            left: -30
        });
    }else{
        jQuery('ul.jgallery li .active').tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: " - ",
            fade: 250,
            left: -30
        });
    }
        
      
    // 征稿部分效果
    var isShow = false;
    jQuery('#showLetter').click(function(){
        if(isShow){
            jQuery('#letterContainer').animate({
                "height": "280px"
            },{
                queue:false,
                duration:1000
            } );
		  
            jQuery(this).html("查看全部内容");
            isShow = false;
        }else{
            jQuery('#letterContainer').animate({
                "height": "850px"
            },{
                queue:false,
                duration:1000
            } );
            jQuery(this).html("隐藏部分内容");
            isShow = true;
        }
		
    });
	
    // 网站主导航
    jQuery("#nav ul li").eq(0).find("a").css({
        'border-left':'0'
    });
    actvie = jQuery("#nav #mainNav .active");
    curWidth = jQuery("a",actvie).width()+30;
    position = actvie.position();
    jQuery(".cur").css({
        "left":position.left,
        "width":curWidth
    });
    jQuery("#nav ul li ul").each(function(index) {
        jQuery(this).width(jQuery(this).parent().width()+10);
        //jQuery(this).css({'opacity': '0.9'});
        jQuery(this).hide();
    });

    jQuery("#nav #mainNav .item").hover(function(){
        curWidth = jQuery("a",this).width()+30;
        position = jQuery(this).position();
        jQuery(".cur").animate({
            "width": curWidth,
            "left": position.left+"px"
        },{
            queue:false,
            duration:300
        } );
        jQuery("ul",this).stop(true, true).slideDown(400);
        jQuery("li",this).hover(function(){
            var color = jQuery(this).css("background-color");
            jQuery(this).css({
                "background-color":"#ac0710"
            });
        },function(){
            jQuery(this).css({
                "background-color":"#000000"
            });
        });
    },function(){
        actvie = jQuery("#nav #mainNav .active");
        curWidth = jQuery("a",actvie).width()+30;
        position = actvie.position();
        jQuery(".cur").animate({
            "width": curWidth,
            "left": position.left+"px"
        },{
            queue:false,
            duration:300
        } );
        jQuery("ul",this).delay(300).stop(true, true).slideUp(400);
    });
	

    // Simple Tabs
    jQuery(".tab_content").hide(); //Hide all content
    jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab
    jQuery(".tab_content:first").show(); //Show first tab content

    //On Click Event
    jQuery("ul.tabs li").click(function() {
        if(jQuery(this).hasClass("active")){
            return false;
        }
        jQuery("ul.tabs li").removeClass("active"); //Remove any "active" class
        jQuery(this).addClass("active"); //Add "active" class to selected tab
        jQuery(".tab_content").hide(); //Hide all tab content
        var activeTab = jQuery(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        jQuery(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });

    //友情链接滚动
    if(jQuery("#marquee dl dt").width()>960){
	//alert(jQuery("#marquee dl dt").width());
        Marquee("marquee");
    }

    
 
});

var Marquee = function(id){
    try{
        document.execCommand("BackgroundImageCache", false, true);
    }catch(e){};
    var container = document.getElementById(id),
    original = container.getElementsByTagName("dt")[0],
    clone = container.getElementsByTagName("dd")[0],
    speed = arguments[1] || 20;
    clone.innerHTML=original.innerHTML;
    var rolling = function(){
        if(container.scrollLeft == clone.offsetLeft){
            container.scrollLeft = 0;
        }else{
            container.scrollLeft++;
        }
    }
    var timer = setInterval(rolling,speed)//设置定时器
    container.onmouseover=function() {
        clearInterval(timer)
    }//鼠标移到marquee上时，清除定时器，停止滚动
    container.onmouseout=function() {
        timer=setInterval(rolling,speed)
    }//鼠标移开时重设定时器
}

function InitWYSIWYG () {
	$('.jwysiwyg').wysiwyg({
		controls: {
			strikeThrough : { visible : true },
			underline     : { visible : true },

			separator00 : { visible : true },

			justifyLeft   : { visible : true },
			justifyCenter : { visible : true },
			justifyRight  : { visible : true },
			justifyFull   : { visible : true },

			separator01 : { visible : true },

			indent  : { visible : true },
			outdent : { visible : true },

			separator02 : { visible : true },

			subscript   : { visible : true },
			superscript : { visible : true },

			separator03 : { visible : false },

			undo : { visible : false },
			redo : { visible : false },

			separator04 : { visible : false },

			insertOrderedList    : { visible : true },
			insertUnorderedList  : { visible : true },
			insertHorizontalRule : { visible : true },
                        separator05 : { visible : false },
                        separator06 : { visible : false },
			separator07 : { visible : false },
                        separator09 : { visible : false },
			cut   : { visible : false },
			copy  : { visible : false },
			paste : { visible : false },
                        createLink : { visible : false },
                        insertImage: { visible : false },
                        h1: { visible : false },
                        h2: { visible : false },
                        h3: { visible : false }
		}
	});

	
}

(function(a){a.fn.mask=function(c,b){a(this).each(function(){if(b!==undefined&&b>0){var d=a(this);d.data("_mask_timeout",setTimeout(function(){a.maskElement(d,c)},b))}else{a.maskElement(a(this),c)}})};a.fn.unmask=function(){a(this).each(function(){a.unmaskElement(a(this))})};a.fn.isMasked=function(){return this.hasClass("masked")};a.maskElement=function(d,c){if(d.data("_mask_timeout")!==undefined){clearTimeout(d.data("_mask_timeout"));d.removeData("_mask_timeout")}if(d.isMasked()){a.unmaskElement(d)}if(d.css("position")=="static"){d.addClass("masked-relative")}d.addClass("masked");var e=a('<div class="loadmask"></div>');if(navigator.userAgent.toLowerCase().indexOf("msie")>-1){e.height(d.height()+parseInt(d.css("padding-top"))+parseInt(d.css("padding-bottom")));e.width(d.width()+parseInt(d.css("padding-left"))+parseInt(d.css("padding-right")))}if(navigator.userAgent.toLowerCase().indexOf("msie 6")>-1){d.find("select").addClass("masked-hidden")}d.append(e);if(c!==undefined){var b=a('<div class="loadmask-msg" style="display:none;"></div>');b.append("<div>"+c+"</div>");d.append(b);b.css("top",Math.round(d.height()/2-(b.height()-parseInt(b.css("padding-top"))-parseInt(b.css("padding-bottom")))/2)+"px");b.css("left",Math.round(d.width()/2-(b.width()-parseInt(b.css("padding-left"))-parseInt(b.css("padding-right")))/2)+"px");b.show()}};a.unmaskElement=function(b){if(b.data("_mask_timeout")!==undefined){clearTimeout(b.data("_mask_timeout"));b.removeData("_mask_timeout")}b.find(".loadmask-msg,.loadmask").remove();b.removeClass("masked");b.removeClass("masked-relative");b.find("select").removeClass("masked-hidden")}})(jQuery);

