/*
 * Action By Class name module
 * By: achun
 * Email:achun.shx at gmail.com
 * MIT-licenses
 * http://www.opensource.org/licenses/mit-license.php
 * 2007-6-23
 */
(function($){
$.abc = {};
$.extend($.fn, {
	hrefrewrite:function(){
		this.each(function(i){
      if (''==this.href){
        this.href='javascript: void(0);';
        return;
      }
			var len=this.href.indexOf(document.domain)+1;
			var act= len && len<9?this.href.substring(len+document.domain.length):this.href;
			if (act.charAt(0)=='#' || act==this.href) return;
			this.href = 'javascript: void(0);';
			if(''==this.target){
				$(this).click(function(){
					Act.a(act);
					return true;
				});
			}else{
				act = ('onload='+act).split(/[=&]/);
				var formstr='<form action="/" method="GET" target="'+this.target+'">';
				for (var i=0; i<act.length;i+=2) {
					formstr+="<input type='hidden' name='"+act[i]+"' value='"+act[i+1]+"' />";
				}
				formstr+='</form>';
				$(this).click(function(){
					$(formstr).appendTo("body").submit().remove();
					return false;
				});
			}
		});
	}
});

$.extend($.fn, {
	abc: function() {
		for (var i=this.length - 1;i>=0;i--) {
		//for (var i=0 ;i<this.length;i++) {
			var cna = this[i ].className.split(/\s+/);
			var obj = $(this[i]);
			for (var j=0; j<cna.length; j++) {
				if ('abc.'!=cna[j].substr(0,4) || cna[j].indexOf('(')<1 || cna[j].substr(cna[j].length-1)!=')') continue;
				var fn='$.'+cna[j].substr(0,cna[j].indexOf('('));
				var option=$.trim(cna[j].substr(cna[j].indexOf('(')+1,cna[j].length-2-cna[j].indexOf('(')));
				option=option.replace(/&/g,' ');
				if (option==""){
					fn = fn+'(this[i])';
				}else
					fn = fn+'(this[i],'+option+',"'+option+'")';
				obj.removeClass(cna[j]);
				try {
					eval(fn);
				}catch (e){alert('abc error:'+fn)};
			}
		}
		this.removeClass('abc');
	}
});
function Marquee(elm,n,p){
	var left=-parseInt(p.css('margin-left'));
	document.title=p.width();
	var width=parseInt(p.width()/n);
	if (left>width) {
		left=0;
	}
	left++;
	p.css('margin-left',-left);
}
$.extend($.abc, {
	marquee: function(elm,options){
		return;
		var w=$(elm).width();
		var m=$('.marquee',elm);
		var n=$('.marquee img',elm).length;
		var width=m.parent().width();
		$('.marquee',elm).css({float:'left'});
		if (n>3 && n<6) {
			var o=m.toggleClass('marquee').clone();
			m.parent().append(o).width(10000);
			n=2;
		}else{
			n=1;
		}
		m=m.parent();
		var MyMar=setInterval(function(){
			Marquee(elm,n,m);}
			,50);
		$(elm).mouseover(function() {clearInterval(MyMar);}).
		mouseout(function() {MyMar=setInterval(
			function(){Marquee(elm,n,m);}
			,50);
		});
	},
	bg4split: function(elm,options){
		var jelm=$(elm);
		elm.style.position='relative';
		$.each(elm.childNodes,function(){
			if (this.nodeType==1){
				var jthis=$(this);
				var z=jthis.css('z-index');
				if (z=='auto')
					z=1;
				else
					z++;
				jthis.css({'z-index':z,position:'relative'});
			}
		});
		var tr = $('<div class="tr" />').css({'background-position':'top right',   top:  '0px',right: '0px',height:'50%',width:'50%',position:'absolute'});
		var tl = $('<div class="tl" />').css({'background-position':'top left',    top:  '0px',left:  '0px',height:'50%',width:'50%',position:'absolute'});
		var br = $('<div class="br" />').css({'background-position':'right bottom',right:'0px',bottom:'0px',height:'50%',width:'50%',position:'absolute'});
		var bl = $('<div class="bl" />').css({'background-position':'left bottom', left: '0px',bottom:'0px',height:'50%',width:'50%',position:'absolute'});
		if(null!=options.className){
			tr.addClass( options.className);
			tl.addClass( options.className);
			br.addClass( options.className);
			bl.addClass( options.className);
		}
		jelm.append(tr).append(tl).append(br).append(bl);
		if ('msie'==$.browser.is && jQuery.browser.version<7) {
			var w=jelm.innerWidth()-tl.outerWidth(),h=jelm.innerHeight()-tl.outerHeight();
			tl.width(w);bl.width(w);tl.height(h);tr.height(h);
		}
	},
  autoSize: function(elm,options,optstr){
    function toSize(elm,options){
      var jelm=$(elm),w=jelm.width(),h=jelm.height(),width,height;
      if(options.max){
        options.max.width = options.max.width || w;
        options.max.height= options.max.height || h;
        width = options.max.width<w ? options.max.width : w;
        height = options.max.height<h ? options.max.height : h;
      }
      if(options.min){
        options.min.width = options.min.width || w;
        options.min.height= options.min.height || h;
        width = options.min.width > w ? options.min.width : w;
        height = options.min.height > h ? options.min.height : h;
      }
			height = Math.round(width * h / w);
      jelm.css({width:width + 'px',height:height+'px'});
    }
		function setonload(o) {
			o.setAttribute('onload','$.abc.autoSize(this,{expr:false},'+optstr+');');
		}
		if (!options) return;
		if (options.expr==false) {
			toSize(elm,optstr);
			return;
		}
		if(!options.expr){
			//delete options.expr;
			options.expr=false;
			setonload(elm);
			//$(this).load(function(){$.abc.autoSize(this,options);});
		}else{
			var expr=options.expr;
			//delete options.expr;
			options.expr=false;
			$(expr,elm).each(function(){ 
				setonload(this);
				//$(this).load(function(){$.abc.autoSize(this,options);});
			});
		}
  },
	flowplayer: function(elm,options){Log(9);
		var splash,videofile,autoPlay;
		if (typeof options=='string') {
			splash='/'+options+'.jpg';
			videofile='/'+options;
			autoPlay=true;
		}else{
			autoPlay=true;
			splash='/'+options.video+'.jpg';
			videofile='/'+options.video;
		}
		$(elm).flashembed({
			src:'/style/FlowPlayerLight.swf',
			width:'100%', 
			height:'100%'
		},
		{config: {
			autoPlay: autoPlay,
			autoBuffering:autoPlay,
			splashImageFile:splash,
			videoFile:videofile,
			//playList:[{url:'/'+options}],
			initialScale: 'fit',
			showMenu:false,
			useNativeFullScreen: true
		}});
	}
});
})(jQuery);
