	/* index */
$(function(){
	// global settings
	$.ajaxSetup({cache: true});
	var adurl = '';
	
	$('#advs_top3,#advs_grid,#advs_center,#advs_left1,#advs_left2').slideDown();    
	// ad


	// slide
	$('#photos').galleryView({
		panel_width: 445,
		panel_height: 295,
		frame_width: 40,
		frame_height: 40,
		overlay_height: 33,
		overlay_font_size: '12px',
		border: 'none',
		transition_interval: 3500,
		img_path: 'templets/default/images/slide/js/'
	});
	// hot
	$('#hotslide .slidegrid').scrollable({
	size:5,
	circular:true,
	next:'.nextPage',
	prev:'.prevPage',
	onBeforeSeek: function(event, i) {
		var pane = this.getItems().eq(i + 4);
		if (pane.is(":empty")) {
			pane.append(hot[this.getIndex()]);
		}
	}
	}).autoscroll();
	// recommend
	$('#push .recommends').scrollable({vertical:true,circular:true}).autoscroll();
	// tab
	mktab(['#designers', '#industry','#production', '#design']);	
	// passport status
	$.get('/templets/default/images/passport.php',function(data){ $('#passport_status').html(data);});
	//gallery
	$('#tu .slidegrid').scrollable({size:5,circular:true,next:'.nextPage',prev:'.prevPage'}).autoscroll();
	$("#galleries .tabs").tabs("#galleries >div",{
		onBeforeClick:function(event,i) {
			var pane=this.getPanes().eq(i);
			if(pane.is(':empty')) {
				var parent = this.getCurrentTab().parents('ul');
				var refer = this.getTabs().eq(i).attr('href');
				refer = refer.replace('?',' #');
				parent.after('<div class="loading" style="padding:20px;">数据加载中...</div>');
				pane.load(refer, function() {
					parent.next('.loading').remove();
					$(refer.split(' ')[1] +' .slidegrid').scrollable({size:5,circular:true,next:'.nextPage',prev:'.prevPage'}).autoscroll();
				});
			}
		}
	});
	// topic
	$('#topic .leftgrid').scrollable({
	vertical:true,
	circular:true,
	next:'.nextPage',
	prev:'.prevPage',		
	onBeforeSeek: function(event, i) {
		var pane = this.getItems().eq(i);
		if (pane.is(":empty")) {
			pane.append(topic[this.getIndex()]);
		}
	}
	}).autoscroll({interval:5000}).navigator();	
	$('#hot,#designers,#industry,#pk,#hr,#exhibition,#production,#contest,#topic,#forum,#design').corner('5px');
	// counter
	document.write = function (s) {$('#counter').append(s);};
	$.getScript('http://js.users.51.la/3032966.js',function(data){ $('#counter').html(data);});
	
	function mktab(tabarr){
		$.each(tabarr, function() {
			$(this + ' .tabs').tabs(this + ' > div[class!=more]',{
				onBeforeClick: function(event, i) {
					var pane = this.getPanes().eq(i);
					if (pane.is(':empty')) {
						var parent = this.getCurrentTab().parents('ul');
						var refer = this.getTabs().eq(i).attr('href');
						refer = refer.replace('?',' #');						
						parent.after('<div class="loading" style="padding:20px;">数据加载中...</div>');
						pane.load(refer, function(){parent.next('.loading').remove();});
					}
				}
			});
		});	
	}	
	
	function mkad(id,url,href,width,height,title){
		var i=url.lastIndexOf('.');
		if(i<0) return;
		var ext=url.substring(i+1);
		ext=ext.toLowerCase();
		width=width?width:240;
		height=height?height:60;
		url=(url.substring(0,7)=='http://')?url:adurl+url;
		var adhtml='';
		if (ext=='swf'){
			adhtml+='<object id="'+id+'-flash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" style="visibility:visible;display:block;">';
			adhtml+='<param name="movie" value="'+url+'">';
			adhtml+='<param name="quality" value="high">';
			adhtml+='<param name="wmode" value="opaque">';
			adhtml+='<param name="menu" value="false">';
			adhtml+='<param name="allowfullscreen" value="false">';
			adhtml+='<param name="allowscriptaccess" value="always">';
			adhtml+='<embed name="'+id+'-flash" src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="opaque" allowfullscreen="false" allowscriptaccess="always"></embed>';
			adhtml+='</object>';
		}else{
			title=title?title:'Advertisement by Arting365';
			adhtml='<a title="'+title+'" href="'+href+'" target="_blank"><img src="'+url+'" width="'+width+'" height="'+height+'" /></a>';
		}
		var ad=document.getElementById(id);
		ad.innerHTML=adhtml;
		ad.style.display='block';
	}
});
