var jsReady=false;
var opus=['opus1.gif','opus2.gif','opus3.gif','opus4.gif','opus5.gif'];
$(document).ready(function(){
jsReady = true;$('#trytry').append('document ready>:');
addNavEvent();
butShowTabs();
leaveBorder();
addLeaveEvent();
addOpus();
addOpusEvent();
addMsnEvent();
addOveroutEvent();
rmAtagBorder();
modifNewLength();
forCssValidte();
});
function forCssValidte(){
 //  forIndex();//首页的欺骗验证     
}
function forIndex(){
   if($('#msg').length==0)return;
    $('#msg').attr('style','SCROLLBAR-FACE-COLOR: #92C3F4;SCROLLBAR-HIGHLIGHT-COLOR: #fff;SCROLLBAR-SHADOW-COLOR: #fff;SCROLLBAR-3DLIGHT-COLOR:#fff;SCROLLBAR-ARROW-COLOR: #0167CD;SCROLLBAR-TRACK-COLOR: #F2F2F2;SCROLLBAR-DARKSHADOW-COLOR: #fff;SCROLLBAR-base-color:#fff;');
/*

        */
}
function modifNewLength(){
$('.news-conts ul a').each(function(){
    $(this).attr('title',$(this).text()).text('* '+cutText($.trim($(this).text()),28,'...'));
});
}
function rmAtagBorder(){
$('a').each(function(){
$(this).focus(function(){
$(this).blur();
});
});
}
function isReady() {
$('#trytry').append('jsReady:'+jsReady+'>');
return jsReady;
}
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
function isComplete(){
var imgnum=0;
var imgcount=getImgCount();
$('#trytry').append('isComplete()>'+'imgcount:'+imgcount+'>');
$('img').each(function(){
var newImg = new Image();
newImg.onload = function(){
imgnum++;
$('#trytry').append('loadImg:'+imgnum+'/'+imgcount+'>');
thisMovie("flashloading").sendToActionScript(parseInt((imgnum/imgcount)*100));
if(imgnum==imgcount){
goEnter('imgnum==imgcount');
}
};
newImg.onerror=loadEro;
newImg.src = $(this).attr('src');
});
$('*').each(function(i){
if($(this).css('background-image')!='none'&&$(this).css('background-image')!=''){
var newImg2 = new Image();
newImg2.onload = function(){
imgnum++;
$('#trytry').append('loadImg:'+imgnum+'/'+imgcount+'>');
thisMovie("flashloading").sendToActionScript(parseInt((imgnum/imgcount)*100));
if(imgnum==imgcount){
goEnter('imgnum==imgcount');
}
};
newImg2.onerror=loadEro;
newImg2.src = $(this).css('background-image').match(/^url\("?([^"]+)"?\)$/)[1];
}
});
$('#enter').click(function(){
goEnter();
});
setTimeout('goEnter("timeout")',8000);
}
function getImgCount(){
var num=$('img').length;
$('*').each(function(){
if($(this).css('background-image')!='none'&&$(this).css('background-image')!=''){
num++;
}
});
return num;
}
function loadEro(){
$('#trytry').append('loaderror>');
goEnter('error');
}
function goEnter(msg){
thisMovie("flashloading").sendToActionScript(100);
$('#trytry').append('goEnter():'+msg+'>');
$('#loadflash').css('display','none');
$('#flash,#header-outline,#wrapper,#footer,#tracqfloater,#tracqfloater1').css('display','block');
}
function cutText(str,len,append){
var a = 0;
var i = 0;
var temp = '';
for (i=0;i<str.length;i++) {
if (str.charCodeAt(i)>255)
a+=2;
else
a++;
if(a > len) return temp+append;
temp += str.charAt(i);
}
return str;
}
function loadHideimg(parents){
    if($('.showhideimg:first').length==0){
    $(parents).each(function(){
        var img=$('<img class="showhideimg" src="" style="display:none"/>');
        var the=$(this);
        $(this).find('a').append(img);
        img.load(function(){
            the.css('background-image','none');
            img.css('display','block');
        });
        img.attr('src',$(this).attr('hideimg'));
    });
    }
}
function loadImg(parents){
    if($('.showhideimg2:first').length==0){
    $(parents).each(function(){
        var img=$('<img class="showhideimg2" src="" style="display:none"/>');
        var the=$(this);
        $(this).append(img);
        img.load(function(){
            the.css('background-image','none');
            img.css('display','block');
        });
        img.attr('src',$(this).attr('hideimg'));    
    });
    }
}
function butShowTab(buts,tabs,num,targe){
	$(tabs.join()).css('display','none');
	$(tabs[num]).css('display','block');
	$(buts.join()).each(function(i){
		if(num!=i){
			$(this).addClass('imagenone');
		}
		eval('$(this).'+targe+'(function(){'+
			'$(buts.join()).addClass("imagenone");'+
			'$(tabs.join()).css("display","none");'+
			'$(buts[i]).removeClass("imagenone");'+
			'$(tabs[i]).css("display","block");'+
		'});');			
	});
}
function butShowTabs(){
var buts1=['.home-1-but1','.home-1-but2','.home-1-but3'];
var tabs1=['.home-1-desc1','.home-1-desc2','.home-1-desc3'];
//var tabs=['.','.','.'];
var buts2=['.home3-but1','.home3-but2'];
var tabs2=['.home3-desc1','.home3-desc2'];

var buts3=['.news-tag1','.news-tag2','.news-tag3','.news-tag4'];
var tabs3=['.newstab1','.newstab2','.newstab3','.newstab4'];

butShowTab(buts1,tabs1,0,'click');
butShowTab(buts2,tabs2,0,'mouseover');
butShowTab(buts3,tabs3,0,'mouseover');
}
function leaveBorder(){
	var positiony=['0','-25px','-49px','-72px'];
	var dv='如果您有任何需求或疑问，请点击此方框并留言。我们会尽快和您联系并解答。谢谢！';
	 $('.leaveborder').each(function(i){
	 	$(this).focus(function(){
	 		$(this).css('background-position','-212px '+positiony[i]);
	 		if(i==3&&$(this).attr('value')==dv){
	 			$(this).attr('value','');
	 		}
	 	});
	 	$(this).blur(function(){
	 		$(this).css('background-position','0 '+positiony[i]);
	 		if(i==3&&$.trim($(this).attr('value'))==''){
	 			$(this).attr('value',dv);
	 		}
	 	});
	 });
	 
	$('.leave-sum').mouseover(function(){
	 	$(this).css('opacity','0.3').css('background-position','0 -26px').animate({'opacity':'1'},500);
	});
	$('.leave-sum').mouseout(function(){
		$(this).css('opacity','0.3').css('background-position','0 0').animate({'opacity':'1'},500);
	});
	$('.leave-reset').mouseover(function(){
	 	$(this).css('opacity','0.3').css('background-position','-95px -26px').animate({'opacity':'1'},500);
	});
	$('.leave-reset').mouseout(function(){
		$(this).css('opacity','0.3').css('background-position','-95px 0').animate({'opacity':'1'},500);
	});
	
	$('#leave-layer').click(function(){
		$(this).fadeOut(500);
	});
}
function addOpus(){
        for(imgsrc in opus){
                var img='<div  class="home2-opus2 left" hideimg="/media/mulan/images/'+opus[imgsrc]+'"><a href="/index.php/portfolio"></a></div>';
                $('.home2-opus1:first').append(img);
        }
        loadHideimg('.home2-opus > div > div');
}
function addOpusEvent(){
        var length=$('.home2-opus > div >div').length;
	var now=0,size=4;
	now=size;
	var imgwidth=139;
	var width=length*imgwidth;
	$('.home2-opus > div').css('width',width);
	if(length<=size)return;
	$('.home2-left:first').click(function(){
		if($('.home2-opus2').queue('fx').length!=0)return;
		now--;
		if(now<size){
			now=length-1;
			$('.home2-opus1:first').prepend($('.home2-opus2:last'));
			$('.home2-opus2').css('left','-'+imgwidth+'px');
		}
		$('.home2-opus2').animate({left:'+='+imgwidth+'px' },'slow');
	}).mouseover(function(){
		$(this).css('background-position','0 -115px');
	}).mouseout(function(){
		$(this).css('background-position','0 0');
	});
	$('.home2-right:first').click(function(){
		if($('.home2-opus2').queue('fx').length!=0)return;
		now++;
		if(now>length){
			now=size+1;
			$('.home2-opus1:first').append($('.home2-opus2:first'));
			$('.home2-opus2').css('left','0');
		}
		$('.home2-opus2').animate({ left:'-='+imgwidth+'px' },'slow');
	}).mouseover(function(){
		$(this).css('background-position','-2px -115px');
	}).mouseout(function(){
		$(this).css('background-position','-2px 0');
	});
}
function addMsnEvent(){
	if(!$.browser.msie){
		$('#msn').attr('href','mailto: ask@mulandesign.com');
	}else{
		$('#msn').attr('href','msnim:chat?contact=ask@mulandesign.com');
    }
}
function addNavEvent(){
$('.menu ul li ul').css('opacity','0.9');
$('.menu-nav:first > li').each(function(j){
if(j!=0)
$(this).css('background','url(/media/mulan/images/nav_spit03.gif) no-repeat 0 12px');
$(this).find('ul a').mouseup(function(){ 
	$(this).parent().parent().hide(300);
});
$(this).mouseover(function(e){
    if (!e) e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg.nodeName != 'BODY'&&$(reltg).get(0)!=$(tg).parents('li:last').get(0))
	reltg= reltg.parentNode;
	if ($(reltg).get(0)==$(tg).parents('li:last').get(0)) return;
	$(this).find('ul').stop(null,true).show(300);
    $(this).css('background','url(/media/mulan/images/nav_left.jpg) no-repeat');
});
});
$('.menu-nav:first > li').each(function(j){
$(this).mouseout(function(e){
	if (!e) e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg.nodeName != 'BODY'&&$(reltg).get(0)!=$(tg).parents('li:last').get(0))
	reltg= reltg.parentNode;
	if ($(reltg).get(0)==$(tg).parents('li:last').get(0)) return;
	$(this).find('ul').stop(null,true);
	$(this).find('ul').hide(300);
	if(j!=0)
	$(this).css('background','url(/media/mulan/images/nav_spit03.gif) no-repeat 0 12px');
	else $(this).css('background','none');
});
});
$('.menu-nav:first > li:last').css('height','39px');
$('.menu-nav:first > li:last a:first').css('height','39px');
$('.menu-nav:first > li ').each(function(j){
	$(this).find('ul').css('background','url(/media/mulan/images/nav2_border.jpg) no-repeat');
	$(this).find('ul > li:first').css('background','url(/media/mulan/images/nav2_top.jpg) no-repeat');
	$(this).find('ul > li').each(function(i){
	    $(this).mouseover(function(){
	        $(this).find('a').css('background','url(/media/mulan/images/nav2_shade.jpg) no-repeat center');
	    });
	    $(this).mouseout(function(){
	    	$(this).find('a').css('background','none');
	    });
   	});
});
}
function addOveroutEvent(){
        //$('.home3-qq:first').attr('href','tencent://message/?uin=1091955322&Site=www.mulandesign.com&Menu=yes');
	$('.home-1-more').mouseover(function(){
		$(this).css('background-position','-85px 0');
	}).mouseout(function(){
		$(this).css('background-position','0 0');
	});
	$('.but-opus').mouseover(function(){
		$(this).css('opacity','0.3').css('background-position','-123px 0').animate({'opacity':'1'},500);
	}).mouseout(function(){
		$(this).css('opacity','0.3').css('background-position','0 0').animate({'opacity':'1'},500);
	});
$('#web-individuality-call,#web-ecom-btn').mouseover(function(){
	$(this).css('background-position','0 -33px');
});

$('#web-individuality-call,#web-ecom-btn,#web-individuality-btn,#web-translate-btn,.more ,#flash-btn,#web-protal-btn').mouseout(function(){
	$(this).css('background-position','0 0');
});

$('#flash-btn,#web-protal-btn').mouseover(function(){
	$(this).css('background-position','0 -34px');
});

$('.more').mouseover(function(){
	$(this).css('background-position','0 -17px');
});
$('#web-translate-btn ,#web-individuality-btn').mouseover(function(){
	$(this).css('background-position','0 -35px');
});

$('#sflsh,#svi,#sseo,#sgraph,#scom').mouseover(function(){
	$(this).css('background-position','0 -16px');
});
$('#sflsh,#svi,#sseo,#sgraph,#scom').mouseout(function(){
	$(this).css('background-position','0 0');
});
/*$('.home3-qq:first').mouseout(function(){
	$(this).css('opacity','0.3').css('background-position','15px -1px').animate({'opacity':'1'},500);
}).mouseover(function(){
	$(this).css('opacity','0.3').css('background-position','15px -31px').animate({'opacity':'1'},500);
})
$('.home3-msn:first').mouseout(function(){
	$(this).css('opacity','0.3').css('background-position','-135px -1px').animate({'opacity':'1'},500);
}).mouseover(function(){
	$(this).css('opacity','0.3').css('background-position','-135px -31px').animate({'opacity':'1'},500);
})*/
$('.home-top2-1 a').mouseover(function(){
	$(this).css('background-position','0 -16px');
}).mouseout(function(){
	$(this).css('background-position','0 0');
});
$('.free-more,.news-more').mouseover(function(){
	$(this).css('background-position','3px 0');
}).mouseout(function(){
	$(this).css('background-position','right 0');
});
}
