

jQuery(function(){
 jQuery('a').focus(function(){this.blur();});

 jQuery('input.text-default').each(function(){
  jQuery(this).attr('default',jQuery(this).val());
 }).focus(function(){
  if(jQuery(this).val()==jQuery(this).attr('default'))
   jQuery(this).val('');
 }).blur(function(){
  if(jQuery(this).val()=='')
   jQuery(this).val(jQuery(this).attr('default'));
 });
 
 jQuery('div.car').each(function(){
  var car=this;
  jQuery('div.sec',this).each(function(){
   if(this.scrollHeight>168)
    jQuery(this).css('backgroundPosition','410px 100%');
	});
  jQuery('div.sec:gt(1)',car).hide();
  jQuery('a.tab',car).click(function(){
   jQuery('div.sec',car).hide();
   jQuery('div.'+jQuery(this).attr('rel'),car).show();
   jQuery('a.tab',car).removeClass('on');
   jQuery(this).addClass('on');
   return false;
  }).eq(0).addClass('on');
 });
 
});

jQuery(window).load(function(){
 setTimeout('load_car();',250);
});
function load_car(){
 if(jQuery('div#imgcar').length){
  var car=jQuery('div#imgcar'),cur=0;
  var center=(car.width()-jQuery('img:first',car).width())/2,widths=[],moves=[];
  jQuery('img',car).each(function(i){
   jQuery(this).css({left:center+widths.sum()+(widths.length*20),opacity:i?0.4:1}).show();
   widths[i]=parseInt(jQuery(this).width());
   moves[i]=((widths[i-1]>0?widths[i-1]:0)+widths[i]+20)/2;
  });
  moves[0]=moves[1];
  jQuery('div#imgcarr').append('<a href="#" class="next" rel="n" /><a href="#" class="prev" rel="p" />');
  jQuery('a','div#imgcarr').click(function(){
   var dir=(jQuery(this).attr('rel')=='n'?1:-1);
   if(cur+dir<0 || cur+dir>=jQuery('img',car).length){
    return false;
   }
   jQuery('img',car).each(function(j){
    jQuery(this).animate({left:(dir>0?'-':'+')+'='+moves[cur+dir]+'px',opacity:(j==cur+dir?1:0.4)});
   });
   cur+=dir;
   return false;
  });
 }
}

function add_image(id){
 jQuery('#'+id).append('<p>('+(jQuery('input.file').length+1)+') <input type="file" name="images[]" value="" class="file" /></p>');
}

Array.prototype.sum=function(){
 return (!this.length)?0:this.slice(1).sum()+
 ((typeof this[0]=='number')?this[0]:0);
};
