function newClass(parent, prop) {
  var clazz = function() {
     if (clazz.preparing) return delete(clazz.preparing);
    if (clazz.constr) {
      this.constructor = clazz; 
      clazz.constr.apply(this, arguments);
    }
  }
  clazz.prototype = {}; 
  if (parent) {
    parent.preparing = true;
    clazz.prototype = new parent;
    clazz.prototype.constructor = parent;
    clazz.constr = parent; 
  }
  if (prop) {
    var cname = "construct";
    for (var k in prop) {
      if (k != cname) clazz.prototype[k] = prop[k];
    }
    if (prop[cname] && prop[cname] != Object)
      clazz.constr = prop[cname];
  }
  return clazz;
}

function $(id) { return document.getElementById(id); }

Slider = newClass(null, {
	
          construct : function() {
    	  this.image=new Array();
    	  this.slide=new Array();
    	  this.img_size='_s';
	},
	
	Start:function(id) {
	    if(!this.image[id]) this.ChangePic(id);	
	    this.image[id] = setInterval('slider.ChangePic("'+id+'")',500);
	},
	
          SelectCategory: function(){
             var cat=$('category').options[$('category').selectedIndex].value;
             if(cat!='0') document.location='/category/'+cat+'/';
             else document.location='/';
           },	
   
	ChangePic:function(id) {
                 if(!this.slide[id]){
                    $('img_'+id).src = $('img_'+id).src.replace(id+this.img_size+'.jpg',id+'_1'+this.img_size+'.jpg');
                     this.slide[id]=1;
                 }else{
                   var cur_slide=this.slide[id];
                   if(this.slide[id]>=9) this.slide[id]=1;
                   else this.slide[id]++;
                   $('img_'+id).src = $('img_'+id).src.replace(id+'_'+cur_slide+this.img_size+'.jpg',id+'_'+this.slide[id]+this.img_size+'.jpg');
                 }
	},
	
	Return:function(id) {
	    clearInterval(this.image[id]);	
	    var cur_slide=this.slide[id];	
               this.slide[id]=0;
                $('img_'+id).src = $('img_'+id).src.replace(id+'_'+cur_slide+this.img_size+'.jpg',id+this.img_size+'.jpg');
                this.Start(id);
	},
	
	Stop:function(id) {
	     clearInterval(this.image[id]);
	     this.image[id]=0;
	}
});

var slider=new Slider();


function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if(b.type == "Netscape") window.sidebar.addPanel(title,url,"");

 return false;
}

